mongoid-app_settings 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "mongoid"
4
+ gem "activesupport"
5
+
6
+ group :development do
7
+ gem "database_cleaner"
8
+ gem "bson_ext", "1.4.1"
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "jeweler", "~> 1.6.4"
11
+ gem "rcov", ">= 0"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.1.1)
5
+ activesupport (= 3.1.1)
6
+ builder (~> 3.0.0)
7
+ i18n (~> 0.6)
8
+ activesupport (3.1.1)
9
+ multi_json (~> 1.0)
10
+ bson (1.4.1)
11
+ bson_ext (1.4.1)
12
+ builder (3.0.0)
13
+ database_cleaner (0.6.7)
14
+ diff-lcs (1.1.3)
15
+ git (1.2.5)
16
+ i18n (0.6.0)
17
+ jeweler (1.6.4)
18
+ bundler (~> 1.0)
19
+ git (>= 1.2.5)
20
+ rake
21
+ mongo (1.4.1)
22
+ bson (= 1.4.1)
23
+ mongoid (2.3.2)
24
+ activemodel (~> 3.1)
25
+ mongo (~> 1.4)
26
+ tzinfo (~> 0.3.22)
27
+ multi_json (1.0.3)
28
+ rake (0.9.2.2)
29
+ rcov (0.9.11)
30
+ rspec (2.3.0)
31
+ rspec-core (~> 2.3.0)
32
+ rspec-expectations (~> 2.3.0)
33
+ rspec-mocks (~> 2.3.0)
34
+ rspec-core (2.3.1)
35
+ rspec-expectations (2.3.0)
36
+ diff-lcs (~> 1.1.2)
37
+ rspec-mocks (2.3.0)
38
+ tzinfo (0.3.30)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ activesupport
45
+ bson_ext (= 1.4.1)
46
+ database_cleaner
47
+ jeweler (~> 1.6.4)
48
+ mongoid
49
+ rcov
50
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Marten Veldthuis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,40 @@
1
+ # mongoid-app_settings
2
+
3
+ ## Usage
4
+
5
+ Simply create some class and include `Mongoid::AppSettings`.
6
+
7
+ class MySettings
8
+ include Mongoid::AppSettings
9
+
10
+ default :enable_my_feature, true
11
+ end
12
+
13
+ Then you can do things like:
14
+
15
+ MySettings.enable_my_feature
16
+ => true
17
+
18
+ MySettings.enable_my_feature = false
19
+ MySettings.enable_my_feature
20
+ => false
21
+
22
+ MySettings.something_else = "FooBar"
23
+ MySettings.something_else
24
+ => "FooBar"
25
+
26
+ # Contributing to mongoid-app_settings
27
+
28
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
29
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
30
+ * Fork the project
31
+ * Start a feature/bugfix branch
32
+ * Commit and push until you are happy with your contribution
33
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
34
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
35
+
36
+ == Copyright
37
+
38
+ Copyright (c) 2011 Marten Veldthuis. See LICENSE.txt for
39
+ further details.
40
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "mongoid-app_settings"
18
+ gem.homepage = "http://github.com/marten/mongoid-app_settings"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Store settings for your application in MongoDB}
21
+ gem.description = %Q{Mongoid::AppSettings allows you to store settings in MongoDB, and access them easily}
22
+ gem.email = "marten@veldthuis.com"
23
+ gem.authors = ["Marten Veldthuis"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "mongoid-app_settings #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,49 @@
1
+ require 'mongoid'
2
+
3
+ module Mongoid
4
+ module AppSettings
5
+ extend ActiveSupport::Concern
6
+
7
+ class Record
8
+ include Mongoid::Document
9
+ identity type: String
10
+ end
11
+
12
+ module ClassMethods
13
+ def method_missing(name, *args, &block)
14
+ if name.to_s =~ /^(.*)=$/
15
+ set_value($1, args[0])
16
+ else
17
+ get_value(name.to_s)
18
+ end
19
+ end
20
+
21
+ def defaults
22
+ @defaults ||= {}
23
+ end
24
+
25
+ def default(name, value)
26
+ defaults[name.to_s] = value
27
+ end
28
+
29
+ def record
30
+ return @record if @record
31
+ @record = Record.find_or_create_by(id: "settings")
32
+ end
33
+
34
+ def get_value(name)
35
+ if record.attributes.include?(name)
36
+ record.read_attribute(name)
37
+ else
38
+ defaults[name]
39
+ end
40
+ end
41
+
42
+ def set_value(name, value)
43
+ record.write_attribute(name, value)
44
+ record.save
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Mongoid::AppSettings" do
4
+ let(:settings) do
5
+ settings = Class.new
6
+ settings.instance_eval { include Mongoid::AppSettings }
7
+ settings
8
+ end
9
+
10
+ it "should be possible to save a setting" do
11
+ settings.something = "some nice value"
12
+ settings.something.should == "some nice value"
13
+ end
14
+
15
+ it "should save settings outside of itself" do
16
+ settings.something = "some nice value"
17
+ fresh_settings = Class.new
18
+ fresh_settings.instance_eval { include Mongoid::AppSettings }
19
+ fresh_settings.something.should == "some nice value"
20
+ end
21
+
22
+ it "should be possible to specify default values" do
23
+ settings.instance_eval do
24
+ default :foo, "bar"
25
+ end
26
+ settings.foo.should == "bar"
27
+ end
28
+
29
+ it "should be possible to overwrite a default value" do
30
+ settings.instance_eval { default :foo, "bar" }
31
+ settings.foo = "baz"
32
+ settings.foo.should == "baz"
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'database_cleaner'
5
+ require 'mongoid'
6
+ require 'mongoid-app_settings'
7
+
8
+ Mongoid.configure do |config|
9
+ name = "mongoid-app_settings_test"
10
+ host = "localhost"
11
+ config.master = Mongo::Connection.new.db(name)
12
+ config.autocreate_indexes = true
13
+ end
14
+
15
+ # Requires supporting files with custom matchers and macros, etc,
16
+ # in ./support/ and its subdirectories.
17
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
18
+
19
+ RSpec.configure do |config|
20
+ config.before(:suite) do
21
+ DatabaseCleaner.strategy = :truncation
22
+ DatabaseCleaner.clean_with(:truncation)
23
+ end
24
+
25
+ config.before(:each) do
26
+ DatabaseCleaner.start
27
+ end
28
+
29
+ config.after(:each) do
30
+ DatabaseCleaner.clean
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-app_settings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marten Veldthuis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: &16903940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *16903940
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &16903000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *16903000
36
+ - !ruby/object:Gem::Dependency
37
+ name: database_cleaner
38
+ requirement: &16901940 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *16901940
47
+ - !ruby/object:Gem::Dependency
48
+ name: bson_ext
49
+ requirement: &16900960 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - =
53
+ - !ruby/object:Gem::Version
54
+ version: 1.4.1
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *16900960
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &16899860 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 2.3.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *16899860
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &16898960 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.6.4
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *16898960
80
+ - !ruby/object:Gem::Dependency
81
+ name: rcov
82
+ requirement: &16897980 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *16897980
91
+ description: Mongoid::AppSettings allows you to store settings in MongoDB, and access
92
+ them easily
93
+ email: marten@veldthuis.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.markdown
99
+ files:
100
+ - .document
101
+ - .rspec
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.markdown
106
+ - Rakefile
107
+ - VERSION
108
+ - lib/mongoid-app_settings.rb
109
+ - spec/mongoid-app_settings_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: http://github.com/marten/mongoid-app_settings
112
+ licenses:
113
+ - MIT
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ segments:
125
+ - 0
126
+ hash: 1976003032920280521
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 1.8.10
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Store settings for your application in MongoDB
139
+ test_files: []