class Hocon::Impl::Parseable::ParseableFile

NOTE: Skipping `ParseableURL` for now as we probably won't support this right away

Public Class Methods

new(input, options) click to toggle source
Calls superclass method Hocon::Impl::Parseable.new
# File lib/hocon/impl/parseable.rb, line 396
def initialize(input, options)
  super()
  @input = input
  post_construct(options)
end

Public Instance Methods

create_origin() click to toggle source
# File lib/hocon/impl/parseable.rb, line 452
def create_origin
  Hocon::Impl::SimpleConfigOrigin.new_file(@input)
end
custom_reader() click to toggle source
# File lib/hocon/impl/parseable.rb, line 402
def custom_reader
  if Hocon::Impl::ConfigImpl.trace_loads_enabled
    self.class.trace("Loading config from a String: #{@input}")
  end
  # we return self here, which will cause `open` to be called on us, so
  # we can provide an implementation of that.
  self
end
guess_syntax() click to toggle source
# File lib/hocon/impl/parseable.rb, line 429
def guess_syntax
  Hocon::Impl::Parseable.syntax_from_extension(File.basename(@input))
end
open() { |f| ... } click to toggle source
# File lib/hocon/impl/parseable.rb, line 411
def open
  begin
    if block_given?
      File.open(@input, :encoding => 'bom|utf-8') do |f|
        yield f
      end
    else
      File.open(@input, :encoding => 'bom|utf-8')
    end
  rescue Errno::ENOENT
    if @initial_options.allow_missing?
      return Hocon::Impl::SimpleConfigObject.empty
    end

    raise Hocon::ConfigError::ConfigIOError.new(nil, "File not found. No file called #{@input}")
  end
end
relative_to(filename) click to toggle source
Calls superclass method Hocon::Impl::Parseable#relative_to
# File lib/hocon/impl/parseable.rb, line 433
def relative_to(filename)
  sibling = nil
  if Pathname.new(filename).absolute?
    sibling = File.new(filename)
  else
    # this may return nil
    sibling = Hocon::Impl::Parseable.relative_to(@input, filename)
  end
  if sibling.nil?
    nil
  elsif File.exists?(sibling)
    self.class.trace("#{sibling} exists, so loading it as a file")
    Hocon::Impl::Parseable.new_file(sibling, options.set_origin_description(nil))
  else
    self.class.trace("#{sibling} does not exist, so trying it as a resource")
    super(filename)
  end
end
to_s() click to toggle source
# File lib/hocon/impl/parseable.rb, line 456
def to_s
  "#{self.class.name.split('::').last} (#{@input})"
end