Class: FunWith::Configurations::TryObject
- Inherits:
-
Object
- Object
- FunWith::Configurations::TryObject
show all
- Defined in:
- lib/fun_with/configurations/try_object.rb
Instance Method Summary
collapse
Constructor Details
#initialize(config) ⇒ TryObject
5
6
7
8
9
|
# File 'lib/fun_with/configurations/try_object.rb', line 5
def initialize( config )
@config = config
@success = true
@leaf = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
11
12
13
|
# File 'lib/fun_with/configurations/try_object.rb', line 11
def method_missing( method, *args )
follow_config_method_chain( method )
end
|
Instance Method Details
#[](method_key) ⇒ Object
15
16
17
|
# File 'lib/fun_with/configurations/try_object.rb', line 15
def [] method_key
follow_config_method_chain( method_key.to_sym )
end
|
#config_method_chain_result(*keys) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/fun_with/configurations/try_object.rb', line 36
def config_method_chain_result( *keys )
keys = keys.flatten
if success?
keys.each do |k|
follow_config_method_chain(k)
end
end
TryResult.new( @config, success? )
end
|
#follow_config_method_chain(method) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/fun_with/configurations/try_object.rb', line 19
def follow_config_method_chain( method )
if @success == true
if @config.is_a?(Config) && @config.has_key?(method)
@config = @config[method]
unless @config.is_a?(Config)
@leaf = true
end
elsif @leaf
@leaf = false else
@success = false
end
end
self
end
|
#success? ⇒ Boolean
48
49
50
|
# File 'lib/fun_with/configurations/try_object.rb', line 48
def success?
@success
end
|