Module: FigNewton::Missing
- Included in:
- FigNewton, Node
- Defined in:
- lib/fig_newton/missing.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/fig_newton/missing.rb', line 7
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 = FigNewton::Node.new(value) unless type_known? value
value
end
|
Instance Method Details
#read_file ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/fig_newton/missing.rb', line 18
def read_file
@yml = nil
@yml = ::YAML.load(ERB.new(File.read("#{yml_directory}/#{ENV['FIG_NEWTON_FILE']}")).result(binding)) if ENV['FIG_NEWTON_FILE']
unless @yml
hostname = Socket.gethostname
hostfile = "#{yml_directory}/#{hostname}.yml"
@yml = YAML.load_file hostfile if File.exist? hostfile
end
FigNewton.load('default.yml') if @yml.nil?
end
|