Module: Hyperloop

Defined in:
lib/hyperloop-config.rb

Class Method Summary collapse

Class Method Details

.configuration {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Hyperloop)

    the object that the method was called on



13
14
15
16
17
# File 'lib/hyperloop-config.rb', line 13

def configuration
  reset_blocks.each(&:call)
  yield self
  initialized_blocks.each(&:call)
end

.define_setting(name, default = nil, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hyperloop-config.rb', line 19

def define_setting(name, default = nil, &block)
  class_variable_set("@@#{name}", default)

  define_class_method "#{name}=" do |value|
    class_variable_set("@@#{name}", value)
    block.call value if block
    value
  end

  define_class_method name do
    class_variable_get("@@#{name}")
  end
end

.initialized_blocksObject



5
6
7
# File 'lib/hyperloop-config.rb', line 5

def initialized_blocks
  @initialized_blocks ||= []
end

.on_config_initialized(&block) ⇒ Object



37
38
39
# File 'lib/hyperloop-config.rb', line 37

def on_config_initialized &block
  initialized_blocks << block
end

.on_config_reset(&block) ⇒ Object



33
34
35
# File 'lib/hyperloop-config.rb', line 33

def on_config_reset &block
  reset_blocks << block
end

.reset_blocksObject



9
10
11
# File 'lib/hyperloop-config.rb', line 9

def reset_blocks
  @reset_blocks ||= []
end