Module: Infrastructure::Configurable

Included in:
Infrastructure, Databases, Environment, Path, Server, Version
Defined in:
lib/infrastructure/configurable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/infrastructure/configurable.rb', line 4

def self.included(base)
  base.extend Forwardable
  base.send :def_delegators, :configuration, :assign, :fetch, :configure, :each
  base.send :def_delegators, :configuration, :load_config, :load_config_if_exists, :save_config
end

Instance Method Details

#after_assignment(*params) ⇒ Object



38
39
40
# File 'lib/infrastructure/configurable.rb', line 38

def after_assignment(*params)
  callbacks[:after_assignment].each { |block| block.call *params }
end

#after_configure(*params) ⇒ Object



46
47
48
# File 'lib/infrastructure/configurable.rb', line 46

def after_configure(*params)
  callbacks[:after_configure].each { |block| block.call *params }
end

#before_assignment(*params) ⇒ Object



34
35
36
# File 'lib/infrastructure/configurable.rb', line 34

def before_assignment(*params)
  callbacks[:before_assignment].each { |block| block.call *params }
end

#before_configure(*params) ⇒ Object



42
43
44
# File 'lib/infrastructure/configurable.rb', line 42

def before_configure(*params)
  callbacks[:before_configure].each { |block| block.call *params }
end

#callback(key, *params, &block) ⇒ Object



14
15
16
17
# File 'lib/infrastructure/configurable.rb', line 14

def callback(key, *params, &block)
  callbacks[key] << block if block
  callbacks[key] += Array(params)
end

#callbacksObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/infrastructure/configurable.rb', line 19

def callbacks
  @callbacks ||= { 
    before_configure: [],
    after_configure: [],
    before_assignment: [ 
      -> (key, value) { configuration_accessor key unless respond_to? key }
    ],
    after_assignment: []
  }
end

#configurationObject



10
11
12
# File 'lib/infrastructure/configurable.rb', line 10

def configuration
  @configuration ||= Configuration.new self
end

#configuration_accessor(key) ⇒ Object



30
31
32
# File 'lib/infrastructure/configurable.rb', line 30

def configuration_accessor(key)
  self.class.send(:define_method, key) { configuration.send(key) }
end