config_context 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- = Remote Executor:
1
+ = Config Context:
2
2
 
3
3
  Your DSL config context...
4
4
 
@@ -6,9 +6,8 @@ Your DSL config context...
6
6
 
7
7
  The latest stable version is published in gemcutter.
8
8
 
9
- gem source --add http://gemcutter.org
10
- gem install context_config
11
-
9
+ rake
10
+ gem install ./pk/config_context-${VERSION}.gem
12
11
 
13
12
  == How to use
14
13
 
@@ -26,14 +26,27 @@ module ConfigContext
26
26
  end
27
27
 
28
28
  def []( key )
29
- @config[key.to_sym] if @config
29
+
30
+ @config ||= {}
31
+
32
+ if( key.instance_of?( String ) )
33
+ @config[key] ? @config[key] : @config[key.to_sym]
34
+ elsif( key.instance_of?( Symbol ) )
35
+ @config[key] ? @config[key] : @config[key.to_s]
36
+ else
37
+ nil
38
+ end
30
39
  end
31
40
 
32
41
  def[]=( key, value )
33
- @config[key.to_sym] = value if @config
42
+
43
+ @config ||= {}
44
+ @config[key] = value
34
45
  end
35
46
 
36
47
  def all
48
+
49
+ @config ||= {}
37
50
  @config
38
51
  end
39
52
 
@@ -45,6 +58,7 @@ module ConfigContext
45
58
  yaml_config.keys.each { |key| @config[key] = yaml_config[key] }
46
59
  rescue Exception => e
47
60
  raise ConfigContextError.new( e.message )
61
+ nil
48
62
  else
49
63
  @config
50
64
  end
@@ -2,8 +2,8 @@ module Version
2
2
  module Info
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 0
6
- PATCH = 1
5
+ MINOR = 1
6
+ PATCH = 0
7
7
 
8
8
  end
9
9
 
@@ -4,10 +4,7 @@ require 'test/unit'
4
4
  require 'config_context'
5
5
 
6
6
 
7
- class TestLibraryFileName < Test::Unit::TestCase
8
-
9
- TEST_HASH = { :a=>'a', :b=>'b', :c=>'c' }
10
- TEST_FILE = File.join( File.dirname( __FILE__ ), %w[ .. fixtures test.yml] )
7
+ class TestConfigContext < Test::Unit::TestCase
11
8
 
12
9
  def test_case_configure
13
10
 
@@ -17,9 +14,13 @@ class TestLibraryFileName < Test::Unit::TestCase
17
14
  config.c = "c"
18
15
  end
19
16
 
17
+ ConfigContext["d"] = "d"
18
+
20
19
  assert_equal( ConfigContext.a, "a" )
21
20
  assert_equal( ConfigContext.b, "b" )
22
21
  assert_equal( ConfigContext.c, "c" )
22
+ assert_equal( ConfigContext["d"], "d" )
23
+ assert_nil( ConfigContext.d, "d" )
23
24
  end
24
25
 
25
26
  def test_case_all
@@ -29,18 +30,22 @@ class TestLibraryFileName < Test::Unit::TestCase
29
30
  config.b = "b"
30
31
  config.c = "c"
31
32
  end
33
+
34
+ ConfigContext["d"] = "d"
32
35
 
33
- assert_equal( ConfigContext.all, TEST_HASH )
36
+ assert_equal( ConfigContext.all, { :a=>'a', :b=>'b', :c=>'c', "d"=>'d' } )
34
37
  end
35
38
 
36
39
  def test_case_hash
37
40
 
38
41
  ConfigContext.configure do |config|
39
- config[:a] = "a"
40
- config[:b] = "b"
41
- config[:c] = "c"
42
+ config[:a] = "a"
43
+ config[:b] = "b"
44
+ config[:c] = "c"
42
45
  end
43
46
 
47
+ ConfigContext["d"] = "d"
48
+
44
49
  assert_equal( ConfigContext.a, "a" )
45
50
  assert_equal( ConfigContext.b, "b" )
46
51
  assert_equal( ConfigContext.c, "c" )
@@ -48,13 +53,16 @@ class TestLibraryFileName < Test::Unit::TestCase
48
53
  assert_equal( ConfigContext[:a], "a" )
49
54
  assert_equal( ConfigContext[:b], "b" )
50
55
  assert_equal( ConfigContext[:c], "c" )
56
+
57
+ assert_equal( ConfigContext[:d], "d" )
58
+ assert_equal( ConfigContext["d"], "d" )
51
59
 
52
- assert_equal( ConfigContext.all, TEST_HASH )
60
+ assert_equal( ConfigContext.all, { :a=>'a', :b=>'b', :c=>'c', "d"=>'d' } )
53
61
  end
54
62
 
55
63
  def test_case_yaml
56
64
 
57
- ConfigContext.load( TEST_FILE )
58
- assert_equal( ConfigContext.all, TEST_HASH )
65
+ ConfigContext.load( File.join( File.dirname( __FILE__ ), %w[ .. fixtures test.yml] ) )
66
+ assert_equal( ConfigContext.all, { :a=>'a', :b=>'b', :c=>'c', "d"=>'d' } )
59
67
  end
60
68
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: config_context
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.1.0
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-02-14 00:00:00 +01:00
13
+ date: 2011-02-21 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16