mooconfig 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH << "."
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in mooconfig.gemspec
6
+ gemspec
7
+
8
+ gem 'mongo'
9
+ gem 'growl'
10
+ gem 'guard-minitest'
11
+ gem 'rb-fsevent'
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'minitest' do
5
+ # with Minitest::Unit
6
+ watch(/^test\/(.*).rb/) { "test" }
7
+ watch(/^lib\/(.*)([^\/]+)\.rb/) { "test" }
8
+ watch(/^test\/test_helper.rb/) { "test" }
9
+
10
+ # with Minitest::Spec
11
+ # watch(/^spec\/(.*)_spec.rb/)
12
+ # watch(/^lib\/(.*)\.rb/) { |m| "spec/#{m[1]}_spec.rb" }
13
+ # watch(/^spec\/spec_helper.rb/) { "spec" }
14
+ end
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ #The what?
2
+ Doing configuration with MongoDB
3
+
4
+ - - -
5
+ #The how?
6
+
7
+ ##Preliminaries
8
+ >MongoDB (http://www.mongodb.org/)
9
+ >See Gemfile for dependancies
10
+
11
+ ##Usage
12
+ >host = 'localhost'; port = 21017; db='foo'
13
+
14
+ ###Init
15
+ >mconf = MooConfig::Config.new( host, port, db )
16
+ ###Set configuration
17
+ >mconf.set!( { "a" => true, "b" => { "b1" => "1", "b2" => 1234, "b3" => [ "z", 3, "e" ] }, "c" => "asdf" } ) # default config
18
+ >mconf.set!( { "a" => false, "b" => { "b1" => "1", "b2" => 1234, "b3" => [ "z", 3, "e" ] }, "c" => "asdf" }, "production" )
19
+ ###Get configuration
20
+ >puts "production configuration: #{mconf.get( "production" )['a']} \n default configuration: #{mconf.get['a']}"
21
+
22
+ ##Test
23
+ > via guard and guardminitest
24
+ > see test folder
25
+
26
+ #License
27
+ ##The MIT License
28
+ ``
29
+ Copyright (c) 2010 ronbee.github@gmail.com
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.''
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,3 @@
1
+ module MooConfig
2
+ VERSION = "0.1.1"
3
+ end
data/lib/mooconfig.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'mongo'
2
+
3
+ module MooConfig
4
+
5
+ class Config
6
+ DEFAULT_CONFIG_ID = 'default'
7
+ def initialize( host, port, db )
8
+ @cCollection = Mongo::Connection.new( host, port ).db( db ).collection( 'config' )
9
+ rescue => err
10
+ puts "Config::initialize something is wrong with mongo details [host:#{host}, port:#{port}, db:#{db}]"
11
+ raise err
12
+ end
13
+
14
+ def get( config_id = DEFAULT_CONFIG_ID )
15
+ @cCollection.find_one( { '_id' => config_id } )['c'] rescue {}
16
+ end
17
+
18
+ def set!( config, config_id = DEFAULT_CONFIG_ID )
19
+ @cCollection.update( {'_id'=>config_id }, {'_id'=>config_id, 'c' => config }, { :upsert => true } )
20
+ end
21
+ end
22
+
23
+ end
24
+
data/mooconfig.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mooconfig/version"
4
+ require "mooconfig.rb"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "mooconfig"
8
+ s.version = MooConfig::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["ronbee"]
11
+ s.email = ["ronbee.github@gmail.com"]
12
+ s.homepage = "https://github.com/ronbee"
13
+ s.summary = %q{Doing config with mongodb}
14
+ s.description = %q{Keeping and managing configuration via MongoDB. Light implementation.}
15
+
16
+ s.rubyforge_project = "mooconfig"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,40 @@
1
+ require 'minitest/unit'
2
+
3
+ require File.dirname(__FILE__) + '/../lib/mooconfig.rb'
4
+
5
+ class MatchTest < MiniTest::Unit::TestCase
6
+
7
+ HOST = 'localhost'
8
+ PORT = 27017
9
+ DB = 'foo'
10
+
11
+ FIXED = { 'a' => { "a1"=>1, "a2"=>"2" } , 'b' => false }
12
+
13
+ def setup
14
+ c = Mongo::Connection.new( HOST, PORT ).db( DB ).collection( 'config' )
15
+ c.update( { '_id' => 'default' }, { '_id' => 'default', 'c' => FIXED }, { :upsert => true } )
16
+ end
17
+
18
+
19
+ def test_get
20
+ confie = MooConfig::Config.new( HOST, PORT, DB ).get
21
+
22
+ assert( confie == FIXED, "get retrivied #{confie.inspect} when expected #{FIXED.inspect}" )
23
+ end
24
+
25
+ def test_set!
26
+ confie = MooConfig::Config.new( HOST, PORT, DB )
27
+ confie.set!( { 'b' => true} )
28
+ assert( confie.get['b'], "failed to update 'b'=>false" )
29
+ end
30
+
31
+ def test_no_default
32
+ confie = MooConfig::Config.new( HOST, PORT, DB )
33
+ confie.set!( confie.get, 'foo' )
34
+
35
+ 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
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mooconfig
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.1
6
+ platform: ruby
7
+ authors:
8
+ - ronbee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-11 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: Keeping and managing configuration via MongoDB. Light implementation.
17
+ email:
18
+ - ronbee.github@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - Gemfile
27
+ - Guardfile
28
+ - README.md
29
+ - Rakefile
30
+ - lib/mooconfig.rb
31
+ - lib/mooconfig/version.rb
32
+ - mooconfig.gemspec
33
+ - test/mooconfig_test.rb
34
+ homepage: https://github.com/ronbee
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ requirements: []
55
+
56
+ rubyforge_project: mooconfig
57
+ rubygems_version: 1.8.5
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Doing config with mongodb
61
+ test_files:
62
+ - test/mooconfig_test.rb