class ConfigHound::Resource

Represents a source of configuration data.

Attributes

uri[R]

Public Class Methods

[](arg) click to toggle source
# File lib/config_hound/resource.rb, line 16
def [](arg)
  return arg if arg.is_a?(Resource)
  new(uri_for(arg))
end
new(uri) click to toggle source
# File lib/config_hound/resource.rb, line 68
def initialize(uri)
  @uri = uri
end

Private Class Methods

uri_for(arg) click to toggle source
# File lib/config_hound/resource.rb, line 25
def uri_for(arg)
  case arg
  when URI
    arg
  when %r{^\w+:/}
    URI(arg)
  when %r{^/}
    URI("file://#{arg}")
  else
    URI("file://#{File.expand_path(arg)}")
  end
end

Public Instance Methods

format() click to toggle source
# File lib/config_hound/resource.rb, line 58
def format
  File.extname(uri.to_s)[1..-1]
end
load() click to toggle source
# File lib/config_hound/resource.rb, line 62
def load
  Parser.parse(read, format)
end
read() click to toggle source
# File lib/config_hound/resource.rb, line 50
def read
  open(uri.scheme == "file" ? uri.path : uri.to_s) do |io|
    io.read
  end
rescue Errno::ENOENT
  raise LoadError, "can't load: #{uri}"
end
resolve(path) click to toggle source
# File lib/config_hound/resource.rb, line 46
def resolve(path)
  Resource[uri + path]
end
to_s() click to toggle source
# File lib/config_hound/resource.rb, line 42
def to_s
  uri.to_s
end