Sha256: cd3791275cf36d1687d8b373304d3588681399d4dda9b5fcb8b23cbd0b0105de
Contents?: true
Size: 930 Bytes
Versions: 4
Compression:
Stored size: 930 Bytes
Contents
require 'yaml' require 'socket' module FigMagic module Missing 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 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 def type_known?(value) known_types = [String, Integer, TrueClass, FalseClass] known_types.any? { |type| value.kind_of? type } end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
fig_magic-0.5 | lib/fig_magic/missing.rb |
fig_magic-0.4 | lib/fig_magic/missing.rb |
fig_magic-0.3 | lib/fig_magic/missing.rb |
fig_magic-0.2 | lib/fig_magic/missing.rb |