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
Source
# File lib/hocon/impl/parseable.rb, line 481 def initialize(resource, options) super() @resource = resource post_construct(options) end
Calls superclass method
Hocon::Impl::Parseable::new
Source
# File lib/hocon/impl/parseable.rb, line 503 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
Source
# File lib/hocon/impl/parseable.rb, line 536 def create_origin Hocon::Impl::SimpleConfigOrigin.new_resource(@resource) end
Source
# File lib/hocon/impl/parseable.rb, line 499 def guess_syntax Hocon::Impl::Parseable.syntax_from_extension(@resource) end
Source
# File lib/hocon/impl/parseable.rb, line 491 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
Source
# File lib/hocon/impl/parseable.rb, line 487 def reader raise Hocon::ConfigError::ConfigBugOrBrokenError, "reader() should not be called on resources" end
Source
# File lib/hocon/impl/parseable.rb, line 516 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
Source
# File lib/hocon/impl/parseable.rb, line 540 def to_s "#{self.class.name.split('::').last}(#{@resource})" end