nifty_settings 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nifty_settings/settings.rb +5 -2
- data/lib/nifty_settings/version.rb +1 -1
- data/spec/nifty_settings/settings_spec.rb +41 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6651dcfe4c7f6e0c28276f172219dc97e5ab1651
|
4
|
+
data.tar.gz: 632811ea407d4a49ec3202db60b7a5524909ec3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7592769ffcce4853ebeea1bd67ce70d63672c4baafc39d9204a9a22ff97c178d1c70bc0f94b58e49228244c681892fe7311f109d943f350b9465610c7bff3a7
|
7
|
+
data.tar.gz: 8c34282af452aa6462d5f85815eb3701ae347782124fe2152256ad7359ddb221f6c6108552c89e02416a18b3531fc02348e3e70415319d26b1c23a7432071012
|
@@ -9,6 +9,10 @@ module NiftySettings
|
|
9
9
|
hash.each_pair { |k, v| self[k] = v }
|
10
10
|
end
|
11
11
|
|
12
|
+
def ==(other)
|
13
|
+
self.to_hash == other.to_hash
|
14
|
+
end
|
15
|
+
|
12
16
|
def to_hash
|
13
17
|
unpack_attr @hash
|
14
18
|
end
|
@@ -36,8 +40,7 @@ module NiftySettings
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def has?(key)
|
39
|
-
key
|
40
|
-
@hash.has_key?(key) && @hash[key].present?
|
43
|
+
@hash.has_key?(key.to_sym)
|
41
44
|
end
|
42
45
|
|
43
46
|
def fetch(key, default = nil)
|
@@ -1,22 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe NiftySettings::Settings do
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
let(:
|
4
|
+
let(:nested_settings_hash) { { pelle: 'fant', shnoo: 'shnaa' } }
|
5
|
+
let(:settings_hash) { { foo: 'bar', nested: nested_settings_hash } }
|
6
|
+
let(:settings) { NiftySettings::Settings.new(settings_hash) }
|
7
|
+
let(:empty_settings) { NiftySettings::Settings.new }
|
7
8
|
|
8
|
-
context '
|
9
|
-
|
9
|
+
context 'comparing two settings' do
|
10
|
+
it 'uses the hash to determine whether they are the same' do
|
11
|
+
expect(NiftySettings::Settings.new(settings_hash)).to eq(NiftySettings::Settings.new(settings_hash))
|
12
|
+
expect(NiftySettings::Settings.new(settings_hash)).to_not eq(NiftySettings::Settings.new(nested_settings_hash))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context '#key' do
|
17
|
+
context 'when no setting with that key exists' do
|
10
18
|
it 'returns nil' do
|
11
19
|
expect(settings.not_found).to be_nil
|
12
20
|
end
|
13
21
|
end
|
14
22
|
|
15
|
-
context
|
16
|
-
it 'returns the
|
23
|
+
context 'when the settings has a single value' do
|
24
|
+
it 'returns the value' do
|
17
25
|
expect(settings.foo).to eq('bar')
|
18
26
|
end
|
19
27
|
end
|
28
|
+
|
29
|
+
context 'when the setting has nested values' do
|
30
|
+
it 'returns a settings object with the values' do
|
31
|
+
expect(settings.nested).to eq(NiftySettings::Settings.new(nested_settings_hash))
|
32
|
+
end
|
33
|
+
end
|
20
34
|
end
|
21
35
|
|
22
36
|
describe '#to_s' do
|
@@ -32,4 +46,24 @@ describe NiftySettings::Settings do
|
|
32
46
|
end
|
33
47
|
end
|
34
48
|
end
|
49
|
+
|
50
|
+
describe '#key?' do
|
51
|
+
context 'when no setting with that key exists' do
|
52
|
+
it 'returns false' do
|
53
|
+
expect(settings.bar?).to eq(false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the settings has a single value' do
|
58
|
+
it 'returns true' do
|
59
|
+
expect(settings.foo?).to eq(true)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when the setting has nested values' do
|
64
|
+
it 'returns true' do
|
65
|
+
expect(settings.nested?).to eq(true)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
35
69
|
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.1
|
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-03-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|