Class: LanGrove::Config::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/langrove/root/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, hash_of_config, logger) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/langrove/root/config.rb', line 16

def initialize( root, hash_of_config, logger )
  
  @root = root
  @config = hash_of_config

  @system = hash_of_config[:system]
  @application = hash_of_config[:application]
  
  #
  # Provides access to initializable 
  # definitions of plugins
  # 
  # See get_plugin
  #
  @plugin_classes = {}
  @plugin_configs = {}
  
  @plugin_types = {}
  
  @config[:plugins].each do |name, definition|
    
    @plugin_classes[ name ] = LanGrove::ClassLoader.create(
    
      :module => 'Plugin',
      :class => definition[:class]
    
    )
    
    type = @plugin_classes[ name ].type
    
    if @plugin_types[ type ].nil?
      
      @plugin_types[ type ] = []
      
    end
    
    @plugin_types[ type ].push(
    
      name
    
    )
    
    @plugin_configs[ name ] = definition
    
  end unless ( 
  
    @config[:plugins].nil? or
    not @config[:plugins].is_a?( Hash )
    
  )

end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



14
15
16
# File 'lib/langrove/root/config.rb', line 14

def application
  @application
end

#systemObject

Returns the value of attribute system.



13
14
15
# File 'lib/langrove/root/config.rb', line 13

def system
  @system
end

Instance Method Details

#get_daemon(name, component = nil, instance = true) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/langrove/root/config.rb', line 96

def get_daemon( name, component = nil, instance = true )

  #
  # Get instance[ ?.new ]
  #

end

#get_daemon_config(name, component = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/langrove/root/config.rb', line 69

def get_daemon_config( name, component = nil )

  #
  I.show "TODO: All config collection should pass through here"
  #
  
  @logger.debug "get_daemon_config( #{name}, #{component} )"

  raise LanGrove::DaemonConfigException.new(

    "No :daemons: named #{name}"

  ) if @config[:daemons][name].nil?

  return @config[:daemons][name] if component == nil?

  if @config[:daemons][name][component].nil?

    @logger.error "No #{component} defined for :daemons: named #{name}"
    return {}

  end

  return @config[:daemons][name][component]

end

#get_plugin(name = nil, type = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/langrove/root/config.rb', line 110

def get_plugin( name = nil, type = nil )
  
  #
  # Return a newly initialized instance of the 
  # plugin
  #
  
  raise LanGrove::DaemonConfigException.new(

    "No :plugins: defined"

  ) if @plugin_classes.size == 0
  
  
  if name.nil? and type.nil? 
    
    raise LanGrove::DaemonConfigException.new(

      "Too many :plugins: to default. Behaviour must specify."

    ) unless @plugin_classes.size == 1
    
    name = @plugin_classes.keys.first
    
    return @plugin_classes[name].new( 
    
      @root, @plugin_configs[name], nil
      
    )
    
  end
  
  raise LanGrove::DaemonConfigException.new(

    "Missing plugin definition for #{name}"

  ) if (
  
    not name.nil? and
    @plugin_classes[name].nil? 
  
  )
  
  raise LanGrove::DaemonConfigException.new(

    "Missing plugin definition for #{type}"

  ) if (
  
    not type.nil? and
    @plugin_types[ type ].nil? 
  
  )
  
  unless name.nil?
    
    return @plugin_classes[name].new( 
    
      @root, @plugin_configs[name], nil
      
    )
    
  end
  
  unless type.nil?
    
    raise LanGrove::DaemonConfigException.new(

      "Too many :plugins: of type #{type}. Behaviour must specify."

    ) if @plugin_types[ type ].length > 1
    
    name = @plugin_types[ type ].first
    
    return @plugin_classes[ name ].new( 
    
      @root, @plugin_configs[name], nil
      
    )
    
  end
  
end

#get_plugin_config(name) ⇒ Object



104
105
106
107
108
# File 'lib/langrove/root/config.rb', line 104

def get_plugin_config( name )

  @config[:plugins][name]

end