class Hocon::Impl::Parseable::ParseableResources
NOTE: this is not a faithful port of the `ParseableResources` class from the upstream, because at least for now we're not going to try to do anything crazy like look for files on the ruby load path. However, there is a decent chunk of logic elsewhere in the codebase that is written with the assumption that this class will provide the 'last resort' attempt to find a config file before giving up, so we're basically port just enough to have it provide that last resort behavior
Public Class Methods
new(resource, options)
click to toggle source
Calls superclass method
Hocon::Impl::Parseable.new
# File lib/hocon/impl/parseable.rb, line 480 def initialize(resource, options) super() @resource = resource post_construct(options) end
parent(resource)
click to toggle source
# File lib/hocon/impl/parseable.rb, line 502 def self.parent(resource) # the "resource" is not supposed to begin with a "/" # because it's supposed to be the raw resource # (ClassLoader#getResource), not the # resource "syntax" (Class#getResource) i = resource.rindex("/") if i < 0 nil else resource.slice(0..i) end end
Public Instance Methods
create_origin()
click to toggle source
# File lib/hocon/impl/parseable.rb, line 535 def create_origin Hocon::Impl::SimpleConfigOrigin.new_resource(@resource) end
guess_syntax()
click to toggle source
# File lib/hocon/impl/parseable.rb, line 498 def guess_syntax Hocon::Impl::Parseable.syntax_from_extension(@resource) end
raw_parse_value(origin, final_options)
click to toggle source
# File lib/hocon/impl/parseable.rb, line 490 def raw_parse_value(origin, final_options) # this is where the upstream code would go out and look for a file on the # classpath. We're not going to do that, and instead we're just going to # raise the same exception that the upstream code would raise if it failed # to find the file. raise IOError, "resource not found: #{@resource}" end
reader()
click to toggle source
# File lib/hocon/impl/parseable.rb, line 486 def reader raise Hocon::ConfigError::ConfigBugOrBrokenError, "reader() should not be called on resources" end
relative_to(sibling)
click to toggle source
# File lib/hocon/impl/parseable.rb, line 515 def relative_to(sibling) if sibling.start_with?("/") # if it starts with "/" then don't make it relative to the # including resource Hocon::Impl::Parseable.new_resources(sibling.slice(1), options.set_origin_description(nil)) else # here we want to build a new resource name and let # the class loader have it, rather than getting the # url with getResource() and relativizing to that url. # This is needed in case the class loader is going to # search a classpath. parent = self.class.parent(@resource) if parent.nil? Hocon::Impl::Parseable.new_resources(sibling, options.set_origin_description(nil)) else Hocon::Impl::Parseable.new_resources("#{parent}/sibling", options.set_origin_description(nil)) end end end
to_s()
click to toggle source
# File lib/hocon/impl/parseable.rb, line 539 def to_s "#{self.class.name.split('::').last}(#{@resource})" end