mongoid-settings 0.5.0
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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +7 -0
- data/lib/mongoid-settings.rb +50 -0
- data/lib/mongoid-settings/version.rb +5 -0
- data/mongoid-settings.gemspec +25 -0
- data/spec/mongoid-settings_spec.rb +41 -0
- data/spec/spec_helper.rb +19 -0
- metadata +114 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2ae3b889017f9e5749eb896f92395ffe76975bb2
|
|
4
|
+
data.tar.gz: 1ed412e073e1030f1cccda291243e396855e4410
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 61d83bd51b893ec02ff3afc8c49a74459cb0da1ef355786bc898f5ca36714abff225e89eafdc55080207b8f944d71422f3940dc5e90c561adb80d71bcd04450e
|
|
7
|
+
data.tar.gz: c1bd5f8185345f25b759b87e054e4f65a6334125877979bf31023f91a102dcc14cadff1d43a04ac3cea035589303b1001bb9868077712ae1b9a5e4f5ae41ad0c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Andrei Gladkyi
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# mongoid-settings
|
|
2
|
+
|
|
3
|
+
A simple gem to store application settings into a MongoDB collection.
|
|
4
|
+
|
|
5
|
+
[](https://travis-ci.org/agladkyi/mongoid-settings)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
gem 'mongoid-settings'
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install mongoid-settings
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Create a model which includes `Mongoid::Settings`.
|
|
24
|
+
|
|
25
|
+
class ApplicationSettings
|
|
26
|
+
include Mongoid::Settings
|
|
27
|
+
|
|
28
|
+
setting :some_name, type: String, default: 'some value'
|
|
29
|
+
setting :another
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
It will allow to use:
|
|
33
|
+
|
|
34
|
+
ApplicationSettings.some_name
|
|
35
|
+
=> 'some value'
|
|
36
|
+
|
|
37
|
+
ApplicationSettings.some_name = 'another value'
|
|
38
|
+
ApplicationSettings.some_name
|
|
39
|
+
=> 'another value'
|
|
40
|
+
|
|
41
|
+
ApplicationSettings[:another] = 100
|
|
42
|
+
ApplicationSettings[:another]
|
|
43
|
+
=> 100
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
Licensed under the MIT license.
|
|
48
|
+
|
|
49
|
+
## Contributing
|
|
50
|
+
|
|
51
|
+
1. Fork it
|
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'mongoid'
|
|
2
|
+
require 'mongoid-settings/version'
|
|
3
|
+
|
|
4
|
+
module Mongoid
|
|
5
|
+
module Settings
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
class Storage
|
|
9
|
+
include Mongoid::Document
|
|
10
|
+
store_in(collection: 'settings')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module ClassMethods
|
|
14
|
+
def [](name)
|
|
15
|
+
storage[name].presence || defaults[name]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def []= (name, value)
|
|
19
|
+
storage.update_attribute(name, value) if defaults.include?(name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def reload!
|
|
23
|
+
@storage = load_storage
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def setting(name, options = {})
|
|
29
|
+
Storage.class_eval do
|
|
30
|
+
field(name, options)
|
|
31
|
+
end
|
|
32
|
+
defaults[name] = options[:default]
|
|
33
|
+
define_singleton_method(name) { self[name] }
|
|
34
|
+
define_singleton_method("#{name}=") { |value| self[name] = value }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def defaults
|
|
38
|
+
@defaults ||= {}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def storage
|
|
42
|
+
@storage ||= load_storage
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def load_storage
|
|
46
|
+
Storage.first_or_create
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'mongoid-settings/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'mongoid-settings'
|
|
8
|
+
spec.version = Mongoid::Settings::VERSION
|
|
9
|
+
spec.authors = ['Andrei Gladkyi']
|
|
10
|
+
spec.email = ['arg@arglabs.net']
|
|
11
|
+
spec.description = 'A simple gem to store application settings into a MongoDB collection.'
|
|
12
|
+
spec.summary = 'A simple gem to store application settings into a MongoDB collection.'
|
|
13
|
+
spec.homepage = 'https://github.com/agladkyi/mongoid-settings'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.test_files = spec.files.grep(/^spec\//)
|
|
18
|
+
spec.require_paths = ['lib']
|
|
19
|
+
|
|
20
|
+
spec.add_runtime_dependency 'mongoid', '>= 3.0.0'
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency 'bundler'
|
|
23
|
+
spec.add_development_dependency 'rake'
|
|
24
|
+
spec.add_development_dependency 'rspec', '>= 2.0.0'
|
|
25
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class Settings
|
|
2
|
+
include Mongoid::Settings
|
|
3
|
+
setting :some_integer, type: Integer, default: 100
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
describe Mongoid::Settings do
|
|
7
|
+
before do
|
|
8
|
+
Settings.reload!
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'fills settings with their default values' do
|
|
12
|
+
expect(Settings.some_integer).to eq(100)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'allows to set values' do
|
|
16
|
+
Settings.some_integer = 200
|
|
17
|
+
expect(Settings.some_integer).to eq(200)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe '[]' do
|
|
21
|
+
it 'returns correct values' do
|
|
22
|
+
expect(Settings[:some_integer]).to eq(100)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'returns nil for non-existent settings' do
|
|
26
|
+
expect(Settings[:other]).to be_nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '[]=' do
|
|
31
|
+
it 'correctly sets the new value' do
|
|
32
|
+
Settings[:some_integer] = 300
|
|
33
|
+
expect(Settings[:some_integer]).to eq(300)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "doesn't set value for non-existent setting" do
|
|
37
|
+
Settings[:other] = 'test'
|
|
38
|
+
expect(Settings[:other]).to be_nil
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
|
|
4
|
+
require 'mongoid-settings'
|
|
5
|
+
|
|
6
|
+
Mongoid.configure do |config|
|
|
7
|
+
config.connect_to 'mongoid_settings_test'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.expect_with :rspec do |c|
|
|
12
|
+
c.syntax = :expect
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
config.before :each do
|
|
16
|
+
Mongoid.purge!
|
|
17
|
+
Mongoid::IdentityMap.clear
|
|
18
|
+
end
|
|
19
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mongoid-settings
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.5.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrei Gladkyi
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: mongoid
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 3.0.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 3.0.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 2.0.0
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 2.0.0
|
|
69
|
+
description: A simple gem to store application settings into a MongoDB collection.
|
|
70
|
+
email:
|
|
71
|
+
- arg@arglabs.net
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- .gitignore
|
|
77
|
+
- .rspec
|
|
78
|
+
- .travis.yml
|
|
79
|
+
- Gemfile
|
|
80
|
+
- LICENSE.txt
|
|
81
|
+
- README.md
|
|
82
|
+
- Rakefile
|
|
83
|
+
- lib/mongoid-settings.rb
|
|
84
|
+
- lib/mongoid-settings/version.rb
|
|
85
|
+
- mongoid-settings.gemspec
|
|
86
|
+
- spec/mongoid-settings_spec.rb
|
|
87
|
+
- spec/spec_helper.rb
|
|
88
|
+
homepage: https://github.com/agladkyi/mongoid-settings
|
|
89
|
+
licenses:
|
|
90
|
+
- MIT
|
|
91
|
+
metadata: {}
|
|
92
|
+
post_install_message:
|
|
93
|
+
rdoc_options: []
|
|
94
|
+
require_paths:
|
|
95
|
+
- lib
|
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - '>='
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: '0'
|
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
|
+
requirements:
|
|
103
|
+
- - '>='
|
|
104
|
+
- !ruby/object:Gem::Version
|
|
105
|
+
version: '0'
|
|
106
|
+
requirements: []
|
|
107
|
+
rubyforge_project:
|
|
108
|
+
rubygems_version: 2.1.3
|
|
109
|
+
signing_key:
|
|
110
|
+
specification_version: 4
|
|
111
|
+
summary: A simple gem to store application settings into a MongoDB collection.
|
|
112
|
+
test_files:
|
|
113
|
+
- spec/mongoid-settings_spec.rb
|
|
114
|
+
- spec/spec_helper.rb
|