Class: Naether::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/naether/configuration.rb

Overview

Naether runtime configuration

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Configurator

Returns a new instance of Configurator.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/naether/configuration.rb', line 8

def initialize(data={})
  gem_dir = File.expand_path("#{File.dirname(__FILE__)}/../../")
  
  version = nil
  
  # Load VERSION file from gem to VERSION var
  if File.exists?( File.expand_path("#{File.dirname(__FILE__)}/../../VERSION") )
    version = IO.read(File.expand_path("#{File.dirname(__FILE__)}/../../VERSION")).strip
      
  # VERSION file not found in gem dir, assume in current path, e.g.running from checkout
  else
    version = IO.read(File.expand_path("VERSION")).strip
  end
  
  
  
  @data = {
    :version => version,
    :gem_dir =>     gem_dir,
    :naether_jar => File.join( gem_dir, "core-#{version}.jar"),
    :platform =>    ($platform || RUBY_PLATFORM[/java/] || 'ruby'),
    :dependencies_yml => File.expand_path("#{File.dirname( __FILE__ )}/../../jar_dependencies.yml")
  }
  
  update!(data)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/naether/configuration.rb', line 53

def method_missing(sym, *args)
  if sym.to_s =~ /(.+)=$/
    self[$1] = args.first
  else
    self[sym]
  end
end

Instance Method Details

#[](key) ⇒ Object



41
42
43
# File 'lib/naether/configuration.rb', line 41

def [](key)
  @data[key.to_sym]
end

#[]=(key, value) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/naether/configuration.rb', line 45

def []=(key, value)
  if value.class == Hash
    @data[key.to_sym] = Config.new(value)
  else
    @data[key.to_sym] = value
  end
end

#update!(data) ⇒ Object



35
36
37
38
39
# File 'lib/naether/configuration.rb', line 35

def update!(data)
  data.each do |key, value|
    self[key] = value
  end
end