Class: Declarative::Defaults

Inherits:
Object
  • Object
show all
Extended by:
Uber::Delegates
Defined in:
lib/declarative/defaults.rb

Instance Method Summary collapse

Constructor Details

#initializeDefaults

Returns a new instance of Defaults.



5
6
7
8
# File 'lib/declarative/defaults.rb', line 5

def initialize
  @static_options  = {}
  @dynamic_options = ->(*) { Hash.new }
end

Instance Method Details

#call(name, given_options) ⇒ Object

TODO: allow to receive rest of options/block in dynamic block. or, rather, test it as it was already implemented.



20
21
22
23
24
# File 'lib/declarative/defaults.rb', line 20

def call(name, given_options)
  options = @static_options
  options = options.merge(@dynamic_options.(name, given_options))
  options = options.merge(given_options)
end

#merge!(hash, &block) ⇒ Object



10
11
12
13
14
# File 'lib/declarative/defaults.rb', line 10

def merge!(hash, &block)
  @static_options.merge!(hash) if hash.any?
  @dynamic_options = block if block_given?
  self
end