mooconfig 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -0
- data/lib/mooconfig.rb +7 -0
- data/lib/mooconfig/version.rb +1 -1
- data/test/mooconfig_test.rb +25 -4
- metadata +2 -2
data/README.md
CHANGED
@@ -24,6 +24,20 @@ gem install mooconfig
|
|
24
24
|
###Get configuration
|
25
25
|
puts "production configuration: #{mconf.get( "production" )['a']} \n default configuration: #{mconf.get['a']}"
|
26
26
|
|
27
|
+
|
28
|
+
###Observers
|
29
|
+
Register observers -- get notifications whenever set!(..) is performed
|
30
|
+
|
31
|
+
class MyConfigObserver
|
32
|
+
def initialize(conf)
|
33
|
+
conf.add_observer self # attach observer to the configuration
|
34
|
+
end
|
35
|
+
|
36
|
+
def update( c_id, c_data )
|
37
|
+
# .. get an update -- configuration id, and configuration data
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
27
41
|
##Test
|
28
42
|
via guard and guardminitest
|
29
43
|
see test folder
|
data/lib/mooconfig.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'mongo'
|
2
|
+
require 'observer'
|
2
3
|
|
3
4
|
module MooConfig
|
4
5
|
|
5
6
|
class Config
|
7
|
+
include Observable
|
8
|
+
|
6
9
|
DEFAULT_CONFIG_ID = 'default'
|
10
|
+
|
7
11
|
def initialize( host, port, db, conf_collection='config' )
|
8
12
|
@cCollection = Mongo::Connection.new( host, port ).db( db ).collection( conf_collection )
|
9
13
|
rescue => err
|
@@ -16,8 +20,11 @@ module MooConfig
|
|
16
20
|
end
|
17
21
|
|
18
22
|
def set!( config, config_id = DEFAULT_CONFIG_ID )
|
23
|
+
changed
|
19
24
|
@cCollection.update( {'_id'=>config_id }, {'_id'=>config_id, 'c' => config }, { :upsert => true } )
|
25
|
+
notify_observers( config_id , get( config_id ) )
|
20
26
|
end
|
27
|
+
|
21
28
|
end
|
22
29
|
|
23
30
|
end
|
data/lib/mooconfig/version.rb
CHANGED
data/test/mooconfig_test.rb
CHANGED
@@ -12,9 +12,12 @@ class MatchTest < MiniTest::Unit::TestCase
|
|
12
12
|
|
13
13
|
def setup
|
14
14
|
c = Mongo::Connection.new( HOST, PORT ).db( DB ).collection( 'config' )
|
15
|
-
c.update( { '_id' => 'default' }, { '_id' => 'default', 'c' => FIXED }, { :upsert => true } )
|
15
|
+
c.update( { '_id' => 'default' }, { '_id' => 'default', 'c' => FIXED }, { :upsert => true } )
|
16
16
|
end
|
17
17
|
|
18
|
+
def teardown
|
19
|
+
Mongo::Connection.new( HOST, PORT ).db( DB ).collection( 'config' ).remove( {'_id' => 'foo'})
|
20
|
+
end
|
18
21
|
|
19
22
|
def test_get
|
20
23
|
confie = MooConfig::Config.new( HOST, PORT, DB ).get
|
@@ -33,8 +36,26 @@ class MatchTest < MiniTest::Unit::TestCase
|
|
33
36
|
confie.set!( confie.get, 'foo' )
|
34
37
|
|
35
38
|
assert( confie.get( 'foo') == confie.get, "Failed in test_no_default either get or set!")
|
36
|
-
|
37
|
-
Mongo::Connection.new( HOST, PORT ).db( DB ).collection( 'config' ).remove( {'_id' => 'foo'})
|
38
39
|
end
|
39
|
-
|
40
|
+
|
41
|
+
def test_observer
|
42
|
+
confie = MooConfig::Config.new( HOST, PORT, DB )
|
43
|
+
obsr = TObserve::new confie
|
44
|
+
confie.set!( confie.get, 'foo' )
|
45
|
+
assert( obsr.touched && obsr.seen_id=='foo', "observer was not notified" )
|
46
|
+
end
|
47
|
+
|
48
|
+
class TObserve
|
49
|
+
attr :touched, false
|
50
|
+
attr :seen_id, "_"
|
51
|
+
|
52
|
+
def initialize(conf)
|
53
|
+
conf.add_observer self
|
54
|
+
end
|
55
|
+
def update( c_id, c_data )
|
56
|
+
@touched = true
|
57
|
+
@seen_id = 'foo'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
40
61
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mooconfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- ronbee
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-31 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Keeping and managing configuration via MongoDB. Light implementation.
|