Class: Naether::Configurator

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

Overview

Naether runtime configuration

Instance Method Summary (collapse)

Constructor Details

- (Configurator) initialize(data = {})

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
34
# 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'),
    :version =>     version,
    :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

- (Object) method_missing(sym, *args)



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

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

Instance Method Details

- (Object) [](key)



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

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

- (Object) []=(key, value)



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

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

- (Object) update!(data)



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

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