easy_settings 0.1.1 → 0.1.2
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/lib/easy_settings.rb +12 -5
- data/lib/easy_settings_version.rb +1 -1
- data/spec/config/child1.yml +1 -0
- data/spec/config/child2.yml +1 -0
- data/spec/{empty_settings.yml → config/empty.yml} +0 -0
- data/spec/config/grand_child.yml +1 -0
- data/spec/{settings_with_namespace.yml → config/namespace.yml} +1 -1
- data/spec/{settings.yml → config/settings.yml} +0 -0
- data/spec/easy_settings_spec.rb +18 -38
- data/spec/helpers/default_paths.rb +23 -0
- data/spec/inheritance_spec.rb +39 -0
- data/spec/spec_helper.rb +1 -1
- metadata +18 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 366d74abf13192efbab8c9441bc9fa51d83ccbe1
|
4
|
+
data.tar.gz: d3c86143c642fc900ca00ac5ee8cce947eddeec2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6f1dc3c8fbe9bddb391824e99409791ced68ea24ffea5078bddff11f823de66a7419c776c92ffb8beba6719524a96f46188d2fbc977304b9a7785899fa1337d
|
7
|
+
data.tar.gz: 9041525ccd526ffd115c5914676ca74930ff2d0a2ad94aea44289cef3af48255b7543240855156af1fd01b670c27356b0efc9074628c8a1806813879b279ceff
|
data/lib/easy_settings.rb
CHANGED
@@ -4,11 +4,16 @@ require "erb"
|
|
4
4
|
|
5
5
|
class EasySettings < Hashie::Mash
|
6
6
|
SourceFileNotExist = Class.new(StandardError)
|
7
|
-
|
8
|
-
DEFAULT_FILES = %w(settings.yml config/settings.yml)
|
9
|
-
|
10
7
|
class << self
|
11
|
-
attr_accessor :source_hash, :source_file, :namespace
|
8
|
+
attr_accessor :source_hash, :source_file, :namespace, :default_files
|
9
|
+
|
10
|
+
def inherited(child_class)
|
11
|
+
child_class.class_eval do
|
12
|
+
define_singleton_method(:default_files) do
|
13
|
+
instance_variable_get(:@default_files) || superclass.default_files
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
12
17
|
|
13
18
|
def instance
|
14
19
|
@instance ||= new(namespace ? _source[namespace] : _source)
|
@@ -53,7 +58,7 @@ class EasySettings < Hashie::Mash
|
|
53
58
|
end
|
54
59
|
|
55
60
|
def _source_from_default_file
|
56
|
-
|
61
|
+
default_files.each do |f|
|
57
62
|
path = File.expand_path(f, _root_path)
|
58
63
|
return _load_file(path) if FileTest.exist?(path)
|
59
64
|
end
|
@@ -69,6 +74,8 @@ class EasySettings < Hashie::Mash
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
77
|
+
self.default_files = %w(settings.yml config/settings.yml)
|
78
|
+
|
72
79
|
def assign_property(name, value)
|
73
80
|
super
|
74
81
|
self[name]
|
@@ -0,0 +1 @@
|
|
1
|
+
app_name: Child Class 1
|
@@ -0,0 +1 @@
|
|
1
|
+
app_name: Child Class 2
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
app_name: Grand Child
|
File without changes
|
data/spec/easy_settings_spec.rb
CHANGED
@@ -33,7 +33,7 @@ shared_examples_for "EasySettings" do |proc|
|
|
33
33
|
settings.foo = :bar
|
34
34
|
expect(settings.foo).to eq :bar
|
35
35
|
|
36
|
-
admin3 = {"password" => "PassWord3", "role" => "administrator"}
|
36
|
+
admin3 = { "password" => "PassWord3", "role" => "administrator" }
|
37
37
|
settings.admins.admin3 = admin3
|
38
38
|
expect(settings.admins.admin3.to_h).to eq admin3
|
39
39
|
end
|
@@ -42,7 +42,7 @@ shared_examples_for "EasySettings" do |proc|
|
|
42
42
|
settings[:foo] = :bar
|
43
43
|
expect(settings.foo).to eq :bar
|
44
44
|
|
45
|
-
admin3 = {"password" => "PassWord3", "role" => "administrator"}
|
45
|
+
admin3 = { "password" => "PassWord3", "role" => "administrator" }
|
46
46
|
settings[:admins][:admin3] = admin3
|
47
47
|
expect(settings.admins.admin3.to_h).to eq admin3
|
48
48
|
end
|
@@ -120,46 +120,26 @@ shared_examples_for "EasySettings" do |proc|
|
|
120
120
|
|
121
121
|
it "can set nil when using nil option" do
|
122
122
|
expect(settings.newkey(nil, nil: true)).to be_nil
|
123
|
-
expect(settings.
|
123
|
+
expect(settings.key?(:newkey)).to be_truthy
|
124
124
|
expect(settings.newkey).to be_nil
|
125
125
|
end
|
126
126
|
|
127
127
|
it "doesn't set nil when not using nil option" do
|
128
128
|
expect(settings.newkey(nil)).to be_nil
|
129
|
-
expect(settings.
|
129
|
+
expect(settings.key?(:newkey)).to be_falsey
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
|
135
|
-
before do
|
136
|
-
FileUtils.mkdir File.expand_path("../../config", __FILE__)
|
137
|
-
end
|
138
|
-
|
139
|
-
after do
|
140
|
-
FileUtils.rm_rf File.expand_path("../../config", __FILE__)
|
141
|
-
end
|
134
|
+
require "helpers/default_paths"
|
142
135
|
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
let(:test_settings_file) do
|
148
|
-
File.expand_path("../settings.yml", __FILE__)
|
149
|
-
end
|
150
|
-
|
151
|
-
let(:default_settings_path1) do
|
152
|
-
File.expand_path("../../settings.yml", __FILE__)
|
153
|
-
end
|
154
|
-
|
155
|
-
let(:default_settings_path2) do
|
156
|
-
File.expand_path("../../config/settings.yml", __FILE__)
|
157
|
-
end
|
136
|
+
describe EasySettings do
|
137
|
+
include_context "default_paths"
|
158
138
|
|
159
139
|
let(:custom_settings_path) do
|
160
140
|
File.expand_path("../../config/application.yml", __FILE__)
|
161
141
|
end
|
162
|
-
|
142
|
+
|
163
143
|
let(:app_name) do
|
164
144
|
"EasySettingsTest"
|
165
145
|
end
|
@@ -173,12 +153,12 @@ describe EasySettings do
|
|
173
153
|
FileUtils.rm_f default_settings_path1
|
174
154
|
end
|
175
155
|
|
176
|
-
it_behaves_like("EasySettings",
|
156
|
+
it_behaves_like("EasySettings", proc { Class.new(EasySettings) })
|
177
157
|
|
178
158
|
describe ".reload!" do
|
179
159
|
it "can reload source" do
|
180
160
|
expect(settings.app_name).to eq app_name
|
181
|
-
settings.source_hash = {app_name: "RELOAD"}
|
161
|
+
settings.source_hash = { app_name: "RELOAD" }
|
182
162
|
expect(settings.reload!).to be_truthy
|
183
163
|
expect(settings.app_name).to eq "RELOAD"
|
184
164
|
end
|
@@ -194,7 +174,7 @@ describe EasySettings do
|
|
194
174
|
FileUtils.rm_f default_settings_path2
|
195
175
|
end
|
196
176
|
|
197
|
-
it_behaves_like("EasySettings",
|
177
|
+
it_behaves_like("EasySettings", proc { Class.new(EasySettings) })
|
198
178
|
end
|
199
179
|
|
200
180
|
context "from custom path" do
|
@@ -208,7 +188,7 @@ describe EasySettings do
|
|
208
188
|
|
209
189
|
it_behaves_like(
|
210
190
|
"EasySettings",
|
211
|
-
|
191
|
+
proc do
|
212
192
|
Class.new(EasySettings) do
|
213
193
|
self.source_file = File.expand_path("../../config/application.yml", __FILE__)
|
214
194
|
end
|
@@ -219,8 +199,8 @@ describe EasySettings do
|
|
219
199
|
context "from source hash" do
|
220
200
|
it_behaves_like(
|
221
201
|
"EasySettings",
|
222
|
-
|
223
|
-
source_file = File.expand_path("../settings.yml", __FILE__)
|
202
|
+
proc do
|
203
|
+
source_file = File.expand_path("../config/settings.yml", __FILE__)
|
224
204
|
Class.new(EasySettings) do
|
225
205
|
self.source_file = source_file
|
226
206
|
self.source_hash = YAML.load_file(source_file)
|
@@ -232,9 +212,9 @@ describe EasySettings do
|
|
232
212
|
context "with namespace" do
|
233
213
|
it_behaves_like(
|
234
214
|
"EasySettings",
|
235
|
-
|
215
|
+
proc do
|
236
216
|
Class.new(EasySettings) do
|
237
|
-
self.source_file = File.expand_path("../
|
217
|
+
self.source_file = File.expand_path("../config/namespace.yml", __FILE__)
|
238
218
|
self.namespace = "test"
|
239
219
|
end
|
240
220
|
end
|
@@ -249,7 +229,7 @@ describe EasySettings do
|
|
249
229
|
|
250
230
|
context "with empty source" do
|
251
231
|
it "EasySettings become empty hash" do
|
252
|
-
settings.source_file = File.
|
232
|
+
settings.source_file = File.join(spec_config_path, "empty.yml")
|
253
233
|
expect(settings.to_h).to eq({})
|
254
234
|
end
|
255
235
|
end
|
@@ -257,7 +237,7 @@ describe EasySettings do
|
|
257
237
|
context "specify wrong source path" do
|
258
238
|
it "raise error" do
|
259
239
|
settings.source_file = "notexist.yml"
|
260
|
-
expect{settings.to_h}.to raise_error(EasySettings::SourceFileNotExist)
|
240
|
+
expect { settings.to_h }.to raise_error(EasySettings::SourceFileNotExist)
|
261
241
|
end
|
262
242
|
end
|
263
243
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
shared_context "default_paths" do
|
2
|
+
let!(:gem_root) { File.expand_path("../../../", __FILE__) }
|
3
|
+
let!(:config_path) { File.join(gem_root, "config") }
|
4
|
+
let!(:spec_root) { File.join(gem_root, "spec") }
|
5
|
+
let!(:spec_config_path) { File.join(spec_root, "config") }
|
6
|
+
|
7
|
+
before do
|
8
|
+
FileUtils.mkdir config_path
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
FileUtils.rm_rf config_path
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:test_settings_file) do
|
16
|
+
File.join(spec_config_path, "settings.yml")
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:default_settings_path1) { File.join(gem_root, "settings.yml") }
|
20
|
+
let(:default_settings_path2) { File.join(config_path, "settings.yml") }
|
21
|
+
|
22
|
+
let(:settings) { Class.new(EasySettings) }
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "helpers/default_paths"
|
2
|
+
|
3
|
+
describe "inheritance" do
|
4
|
+
include_context "default_paths"
|
5
|
+
|
6
|
+
subject(:child_class1) do
|
7
|
+
Class.new(settings) do
|
8
|
+
self.default_files = [File.expand_path("../config/child1.yml", __FILE__)]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:child_class2) do
|
13
|
+
Class.new(settings) do
|
14
|
+
self.default_files = [File.expand_path("../config/child2.yml", __FILE__)]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
before { FileUtils.cp test_settings_file, default_settings_path1 }
|
18
|
+
after { FileUtils.rm default_settings_path1 }
|
19
|
+
|
20
|
+
it "has different value from parent's one" do
|
21
|
+
expect(child_class1.app_name).not_to eq EasySettings.app_name
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has differnt value from other child class's one" do
|
25
|
+
expect(child_class1.app_name).not_to eq child_class2.app_name
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "grandchild" do
|
29
|
+
subject(:grand_child) do
|
30
|
+
Class.new(child_class1) do
|
31
|
+
self.default_files = [File.expand_path("../config/grand_child.yml", __FILE__)]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has different valud from child's one" do
|
36
|
+
expect(grand_child.app_name).not_to eq child_class1.app_name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nownabe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -126,6 +126,12 @@ files:
|
|
126
126
|
- lib/easy_settings.rb
|
127
127
|
- lib/easy_settings/rails.rb
|
128
128
|
- lib/easy_settings_version.rb
|
129
|
+
- spec/config/child1.yml
|
130
|
+
- spec/config/child2.yml
|
131
|
+
- spec/config/empty.yml
|
132
|
+
- spec/config/grand_child.yml
|
133
|
+
- spec/config/namespace.yml
|
134
|
+
- spec/config/settings.yml
|
129
135
|
- spec/easy_settings_spec.rb
|
130
136
|
- spec/easy_settings_test/.env
|
131
137
|
- spec/easy_settings_test/.gitignore
|
@@ -177,9 +183,8 @@ files:
|
|
177
183
|
- spec/easy_settings_test/spec/rails_helper.rb
|
178
184
|
- spec/easy_settings_test/spec/spec_helper.rb
|
179
185
|
- spec/easy_settings_test/vendor/assets/stylesheets/.keep
|
180
|
-
- spec/
|
181
|
-
- spec/
|
182
|
-
- spec/settings_with_namespace.yml
|
186
|
+
- spec/helpers/default_paths.rb
|
187
|
+
- spec/inheritance_spec.rb
|
183
188
|
- spec/spec_helper.rb
|
184
189
|
homepage: https://github.com/nownabe/easy_settings
|
185
190
|
licenses:
|
@@ -206,6 +211,12 @@ signing_key:
|
|
206
211
|
specification_version: 4
|
207
212
|
summary: EasySettings is a simple settings with YAML file.
|
208
213
|
test_files:
|
214
|
+
- spec/config/child1.yml
|
215
|
+
- spec/config/child2.yml
|
216
|
+
- spec/config/empty.yml
|
217
|
+
- spec/config/grand_child.yml
|
218
|
+
- spec/config/namespace.yml
|
219
|
+
- spec/config/settings.yml
|
209
220
|
- spec/easy_settings_spec.rb
|
210
221
|
- spec/easy_settings_test/.env
|
211
222
|
- spec/easy_settings_test/.gitignore
|
@@ -257,8 +268,6 @@ test_files:
|
|
257
268
|
- spec/easy_settings_test/spec/rails_helper.rb
|
258
269
|
- spec/easy_settings_test/spec/spec_helper.rb
|
259
270
|
- spec/easy_settings_test/vendor/assets/stylesheets/.keep
|
260
|
-
- spec/
|
261
|
-
- spec/
|
262
|
-
- spec/settings_with_namespace.yml
|
271
|
+
- spec/helpers/default_paths.rb
|
272
|
+
- spec/inheritance_spec.rb
|
263
273
|
- spec/spec_helper.rb
|
264
|
-
has_rdoc:
|