module FigMagic::Missing

Public Instance Methods

method_missing(*args, &block) click to toggle source
Calls superclass method
# File lib/fig_magic/missing.rb, line 6
def method_missing(*args, &block)
  read_file unless @yml
  m = args.first
  value = @yml[m.to_s]
  value = args[1] if value.nil?
  value = block.call(m.to_s) if value.nil? and block
  super if value.nil?
  value = FigMagic::Node.new(value) unless type_known? value
  value
end
read_file() click to toggle source
# File lib/fig_magic/missing.rb, line 17
def read_file
  @yml = nil
  @yml = YAML.load_file "#{yml_directory}/#{ENV['FIG_MAGIC_FILE']}" if ENV['FIG_MAGIC_FILE']
  unless @yml
    hostname = Socket.gethostname
    hostfile = "#{yml_directory}/#{hostname}.yml"
    @yml = YAML.load_file hostfile if File.exist? hostfile
  end
  FigMagic.load('default.yml') if @yml.nil?
end

Private Instance Methods

type_known?(value) click to toggle source
# File lib/fig_magic/missing.rb, line 30
def type_known?(value)
  known_types = [String, Integer, TrueClass, FalseClass]
  known_types.any? { |type| value.kind_of? type }
end