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
17
18
19
20
21
|
# File 'lib/fun_with/configurations/try_object.rb', line 17
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
23
24
25
|
# File 'lib/fun_with/configurations/try_object.rb', line 23
def method_missing( method, *args )
follow_config_method_chain( method )
end
|
Instance Method Details
#[](method_key) ⇒ Object
27
28
29
|
# File 'lib/fun_with/configurations/try_object.rb', line 27
def [] method_key
follow_config_method_chain( method_key.to_sym )
end
|
#config_method_chain_result(*keys) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/fun_with/configurations/try_object.rb', line 48
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/fun_with/configurations/try_object.rb', line 31
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
60
61
62
|
# File 'lib/fun_with/configurations/try_object.rb', line 60
def success?
@success
end
|