class Confickle

Attributes

root[R]
symbolize_names[R]

Public Class Methods

new(options) click to toggle source
# File lib/confickle.rb, line 11
def initialize(options)
  if options.is_a? String
    options = {root: options}
  end

  @root            = File.absolute_path(options.fetch(:root))
  @symbolize_names = options.fetch(:symbolize_names, true)
end

Public Instance Methods

content(*args) click to toggle source
# File lib/confickle.rb, line 25
def content(*args)
  File.read(self.path(*args))
end
Also aliased as: contents
contents(*args)
Alias for: content
json(*args) click to toggle source
# File lib/confickle.rb, line 30
def json(*args)
  if args.last.is_a? Hash
    args    = args.dup
    options = args.pop
  else
    options = {}
  end

  sn = options.fetch(:symbolize_names, self.symbolize_names)
  JSON.parse(
    self.content(*args),
    symbolize_names: sn
  )
end
path(*args) click to toggle source
# File lib/confickle.rb, line 21
def path(*args)
  File.join(self.root, *args)
end
yaml(*args) click to toggle source
# File lib/confickle.rb, line 46
def yaml(*args)
  if args.last.is_a? Hash
    args    = args.dup
    options = args.pop
  else
    options = {}
  end

  retval = YAML.load_file(path(*args))

  sn = options.fetch(:symbolize_names, self.symbolize_names)
  if sn
    RecSym.this(retval)
  else
    retval
  end
end