config_context 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/config_context.rb +59 -49
  2. data/lib/version.rb +1 -1
  3. metadata +3 -3
@@ -1,61 +1,71 @@
1
1
  require 'yaml'
2
2
 
3
3
 
4
- module ConfigContext
5
- class ConfigContextError < StandardError
6
- end
4
+ module ConfigContext
5
+ extend self
7
6
 
8
- class << self
9
-
10
- def init
11
- @config ||= Hash.new
12
- end
13
-
14
- def method_missing( method, *arguments, &block )
15
-
16
- init
17
- if( method =~ /(.+)=$/)
18
-
19
- key = method.to_s.delete( '=$' ).to_sym
20
- @config[key] = (arguments.length == 1) ? arguments[0] : arguments
21
- else
22
- return @config[method] if @config.keys.include?( method )
23
- end
24
- end
7
+ class ConfigContextError < StandardError; end
25
8
 
26
- def configure
27
- yield self
28
- end
9
+ def init
10
+
11
+ @config ||= {}
12
+ end
29
13
 
30
- def []( key )
31
- init
32
- return @config[key] if @config[key]
33
- nil
34
- end
35
14
 
36
- def[]=( key, value )
37
- init
38
- @config[key]=value
39
- end
15
+ def method_missing( method, *arguments, &block )
40
16
 
41
- def all
42
- init
43
- @config
44
- end
45
-
46
- def load( config_file )
47
- init
48
- yf = YAML.load_file( config_file )
49
-
50
- yf.keys.each do |key|
51
-
52
- @config[key] = yf[key]
53
- end
54
- rescue Exception => e
55
- raise ConfigContextError.new( e.message )
56
- nil
17
+ self.init unless @config
18
+
19
+ if( method =~ /(.+)=$/)
20
+
21
+ config_key = method.to_s.delete( '=$' ).to_sym
22
+ @config[config_key] = (arguments.length == 1) ? arguments[0] : arguments
57
23
  else
58
- @config
24
+ return @config[method] if @config.keys.include?( method )
59
25
  end
60
26
  end
27
+
28
+
29
+ def configure
30
+
31
+ yield self
32
+ end
33
+
34
+
35
+ def []( key )
36
+
37
+ self.init unless @config
38
+
39
+ return @config[key] if @config[key]
40
+ nil
41
+ end
42
+
43
+
44
+ def[]=( key, value )
45
+
46
+ self.init unless @config
47
+
48
+ @config[key]=value
49
+ end
50
+
51
+
52
+ def all
53
+
54
+ self.init unless @config
55
+
56
+ @config
57
+ end
58
+
59
+
60
+ def load( config_file )
61
+
62
+ self.init unless @config
63
+
64
+ yf = YAML.load_file( config_file )
65
+ yf.keys.each { |key| @config[key] = yf[key] }
66
+ rescue Exception => e
67
+ raise ConfigContextError.new( e.message )
68
+ else
69
+ @config
70
+ end
61
71
  end
@@ -3,7 +3,7 @@ module ConfigContext
3
3
  INFO = {
4
4
  :major =>0,
5
5
  :minor =>2,
6
- :patch =>0
6
+ :patch =>1
7
7
  }
8
8
 
9
9
  NAME = 'config_context'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: config_context
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Javier Juarez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-04 00:00:00 +01:00
13
+ date: 2011-03-14 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  requirements: []
52
52
 
53
53
  rubyforge_project: http://github.com/jjuarez/config_context
54
- rubygems_version: 1.5.2
54
+ rubygems_version: 1.6.2
55
55
  signing_key:
56
56
  specification_version: 3
57
57
  summary: A Config Context for little applications