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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d69c55980e686ed5ccc21d0d8fd7de395167016c
4
- data.tar.gz: a4c73431de6fe4842197714100f6c2de742506ce
3
+ metadata.gz: 8c4cd283e57e135e322311d816dee8a29df9da4b
4
+ data.tar.gz: a354ba55bb47ad7b8d6915e820e87a6a2d5ca36a
5
5
  SHA512:
6
- metadata.gz: e98c48636bb4061f903d5c5bed4094125b55e21de576cd754f47e90cb1ccd0a730d2e47ea8f159d513c102db987aa7fe00227ad02b9ff55ace828a1bfe068b6e
7
- data.tar.gz: 739d7a10134c442bc00b3bec378d36725a3ca93111ec42271fa71051fcbb98e056c7816450600da16cd5bc97c803a0f1f4ed86392e376ef40fe0174bef3ca61a
6
+ metadata.gz: e16f56f7ada98619ec65977970c94e607f1bf910442a5a085f6e35528ec315adc48513077bb1e4d9c30d0f512f3f5bae7016f38a038e63c35ca74ccc801d8820
7
+ data.tar.gz: 3d3ce608e8d4664b7cb218f8902bc05ef252645206e8a48f6b85bfe456f62fc8c9f4e436f6840aab43233f8296ee52fc7b8276999be5a422df772bbc4bb07979
data/README.md CHANGED
@@ -4,3 +4,100 @@
4
4
  [![Build Status](https://secure.travis-ci.org/krautcomputing/nifty_settings.png)](http://travis-ci.org/krautcomputing/nifty_settings)
5
5
  [![Dependency Status](https://gemnasium.com/krautcomputing/nifty_settings.png)](https://gemnasium.com/krautcomputing/nifty_settings)
6
6
  [![Code Climate](https://codeclimate.com/github/krautcomputing/nifty_settings.png)](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`.
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
- if tv.is_a?(Hash) && v.is_a?(Hash)
166
- this_hash[k] = tv.deep_merge(v, &block)
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
- this_hash[k] = block && tv ? block.call(k, tv, v) : v
171
+ v
169
172
  end
170
173
  end
171
174
  end
@@ -1,3 +1,3 @@
1
1
  module NiftySettings
2
- VERSION = '1.1.6'
2
+ VERSION = '1.1.7'
3
3
  end
@@ -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 = 'Settings'
13
- gem.description = 'Settings'
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
- it 'loads the settings from the default location' do
91
- # Reset settings path in case it has been modified
92
- NiftySettings::Settings.settings_path = nil
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
- # Copy settings file to default location
95
- settings_file = File.expand_path('../../support/settings.yml', __FILE__)
96
- config_dir = File.expand_path('../../../config', __FILE__)
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
- settings = NiftySettings::Settings.load_from_file
101
- expect(settings).to eq('foo' => 'bar')
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
- # Delete settings file again
104
- FileUtils.rm File.join(config_dir, 'settings.yml')
105
- end
108
+ settings = NiftySettings::Settings.load_from_file
109
+ expect(settings).to eq('foo' => 'bar')
106
110
 
107
- it 'can load the settings from a custom location' do
108
- NiftySettings::Settings.settings_path = File.expand_path('../../support/settings.yml', __FILE__)
109
- settings = NiftySettings::Settings.load_from_file
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
- it 'can load empty settings' do
114
- NiftySettings::Settings.settings_path = File.expand_path('../../support/settings_empty.yml', __FILE__)
115
- settings = NiftySettings::Settings.load_from_file
116
- expect(settings).to eq({})
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.6
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-07-15 00:00:00.000000000 Z
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: Settings
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: Settings
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