nifty_settings 1.1.6 → 1.1.7
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 +4 -4
- data/README.md +97 -0
- data/config/.gitkeep +0 -0
- data/lib/nifty_settings/settings.rb +6 -3
- data/lib/nifty_settings/version.rb +1 -1
- data/nifty_settings.gemspec +3 -3
- data/spec/nifty_settings/settings_spec.rb +31 -22
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c4cd283e57e135e322311d816dee8a29df9da4b
|
4
|
+
data.tar.gz: a354ba55bb47ad7b8d6915e820e87a6a2d5ca36a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e16f56f7ada98619ec65977970c94e607f1bf910442a5a085f6e35528ec315adc48513077bb1e4d9c30d0f512f3f5bae7016f38a038e63c35ca74ccc801d8820
|
7
|
+
data.tar.gz: 3d3ce608e8d4664b7cb218f8902bc05ef252645206e8a48f6b85bfe456f62fc8c9f4e436f6840aab43233f8296ee52fc7b8276999be5a422df772bbc4bb07979
|
data/README.md
CHANGED
@@ -4,3 +4,100 @@
|
|
4
4
|
[](http://travis-ci.org/krautcomputing/nifty_settings)
|
5
5
|
[](https://gemnasium.com/krautcomputing/nifty_settings)
|
6
6
|
[](https://codeclimate.com/github/krautcomputing/nifty_settings)
|
7
|
+
|
8
|
+
A nifty way to save and access application-wide settings. Great for managing different configurations for different Rails/Rack environments.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'nifty_settings'
|
16
|
+
```
|
17
|
+
|
18
|
+
Add your settings in YAML format to `config/settings.yml`
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Let's say we have the following settings file:
|
23
|
+
|
24
|
+
```yaml
|
25
|
+
default:
|
26
|
+
some_service:
|
27
|
+
use_live?: false
|
28
|
+
|
29
|
+
development:
|
30
|
+
foo: bar_dev
|
31
|
+
wibble:
|
32
|
+
wobble: wubble
|
33
|
+
some_collection:
|
34
|
+
- first
|
35
|
+
- second
|
36
|
+
|
37
|
+
test:
|
38
|
+
foo: bar_test
|
39
|
+
|
40
|
+
production:
|
41
|
+
foo: bar
|
42
|
+
some_service:
|
43
|
+
use_live?: true
|
44
|
+
key: my_secret_key
|
45
|
+
timeout: 20
|
46
|
+
```
|
47
|
+
|
48
|
+
We can access the settings by using `Settings.key_name`. A combination of default values and environment specific settings can be used. NiftySettings will use the correct setting based on your current environment.
|
49
|
+
|
50
|
+
Let's use the above settings in a development environment:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
=> Settings.foo
|
54
|
+
"bar_dev"
|
55
|
+
=> Settings.some_collection
|
56
|
+
["first", "second"]
|
57
|
+
```
|
58
|
+
|
59
|
+
Settings can be nested:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
=> Settings.wibble.wobble
|
63
|
+
"wubble"
|
64
|
+
```
|
65
|
+
|
66
|
+
If a setting isn't defined for the current environment, it will fall back to the default value:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
=> Settings.some_service.use_live?
|
70
|
+
false
|
71
|
+
```
|
72
|
+
|
73
|
+
And if the setting doesn't exist at all, it just returns `nil`:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
=> Settings.fizzbuzz
|
77
|
+
nil
|
78
|
+
```
|
79
|
+
|
80
|
+
Using the same settings in a production environment, it picks up the environment specific settings:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
=> Settings.foo
|
84
|
+
"bar"
|
85
|
+
=> Settings.some_service.use_live?
|
86
|
+
true
|
87
|
+
=> Settings.some_service.timeout
|
88
|
+
20
|
89
|
+
```
|
90
|
+
|
91
|
+
## Configuration
|
92
|
+
|
93
|
+
### Specify configuration file
|
94
|
+
|
95
|
+
By default NiftySettings looks for settings in `config/settings.yml`, but this can be changed by setting the path in an initializer.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
Settings.settings_path = '/home/shared/other_settings.yml'
|
99
|
+
```
|
100
|
+
|
101
|
+
### Namespacing
|
102
|
+
|
103
|
+
During initialization, NiftySettings checks if there already is a `Settings` module. If it finds one (e.g. if you have a Rails model called `Settings`), NiftySettings doesn't touch it and your settings are available as `NiftySettings::Settings` in your application. If a `Settings` module is not found, `NiftySettings` uses it and you can access your Settings as `Settings`.
|
data/config/.gitkeep
ADDED
File without changes
|
@@ -162,10 +162,13 @@ unless Hash.new.respond_to?(:deep_merge)
|
|
162
162
|
self.dup.tap do |this_hash|
|
163
163
|
other_hash.each_pair do |k, v|
|
164
164
|
tv = this_hash[k]
|
165
|
-
|
166
|
-
|
165
|
+
this_hash[k] = case
|
166
|
+
when tv.is_a?(Hash) && v.is_a?(Hash)
|
167
|
+
tv.deep_merge(v, &block)
|
168
|
+
when block_given? && tv
|
169
|
+
block.call(k, tv, v)
|
167
170
|
else
|
168
|
-
|
171
|
+
v
|
169
172
|
end
|
170
173
|
end
|
171
174
|
end
|
data/nifty_settings.gemspec
CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.platform = Gem::Platform::RUBY
|
10
10
|
gem.author = 'Manuel Meurer'
|
11
11
|
gem.email = 'manuel@krautcomputing.com'
|
12
|
-
gem.summary = '
|
13
|
-
gem.description = '
|
14
|
-
gem.homepage = 'http://krautcomputing.github.io/nifty_settings'
|
12
|
+
gem.summary = 'A nifty way to save and access application-wide settings.'
|
13
|
+
gem.description = 'A nifty way to save and access application-wide settings.'
|
14
|
+
gem.homepage = 'http://krautcomputing.github.io/nifty_settings/'
|
15
15
|
gem.license = 'MIT'
|
16
16
|
|
17
17
|
gem.files = `git ls-files`.split($/)
|
@@ -87,33 +87,42 @@ describe NiftySettings::Settings do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
describe '.load_from_file' do
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
context 'without Rails and RACK_ENV' do
|
91
|
+
before do
|
92
|
+
# Make sure `ENV['RACK_ENV']` is not set and Rails is not loaded
|
93
|
+
# so that the loaded settings are not scoped to the env
|
94
|
+
ENV['RACK_ENV'] = nil
|
95
|
+
raise 'Rails should not be loaded.' if defined?(Rails)
|
96
|
+
end
|
93
97
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
FileUtils.mkdir_p config_dir
|
98
|
-
FileUtils.cp settings_file, config_dir
|
98
|
+
it 'loads the settings from the default location' do
|
99
|
+
# Reset settings path in case it has been modified
|
100
|
+
NiftySettings::Settings.settings_path = nil
|
99
101
|
|
100
|
-
|
101
|
-
|
102
|
+
# Copy settings file to default location
|
103
|
+
settings_file = File.expand_path('../../support/settings.yml', __FILE__)
|
104
|
+
default_settings_file = File.expand_path('../../../config/settings.yml', __FILE__)
|
105
|
+
FileUtils.mkdir_p File.dirname(default_settings_file)
|
106
|
+
FileUtils.cp settings_file, default_settings_file
|
102
107
|
|
103
|
-
|
104
|
-
|
105
|
-
end
|
108
|
+
settings = NiftySettings::Settings.load_from_file
|
109
|
+
expect(settings).to eq('foo' => 'bar')
|
106
110
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
expect(settings).to eq('foo' => 'bar')
|
111
|
-
end
|
111
|
+
# Delete settings file again
|
112
|
+
FileUtils.rm default_settings_file
|
113
|
+
end
|
112
114
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
115
|
+
it 'can load the settings from a custom location' do
|
116
|
+
NiftySettings::Settings.settings_path = File.expand_path('../../support/settings.yml', __FILE__)
|
117
|
+
settings = NiftySettings::Settings.load_from_file
|
118
|
+
expect(settings).to eq('foo' => 'bar')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'can load empty settings' do
|
122
|
+
NiftySettings::Settings.settings_path = File.expand_path('../../support/settings_empty.yml', __FILE__)
|
123
|
+
settings = NiftySettings::Settings.load_from_file
|
124
|
+
expect(settings).to eq({})
|
125
|
+
end
|
117
126
|
end
|
118
127
|
end
|
119
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nifty_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Meurer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 4.2.0
|
69
|
-
description:
|
69
|
+
description: A nifty way to save and access application-wide settings.
|
70
70
|
email: manuel@krautcomputing.com
|
71
71
|
executables: []
|
72
72
|
extensions: []
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
|
+
- config/.gitkeep
|
82
83
|
- lib/nifty_settings.rb
|
83
84
|
- lib/nifty_settings/railtie.rb
|
84
85
|
- lib/nifty_settings/settings.rb
|
@@ -88,7 +89,7 @@ files:
|
|
88
89
|
- spec/spec_helper.rb
|
89
90
|
- spec/support/settings.yml
|
90
91
|
- spec/support/settings_empty.yml
|
91
|
-
homepage: http://krautcomputing.github.io/nifty_settings
|
92
|
+
homepage: http://krautcomputing.github.io/nifty_settings/
|
92
93
|
licenses:
|
93
94
|
- MIT
|
94
95
|
metadata: {}
|
@@ -111,7 +112,7 @@ rubyforge_project:
|
|
111
112
|
rubygems_version: 2.2.2
|
112
113
|
signing_key:
|
113
114
|
specification_version: 4
|
114
|
-
summary:
|
115
|
+
summary: A nifty way to save and access application-wide settings.
|
115
116
|
test_files:
|
116
117
|
- spec/nifty_settings/settings_spec.rb
|
117
118
|
- spec/spec_helper.rb
|