Module: Capricorn::System::Options

Included in:
Capricorn::System
Defined in:
lib/capricorn/system/options.rb

Instance Method Summary collapse

Instance Method Details

#option(name, proc, &handler) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/capricorn/system/options.rb', line 6

def option(name, proc, &handler)
  if proc
    @option_descriptors.push({
      :name => name.to_sym,
      :proc => proc,
      :handler => handler
    })
  else
    if handler && !@options.key?(name.to_sym)
      @options[name.to_sym] = handler.call(nil)
    end
    @options[name.to_sym]
  end
end

#resolve_options!Object



52
53
54
55
# File 'lib/capricorn/system/options.rb', line 52

def resolve_options!
  resolve_options_for_system!
  resolve_options_for_satellite!
end

#resolve_options_for_satellite!Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/capricorn/system/options.rb', line 66

def resolve_options_for_satellite!
  @satellite_options = {}
  if @current_satellite
    @satellite_option_descriptors.each do |option|
      value = option[:proc].call(@current_satellite)           if option[:proc]
      value = option[:handler].call(@current_satellite, value) if option[:handler]
      @satellite_options[option[:name]] = value
    end
  end
end

#resolve_options_for_system!Object



57
58
59
60
61
62
63
64
# File 'lib/capricorn/system/options.rb', line 57

def resolve_options_for_system!
  @options = {}
  @option_descriptors.each do |option|
    value = option[:proc].call           if option[:proc]
    value = option[:handler].call(value) if option[:handler]
    @options[option[:name]] = value
  end
end

#resolve_options_with(satellite) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/capricorn/system/options.rb', line 40

def resolve_options_with(satellite)
  @current_satellite = satellite
  resolve_options!
  
  result = yield
  
  @current_satellite = nil
  resolve_options!
  
  result
end

#satellite_option(name, proc, &handler) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/capricorn/system/options.rb', line 21

def satellite_option(name, proc, &handler)
  if proc
    @satellite_option_descriptors.push({
      :name => name.to_sym,
      :proc => proc,
      :handler => handler
    })
  else
    if handler && !@satellite_options.key?(name.to_sym)
      @satellite_options[name.to_sym] = handler.call(@current_satellite, nil)
    end
    @satellite_options[name.to_sym]
  end
end

#set_satellite_option(name, value) ⇒ Object



36
37
38
# File 'lib/capricorn/system/options.rb', line 36

def set_satellite_option(name, value)
  @satellite_options[name.to_sym] = value
end