Class: BusinessPipeline::Config
- Inherits:
-
Object
- Object
- BusinessPipeline::Config
show all
- Defined in:
- lib/business_pipeline/config.rb
Instance Method Summary
collapse
Constructor Details
#initialize(hash = nil, &block) ⇒ Config
Returns a new instance of Config.
7
8
9
10
11
|
# File 'lib/business_pipeline/config.rb', line 7
def initialize(hash = nil, &block)
@data = OpenStruct.new(hash)
instance_eval(&block) if block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/business_pipeline/config.rb', line 22
def method_missing(meth, *args, &block)
if args.size.zero? || meth.to_s.end_with?('=')
data.public_send(meth, *args, &block)
else
data[meth] = args.first
end
end
|
Instance Method Details
#fetch(key) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/business_pipeline/config.rb', line 13
def fetch(key)
value = data[key.to_sym]
return value unless value.nil?
return yield(key) if block_given?
fail KeyError, key
end
|
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/business_pipeline/config.rb', line 30
def respond_to_missing?(meth, include_private = false)
data.respond_to?(meth, include_private) || super
end
|