easy_settings 0.0.3 → 0.0.4
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/.rspec +2 -0
- data/Rakefile +4 -0
- data/easy_settings.gemspec +1 -0
- data/lib/easy_settings.rb +1 -1
- data/lib/easy_settings_version.rb +1 -1
- data/spec/easy_settings_spec.rb +263 -0
- data/spec/empty_settings.yml +0 -0
- data/spec/settings.yml +9 -0
- data/spec/settings_with_namespace.yml +14 -0
- data/spec/spec_helper.rb +85 -0
- metadata +28 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2085b197801aa7b23546218a9a2cd4d187c0997b
|
4
|
+
data.tar.gz: f017d3d8cfcac1ad5e3acd50e3420445058b2ea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 235f5f02e84ccc6ac2be90c03e5bafb55035040122feaed01fe4c25857c81dc037ca4adeff405ac4566829694de51d6b8cbf93cdff16c7269685d46d4e9f58a7
|
7
|
+
data.tar.gz: 8af02731d7090dd8b535a84008057e4f4a5a39371dc1ff9cc8b0ac608cc1115beb4aa351df9e039559ef23441ea4e44a3ef145a8cd8c3fd2891d9785ac2e24d6
|
data/.rspec
ADDED
data/Rakefile
CHANGED
data/easy_settings.gemspec
CHANGED
@@ -22,5 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.7"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "simplecov"
|
25
26
|
spec.add_development_dependency "pry"
|
26
27
|
end
|
data/lib/easy_settings.rb
CHANGED
@@ -51,7 +51,7 @@ class EasySettings < Hashie::Mash
|
|
51
51
|
|
52
52
|
def _source_from_file
|
53
53
|
unless FileTest.exist?(source_file)
|
54
|
-
raise(SourceFileNotExist, "Your source file '#{
|
54
|
+
raise(SourceFileNotExist, "Your source file '#{source_file}' does not exist.")
|
55
55
|
end
|
56
56
|
_load_file(source_file)
|
57
57
|
end
|
@@ -0,0 +1,263 @@
|
|
1
|
+
shared_examples_for "EasySettings" do |proc|
|
2
|
+
let(:settings, &proc)
|
3
|
+
|
4
|
+
it "can access by dot" do
|
5
|
+
expect(settings.app_name).to eq app_name
|
6
|
+
end
|
7
|
+
|
8
|
+
it "can access by [Srting]" do
|
9
|
+
expect(settings["app_name"]).to eq app_name
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can access by [Symbol]" do
|
13
|
+
expect(settings[:app_name]).to eq app_name
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can access nested hash by dot" do
|
17
|
+
expect(settings.admins.admin1.password).to eq "PassWord1"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can access nested hash by []" do
|
21
|
+
expect(settings[:admins][:admin1][:password]).to eq "PassWord1"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "return nil when access key that doesn't exist by dot" do
|
25
|
+
expect(settings.admins.admin3).to be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "return nil when access key that doesn't exist by []" do
|
29
|
+
expect(settings[:admins][:admin3]).to be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can be set value by dot" do
|
33
|
+
settings.foo = :bar
|
34
|
+
expect(settings.foo).to eq :bar
|
35
|
+
|
36
|
+
admin3 = {"password" => "PassWord3", "role" => "administrator"}
|
37
|
+
settings.admins.admin3 = admin3
|
38
|
+
expect(settings.admins.admin3.to_h).to eq admin3
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can be set value by []" do
|
42
|
+
settings[:foo] = :bar
|
43
|
+
expect(settings.foo).to eq :bar
|
44
|
+
|
45
|
+
admin3 = {"password" => "PassWord3", "role" => "administrator"}
|
46
|
+
settings[:admins][:admin3] = admin3
|
47
|
+
expect(settings.admins.admin3.to_h).to eq admin3
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can be rewrited by dot" do
|
51
|
+
settings.app_name = "hoge"
|
52
|
+
expect(settings.app_name).to eq "hoge"
|
53
|
+
|
54
|
+
password = "PASSWORD"
|
55
|
+
settings.admins.admin1 = password
|
56
|
+
expect(settings.admins.admin1).to eq password
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can be rewrited by []" do
|
60
|
+
settings[:app_name] = "hoge"
|
61
|
+
expect(settings.app_name).to eq "hoge"
|
62
|
+
|
63
|
+
password = "PASSWORD"
|
64
|
+
settings[:admins][:admin1] = password
|
65
|
+
expect(settings.admins.admin1).to eq password
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can treat ERB format" do
|
69
|
+
unless settings.source_hash
|
70
|
+
expect(settings.erb).to eq "This was set by ERB"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "method?" do
|
75
|
+
it "return true when key exist" do
|
76
|
+
expect(settings.app_name?).to be_truthy
|
77
|
+
end
|
78
|
+
|
79
|
+
it "return false when key doesn't exist" do
|
80
|
+
expect(settings.not_exist?).to be_falsey
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "method!" do
|
85
|
+
it "return new hash when key doesn't exist" do
|
86
|
+
ret = settings.newkey!
|
87
|
+
expect(ret).to be_an_instance_of settings
|
88
|
+
expect(ret.to_h).to eq({})
|
89
|
+
end
|
90
|
+
|
91
|
+
it "return existing value when key exist" do
|
92
|
+
expect(settings.app_name!).to eq app_name
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "method_" do
|
97
|
+
it "return new hash but doesn't set when key doesn't exist" do
|
98
|
+
ret = settings.newkey_
|
99
|
+
expect(ret).to be_an_instance_of settings
|
100
|
+
expect(ret.to_h).to eq({})
|
101
|
+
expect(settings.newkey).to be_nil
|
102
|
+
end
|
103
|
+
|
104
|
+
it "return existing value when key exist" do
|
105
|
+
expect(settings.app_name_).to eq app_name
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "method()" do
|
110
|
+
it "can set new value when key doesn't exist" do
|
111
|
+
new_value = "NEWVAL"
|
112
|
+
expect(settings.newkey(new_value)).to eq new_value
|
113
|
+
expect(settings.newkey).to eq new_value
|
114
|
+
end
|
115
|
+
|
116
|
+
it "doesn't set new value when key already exist" do
|
117
|
+
expect(settings.app_name("NEWVAL")).to eq "EasySettingsTest"
|
118
|
+
expect(settings.app_name).to eq "EasySettingsTest"
|
119
|
+
end
|
120
|
+
|
121
|
+
it "can set nil when using nil option" do
|
122
|
+
expect(settings.newkey(nil, nil: true)).to be_nil
|
123
|
+
expect(settings.has_key?(:newkey)).to be_truthy
|
124
|
+
expect(settings.newkey).to be_nil
|
125
|
+
end
|
126
|
+
|
127
|
+
it "doesn't set nil when not using nil option" do
|
128
|
+
expect(settings.newkey(nil)).to be_nil
|
129
|
+
expect(settings.has_key?(:newkey)).to be_falsey
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe EasySettings do
|
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
|
142
|
+
|
143
|
+
let(:settings) do
|
144
|
+
Class.new(EasySettings)
|
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
|
158
|
+
|
159
|
+
let(:custom_settings_path) do
|
160
|
+
File.expand_path("../../config/application.yml", __FILE__)
|
161
|
+
end
|
162
|
+
|
163
|
+
let(:app_name) do
|
164
|
+
"EasySettingsTest"
|
165
|
+
end
|
166
|
+
|
167
|
+
context "from settings.yml" do
|
168
|
+
before do
|
169
|
+
FileUtils.cp test_settings_file, default_settings_path1
|
170
|
+
end
|
171
|
+
|
172
|
+
after do
|
173
|
+
FileUtils.rm_f default_settings_path1
|
174
|
+
end
|
175
|
+
|
176
|
+
it_behaves_like("EasySettings", Proc.new{Class.new(EasySettings)})
|
177
|
+
|
178
|
+
describe ".reload!" do
|
179
|
+
it "can reload source" do
|
180
|
+
expect(settings.app_name).to eq app_name
|
181
|
+
settings.source_hash = {app_name: "RELOAD"}
|
182
|
+
expect(settings.reload!).to be_truthy
|
183
|
+
expect(settings.app_name).to eq "RELOAD"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "from config/settings.yml" do
|
189
|
+
before do
|
190
|
+
FileUtils.cp test_settings_file, default_settings_path2
|
191
|
+
end
|
192
|
+
|
193
|
+
after do
|
194
|
+
FileUtils.rm_f default_settings_path2
|
195
|
+
end
|
196
|
+
|
197
|
+
it_behaves_like("EasySettings", Proc.new{Class.new(EasySettings)})
|
198
|
+
end
|
199
|
+
|
200
|
+
context "from custom path" do
|
201
|
+
before do
|
202
|
+
FileUtils.cp test_settings_file, custom_settings_path
|
203
|
+
end
|
204
|
+
|
205
|
+
after do
|
206
|
+
FileUtils.rm_f custom_settings_path
|
207
|
+
end
|
208
|
+
|
209
|
+
it_behaves_like(
|
210
|
+
"EasySettings",
|
211
|
+
Proc.new do
|
212
|
+
Class.new(EasySettings) do
|
213
|
+
self.source_file = File.expand_path("../../config/application.yml", __FILE__)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
)
|
217
|
+
end
|
218
|
+
|
219
|
+
context "from source hash" do
|
220
|
+
it_behaves_like(
|
221
|
+
"EasySettings",
|
222
|
+
Proc.new do
|
223
|
+
source_file = File.expand_path("../settings.yml", __FILE__)
|
224
|
+
Class.new(EasySettings) do
|
225
|
+
self.source_file = source_file
|
226
|
+
self.source_hash = YAML.load_file(source_file)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
)
|
230
|
+
end
|
231
|
+
|
232
|
+
context "with namespace" do
|
233
|
+
it_behaves_like(
|
234
|
+
"EasySettings",
|
235
|
+
Proc.new do
|
236
|
+
Class.new(EasySettings) do
|
237
|
+
self.source_file = File.expand_path("../settings_with_namespace.yml", __FILE__)
|
238
|
+
self.namespace = "test"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
)
|
242
|
+
end
|
243
|
+
|
244
|
+
context "source does not exist" do
|
245
|
+
it "EasySettings is empty hash" do
|
246
|
+
expect(settings.to_h).to eq({})
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "with empty source" do
|
251
|
+
it "EasySettings become empty hash" do
|
252
|
+
settings.source_file = File.expand_path("../empty_settings.yml", __FILE__)
|
253
|
+
expect(settings.to_h).to eq({})
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context "specify wrong source path" do
|
258
|
+
it "raise error" do
|
259
|
+
settings.source_file = "notexist.yml"
|
260
|
+
expect{settings.to_h}.to raise_error(EasySettings::SourceFileNotExist)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
File without changes
|
data/spec/settings.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
app_name: EasySettingsTestDefault
|
3
|
+
admins:
|
4
|
+
admin1:
|
5
|
+
password: PassWord1
|
6
|
+
role: administrator
|
7
|
+
admin2:
|
8
|
+
password: PassWord2
|
9
|
+
role: manager
|
10
|
+
erb: <%= "This was set by ERB" %>
|
11
|
+
|
12
|
+
test:
|
13
|
+
<<: *defaults
|
14
|
+
app_name: EasySettingsTest
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter "vendor"
|
4
|
+
add_filter "spec"
|
5
|
+
end
|
6
|
+
|
7
|
+
require "fileutils"
|
8
|
+
require "easy_settings"
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
# rspec-expectations config goes here. You can use an alternate
|
12
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
13
|
+
# assertions if you prefer.
|
14
|
+
config.expect_with :rspec do |expectations|
|
15
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
16
|
+
# and `failure_message` of custom matchers include text for helper methods
|
17
|
+
# defined using `chain`, e.g.:
|
18
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
19
|
+
# # => "be bigger than 2 and smaller than 4"
|
20
|
+
# ...rather than:
|
21
|
+
# # => "be bigger than 2"
|
22
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
23
|
+
end
|
24
|
+
|
25
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
26
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
27
|
+
config.mock_with :rspec do |mocks|
|
28
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
29
|
+
# a real object. This is generally recommended, and will default to
|
30
|
+
# `true` in RSpec 4.
|
31
|
+
mocks.verify_partial_doubles = true
|
32
|
+
end
|
33
|
+
|
34
|
+
config.filter_run :focus
|
35
|
+
config.run_all_when_everything_filtered = true
|
36
|
+
|
37
|
+
# The settings below are suggested to provide a good initial experience
|
38
|
+
# with RSpec, but feel free to customize to your heart's content.
|
39
|
+
=begin
|
40
|
+
# These two settings work together to allow you to limit a spec run
|
41
|
+
# to individual examples or groups you care about by tagging them with
|
42
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
43
|
+
# get run.
|
44
|
+
config.filter_run :focus
|
45
|
+
config.run_all_when_everything_filtered = true
|
46
|
+
|
47
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
48
|
+
# recommended. For more details, see:
|
49
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
50
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
51
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
52
|
+
config.disable_monkey_patching!
|
53
|
+
|
54
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
55
|
+
# be too noisy due to issues in dependencies.
|
56
|
+
config.warnings = true
|
57
|
+
|
58
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
59
|
+
# file, and it's useful to allow more verbose output when running an
|
60
|
+
# individual spec file.
|
61
|
+
if config.files_to_run.one?
|
62
|
+
# Use the documentation formatter for detailed output,
|
63
|
+
# unless a formatter has already been configured
|
64
|
+
# (e.g. via a command-line flag).
|
65
|
+
config.default_formatter = 'doc'
|
66
|
+
end
|
67
|
+
|
68
|
+
# Print the 10 slowest examples and example groups at the
|
69
|
+
# end of the spec run, to help surface which specs are running
|
70
|
+
# particularly slow.
|
71
|
+
config.profile_examples = 10
|
72
|
+
|
73
|
+
# Run specs in random order to surface order dependencies. If you find an
|
74
|
+
# order dependency and want to debug it, you can fix the order by providing
|
75
|
+
# the seed, which is printed after each run.
|
76
|
+
# --seed 1234
|
77
|
+
config.order = :random
|
78
|
+
|
79
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
80
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
81
|
+
# test failures related to randomization by passing the same `--seed` value
|
82
|
+
# as the one that triggered the failure.
|
83
|
+
Kernel.srand config.seed
|
84
|
+
=end
|
85
|
+
end
|
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nownabe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: pry
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,6 +102,7 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
105
|
+
- ".rspec"
|
91
106
|
- Gemfile
|
92
107
|
- LICENSE.txt
|
93
108
|
- README.md
|
@@ -95,6 +110,11 @@ files:
|
|
95
110
|
- easy_settings.gemspec
|
96
111
|
- lib/easy_settings.rb
|
97
112
|
- lib/easy_settings_version.rb
|
113
|
+
- spec/easy_settings_spec.rb
|
114
|
+
- spec/empty_settings.yml
|
115
|
+
- spec/settings.yml
|
116
|
+
- spec/settings_with_namespace.yml
|
117
|
+
- spec/spec_helper.rb
|
98
118
|
homepage: https://github.com/nownabe/easy_settings
|
99
119
|
licenses:
|
100
120
|
- MIT
|
@@ -119,4 +139,9 @@ rubygems_version: 2.4.5
|
|
119
139
|
signing_key:
|
120
140
|
specification_version: 4
|
121
141
|
summary: EasySettings is a simple settings with YAML file.
|
122
|
-
test_files:
|
142
|
+
test_files:
|
143
|
+
- spec/easy_settings_spec.rb
|
144
|
+
- spec/empty_settings.yml
|
145
|
+
- spec/settings.yml
|
146
|
+
- spec/settings_with_namespace.yml
|
147
|
+
- spec/spec_helper.rb
|