quick_store 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -1
- data/README.md +3 -2
- data/Rakefile +1 -1
- data/lib/quick_store.rb +9 -16
- data/lib/quick_store/configuration.rb +14 -0
- data/lib/quick_store/store.rb +82 -52
- data/lib/quick_store/version.rb +1 -1
- data/quick_store.gemspec +11 -13
- data/spec/quick_store/configuration_spec.rb +12 -0
- data/spec/quick_store/store_spec.rb +44 -42
- data/spec/quick_store_spec.rb +12 -15
- data/spec/spec_helper.rb +3 -4
- data/spec/support/macros/test_helpers.rb +1 -1
- metadata +6 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce685b7a4f43be47881c868dfbdc1c5ba78369af
|
4
|
+
data.tar.gz: d40c5ea3bd418caec5d7ff4538cfca30a2b25421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3820442b0e7aabfbf9ff41bfe7e831ee157941accb944f324c64520a1e271a6c2a8ff8ce0c21292ab25c789daf751be4b94af4707d36c9551df91c6197d1dd02
|
7
|
+
data.tar.gz: 443d9e13a96c503de77cd034f0367d68aec5cee9948749c2a5c7e5b8244c3bed2573fa3ca42fba585ccb28c99da293ec671521d0b673c8cd7a9cd57d6403b34d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -37,6 +37,7 @@ end
|
|
37
37
|
```
|
38
38
|
|
39
39
|
### Storing, fetching, and deleting data
|
40
|
+
|
40
41
|
You can store, receive, and remove data from the store by using different methods:
|
41
42
|
|
42
43
|
```ruby
|
@@ -59,11 +60,11 @@ QuickStore.store.get('a') # => {"b"=>{"c"=>"value"}}
|
|
59
60
|
|
60
61
|
# Removing data for a certain nested key
|
61
62
|
QuickStore.store.delete('a/b/c') # => {"b"=>{"c"=>nil}}
|
62
|
-
QuickStore.get('a')
|
63
|
+
QuickStore.store.get('a') # => {"b"=>{"c"=>nil}}
|
63
64
|
|
64
65
|
# Removing data for all nested keys under a certain key
|
65
66
|
QuickStore.store.delete('a') # => {"b"=>{"c"=>nil}}
|
66
|
-
QuickStore.get('a')
|
67
|
+
QuickStore.store.get('a') # => nil
|
67
68
|
```
|
68
69
|
|
69
70
|
## Contributing
|
data/Rakefile
CHANGED
data/lib/quick_store.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'quick_store/version'
|
2
|
+
require 'quick_store/configuration'
|
3
|
+
require 'quick_store/store'
|
3
4
|
|
5
|
+
# Allows configuring a YAML store and accessing the configured YAML store
|
6
|
+
# through the .store method.
|
4
7
|
module QuickStore
|
5
|
-
|
6
|
-
NO_FILE_PATH_CONFIGURED = "Please configure a file_path for your QuickStore!"
|
8
|
+
NO_FILE_PATH_CONFIGURED = 'Please configure a file_path for your QuickStore!'.freeze
|
7
9
|
|
8
10
|
class << self
|
9
11
|
attr_accessor :configuration
|
@@ -16,9 +18,9 @@ module QuickStore
|
|
16
18
|
# config.key_separator = '|' # default is '/'
|
17
19
|
# end
|
18
20
|
def self.configure
|
19
|
-
yield(
|
20
|
-
raise(NO_FILE_PATH_CONFIGURED) unless
|
21
|
-
|
21
|
+
yield(config) if block_given?
|
22
|
+
raise(NO_FILE_PATH_CONFIGURED) unless config.file_path
|
23
|
+
config
|
22
24
|
end
|
23
25
|
|
24
26
|
# Returns the QuickStore::Configuration.
|
@@ -45,13 +47,4 @@ module QuickStore
|
|
45
47
|
def self.store
|
46
48
|
QuickStore::Store
|
47
49
|
end
|
48
|
-
|
49
|
-
class Configuration
|
50
|
-
attr_accessor :key_separator, :file_path
|
51
|
-
|
52
|
-
def initialize
|
53
|
-
@key_separator = '/'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
50
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module QuickStore
|
2
|
+
# The Configuration class is used internally by QuickStore to create a
|
3
|
+
# singleton configuration.
|
4
|
+
# The *key_separator* defines the character which can be used to access nested
|
5
|
+
# store items (default is "/").
|
6
|
+
# The *file_path* determines where the YAML file is stored.
|
7
|
+
class Configuration
|
8
|
+
attr_accessor :key_separator, :file_path
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@key_separator = '/'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/quick_store/store.rb
CHANGED
@@ -1,15 +1,64 @@
|
|
1
|
-
require 'active_support'
|
2
1
|
require 'yaml/store'
|
3
2
|
require 'fileutils'
|
4
3
|
require 'singleton'
|
5
4
|
|
6
5
|
module QuickStore
|
7
|
-
|
6
|
+
# Provides setter and getter methods for inserting values into the YAML store,
|
7
|
+
# fetching (nested) values, and removing (nested) items from the YAML store.
|
8
8
|
class Store
|
9
9
|
include Singleton
|
10
10
|
|
11
11
|
attr_reader :file
|
12
12
|
|
13
|
+
class << self
|
14
|
+
def get(key)
|
15
|
+
instance.get(key)
|
16
|
+
end
|
17
|
+
|
18
|
+
def set(key, value)
|
19
|
+
instance.set(key, value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def file
|
23
|
+
instance.file
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete(key)
|
27
|
+
instance.delete(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Defines getter and setter methods for arbitrarily named methods.
|
31
|
+
#
|
32
|
+
# QuickStore::Store.answer = 42 # saves 'answer: 42' to the store
|
33
|
+
# # => 42
|
34
|
+
#
|
35
|
+
# QuickStore::Store.answer
|
36
|
+
# # => 42
|
37
|
+
def method_missing(method, *args, &block)
|
38
|
+
if method =~ /.*=$/
|
39
|
+
ensure_not_singleton_method!(method)
|
40
|
+
instance.set(method.to_s.gsub(/=$/, ''), args[0])
|
41
|
+
elsif method =~ /\Adelete\_.*$/
|
42
|
+
instance.delete(method.to_s.gsub(/\Adelete\_/, ''))
|
43
|
+
elsif args.count == 0
|
44
|
+
instance.get(method)
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def ensure_not_singleton_method!(key)
|
53
|
+
return unless singleton_methods.include?(key.to_s.chop.to_sym)
|
54
|
+
|
55
|
+
raise "There is a \"#{key.to_s.chop}\" instance method already " \
|
56
|
+
'defined. This will lead to problems while getting values ' \
|
57
|
+
'from the store. Please use another key than ' \
|
58
|
+
"#{singleton_methods.map(&:to_s)}."
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
13
62
|
def initialize
|
14
63
|
@file = QuickStore.config.file_path
|
15
64
|
|
@@ -34,22 +83,12 @@ module QuickStore
|
|
34
83
|
# QuickStore::Store.instance.set('a/b/c', 'value')
|
35
84
|
# # => { "b": { "c": "value" } }
|
36
85
|
def set(key, value)
|
37
|
-
keys
|
86
|
+
keys = key.to_s.split(QuickStore.config.key_separator)
|
38
87
|
base_key = keys.shift
|
39
88
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
final_value = keys.reverse.inject(value) { |v, k| { k => v } }
|
44
|
-
end
|
45
|
-
|
46
|
-
old_value = get(base_key)
|
47
|
-
|
48
|
-
if old_value.is_a?(Hash) && final_value.is_a?(Hash)
|
49
|
-
updated_values = old_value ? old_value.deep_merge(final_value) : final_value
|
50
|
-
else
|
51
|
-
updated_values = final_value
|
52
|
-
end
|
89
|
+
final_value = final_value(keys, value)
|
90
|
+
old_value = get(base_key)
|
91
|
+
updated_values = updated_values(old_value, final_value)
|
53
92
|
|
54
93
|
@db.transaction { @db[base_key.to_s] = updated_values }
|
55
94
|
end
|
@@ -57,8 +96,8 @@ module QuickStore
|
|
57
96
|
# Gets the value for the given key.
|
58
97
|
# If the value was saved for a key of structure "a/b/c" then the value is
|
59
98
|
# searched in a nested Hash, like: {"a"=>{"b"=>{"c"=>"value"}}}.
|
60
|
-
# If there is a value stored within a nested hash, it returns the
|
61
|
-
# Hash if a partial key is used.
|
99
|
+
# If there is a value stored within a nested hash, it returns the
|
100
|
+
# appropriate Hash if a partial key is used.
|
62
101
|
#
|
63
102
|
# QuickStore::Store.instance.get('a')
|
64
103
|
# # => {"b"=>{"c"=>"value"}}
|
@@ -76,7 +115,9 @@ module QuickStore
|
|
76
115
|
data = @db[base_key.to_s]
|
77
116
|
|
78
117
|
if data
|
79
|
-
keys.reduce(data)
|
118
|
+
keys.reduce(data) do |value, store_key|
|
119
|
+
value ? value[store_key] : nil
|
120
|
+
end
|
80
121
|
end
|
81
122
|
end
|
82
123
|
end
|
@@ -89,49 +130,38 @@ module QuickStore
|
|
89
130
|
end
|
90
131
|
end
|
91
132
|
|
92
|
-
|
93
|
-
def get(key)
|
94
|
-
instance.get(key)
|
95
|
-
end
|
133
|
+
private
|
96
134
|
|
97
|
-
|
98
|
-
|
135
|
+
def final_value(keys, value)
|
136
|
+
if keys.empty?
|
137
|
+
value
|
138
|
+
else
|
139
|
+
keys.reverse.inject(value) { |final_value, key| { key => final_value } }
|
99
140
|
end
|
141
|
+
end
|
100
142
|
|
101
|
-
|
102
|
-
|
143
|
+
def updated_values(old_value, final_value)
|
144
|
+
if old_value.is_a?(Hash) && final_value.is_a?(Hash)
|
145
|
+
deep_merge(old_value, final_value)
|
146
|
+
else
|
147
|
+
final_value
|
103
148
|
end
|
149
|
+
end
|
104
150
|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
151
|
+
def deep_merge(old_hash, new_hash)
|
152
|
+
final_hash = old_hash.dup
|
108
153
|
|
109
|
-
|
110
|
-
|
111
|
-
# QuickStore::Store.answer = 42 # saves 'answer: 42' to the store
|
112
|
-
# # => 42
|
113
|
-
#
|
114
|
-
# QuickStore::Store.answer
|
115
|
-
# # => 42
|
116
|
-
def method_missing(method, *args, &block)
|
117
|
-
if method =~ /.*=$/
|
118
|
-
if singleton_methods.include?(method.to_s.chop.to_sym)
|
119
|
-
raise "There is a \"#{method.to_s.chop}\" instance method already " +
|
120
|
-
"defined. This will lead to problems while getting values " +
|
121
|
-
"from the store. Please use another key than " +
|
122
|
-
"#{singleton_methods.map(&:to_s)}."
|
123
|
-
end
|
154
|
+
new_hash.each_pair do |key, other_value|
|
155
|
+
old_value = final_hash[key]
|
124
156
|
|
125
|
-
|
126
|
-
|
127
|
-
instance.delete(method.to_s.gsub(/\Adelete\_/, ''))
|
128
|
-
elsif args.count == 0
|
129
|
-
instance.get(method)
|
157
|
+
if old_value.is_a?(Hash) && other_value.is_a?(Hash)
|
158
|
+
final_hash[key] = deep_merge(old_value, other_value)
|
130
159
|
else
|
131
|
-
|
160
|
+
final_hash[key] = other_value
|
132
161
|
end
|
133
162
|
end
|
163
|
+
|
164
|
+
final_hash
|
134
165
|
end
|
135
166
|
end
|
136
|
-
|
137
167
|
end
|
data/lib/quick_store/version.rb
CHANGED
data/quick_store.gemspec
CHANGED
@@ -4,24 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'quick_store/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'quick_store'
|
8
8
|
spec.version = QuickStore::VERSION
|
9
9
|
spec.required_ruby_version = '>= 1.9.3'
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
10
|
+
spec.authors = ['Paul Götze']
|
11
|
+
spec.email = ['paul.christoph.goetze@gmail.com']
|
12
|
+
spec.summary = 'Simple local key-value store based on YAML::Store.'
|
13
|
+
spec.description = 'Simple local key-value store based on YAML::Store.'
|
14
|
+
spec.homepage = 'https://github.com/daigaku-ruby/quick_store'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.
|
23
|
-
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
25
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe QuickStore::Configuration do
|
4
|
+
it { is_expected.to respond_to :key_separator }
|
5
|
+
it { is_expected.to respond_to :key_separator= }
|
6
|
+
it { is_expected.to respond_to :file_path }
|
7
|
+
it { is_expected.to respond_to :file_path= }
|
8
|
+
|
9
|
+
it 'has the default key separator "/"' do
|
10
|
+
expect(QuickStore::Configuration.new.key_separator).to eq '/'
|
11
|
+
end
|
12
|
+
end
|
@@ -1,98 +1,100 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe QuickStore::Store do
|
4
|
-
|
5
4
|
subject { QuickStore::Store.send(:new) }
|
6
5
|
|
7
6
|
it { is_expected.to respond_to :get }
|
8
7
|
it { is_expected.to respond_to :set }
|
9
8
|
it { is_expected.to respond_to :file }
|
10
9
|
|
11
|
-
it
|
12
|
-
allow_any_instance_of(QuickStore::Configuration)
|
10
|
+
it 'raises an error if used without a configured file_path' do
|
11
|
+
allow_any_instance_of(QuickStore::Configuration)
|
12
|
+
.to receive(:file_path)
|
13
|
+
.and_return(nil)
|
14
|
+
|
13
15
|
expect { QuickStore::Store.send(:new) }.to raise_error
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
18
|
+
it 'creates the store file in the given directory on access' do
|
17
19
|
QuickStore::Store.call_an_arbitrary_method
|
18
20
|
expect(File.exist?(file_path)).to be_truthy
|
19
21
|
end
|
20
22
|
|
21
|
-
it
|
22
|
-
expect { QuickStore::Store.brownie =
|
23
|
+
it 'allows setting arbitrary keys by setter methods' do
|
24
|
+
expect { QuickStore::Store.brownie = 'brownie' }.not_to raise_error
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
26
|
-
QuickStore::Store.carrots =
|
27
|
-
expect(QuickStore::Store.carrots).to eq
|
27
|
+
it 'allows getting subsequently set keys' do
|
28
|
+
QuickStore::Store.carrots = 'carrots'
|
29
|
+
expect(QuickStore::Store.carrots).to eq 'carrots'
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
32
|
+
it 'allows deleting arbitrary keys by dynamic delete' do
|
31
33
|
value = 'chips'
|
32
34
|
QuickStore::Store.potatoes_variation = value
|
33
35
|
expect(QuickStore::Store.potatoes_variation).to eq value
|
34
36
|
|
35
|
-
QuickStore::Store
|
37
|
+
QuickStore::Store.delete_potatoes_variation
|
36
38
|
expect(QuickStore::Store.potatoes_variation).to be_nil
|
37
39
|
end
|
38
40
|
|
39
|
-
it
|
41
|
+
it 'returns nil for not set simple keys' do
|
40
42
|
expect(QuickStore::Store.hamburger).to be_nil
|
41
43
|
end
|
42
44
|
|
43
|
-
it
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
it 'returns nil for not set nested keys' do
|
46
|
+
key = 'pastries/muffins/savory'
|
47
|
+
expect(QuickStore::Store.get(key)).to be_nil
|
48
|
+
end
|
47
49
|
|
48
|
-
it
|
50
|
+
it 'raises an method missing errror for non getter/setter methods' do
|
49
51
|
expect { QuickStore::Store.arbitrary_method(1, 2) }
|
50
52
|
.to raise_error NoMethodError
|
51
53
|
end
|
52
54
|
|
53
55
|
[:get, :set, :file, :delete].each do |method|
|
54
|
-
it "responds to
|
56
|
+
it "responds to .#{method}" do
|
55
57
|
expect(QuickStore::Store).to respond_to method
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
|
-
describe
|
60
|
-
it
|
61
|
+
describe '.get' do
|
62
|
+
it 'returns the value of the given key' do
|
61
63
|
toast = 'toast'
|
62
64
|
QuickStore::Store.toast = toast
|
63
65
|
expect(QuickStore::Store.get(:toast)).to eq toast
|
64
66
|
end
|
65
67
|
|
66
|
-
it
|
67
|
-
base_key
|
68
|
+
it 'gets the value hash for a given partly key' do
|
69
|
+
base_key = 'pastries'
|
68
70
|
second_key = 'muffins'
|
69
|
-
third_key
|
70
|
-
key
|
71
|
-
muffin
|
72
|
-
hash
|
71
|
+
third_key = 'sweet'
|
72
|
+
key = "#{base_key}/#{second_key}/#{third_key}"
|
73
|
+
muffin = 'raspberry cream muffin'
|
74
|
+
hash = { second_key => { third_key => muffin } }
|
73
75
|
|
74
76
|
QuickStore::Store.set(key, muffin)
|
75
77
|
expect(QuickStore::Store.get(base_key)).to eq hash
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
describe
|
80
|
-
it
|
81
|
+
describe '.set' do
|
82
|
+
it 'sets the value for the given key' do
|
81
83
|
juice = 'orange juice'
|
82
84
|
QuickStore::Store.set(:juice, juice)
|
83
85
|
expect(QuickStore::Store.juice).to eq juice
|
84
86
|
end
|
85
87
|
|
86
|
-
it
|
87
|
-
key
|
88
|
+
it 'sets the value for the given nested key' do
|
89
|
+
key = 'pastries/muffins/sweet'
|
88
90
|
muffin = 'blueberry muffin'
|
89
91
|
|
90
92
|
QuickStore::Store.set(key, muffin)
|
91
93
|
expect(QuickStore::Store.get(key)).to eq muffin
|
92
94
|
end
|
93
95
|
|
94
|
-
it
|
95
|
-
key
|
96
|
+
it 'sets the value for the given nested key' do
|
97
|
+
key = 'pastries/muffins/sweet'
|
96
98
|
muffin = 'apple walnut muffin'
|
97
99
|
|
98
100
|
QuickStore::Store.set(key, muffin)
|
@@ -100,29 +102,29 @@ describe QuickStore::Store do
|
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
103
|
-
describe
|
104
|
-
it
|
105
|
+
describe '.file' do
|
106
|
+
it 'returns the storage file path' do
|
105
107
|
expect(QuickStore::Store.file).to eq QuickStore.config.file_path
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
|
-
describe
|
111
|
+
describe '.delete' do
|
110
112
|
[:to_delete, 'to_delete'].each do |key|
|
111
|
-
it
|
113
|
+
it 'removes the key from the store' do
|
112
114
|
statement = 'I really love deleting things!'
|
113
115
|
|
114
116
|
QuickStore.store.to_delete = statement
|
115
117
|
expect(QuickStore.store.to_delete).to eq statement
|
116
118
|
|
117
|
-
QuickStore.store.delete(
|
119
|
+
QuickStore.store.delete(key)
|
118
120
|
expect(QuickStore.store.to_delete).to be_nil
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
122
|
-
it
|
123
|
-
key
|
124
|
-
other_key
|
125
|
-
value
|
124
|
+
it 'removes nested keys, but keeps other keys on same level' do
|
125
|
+
key = 'a/deeply/nested/key'
|
126
|
+
other_key = 'a/deeply/nested/other_key'
|
127
|
+
value = 'Such worth being deleted.'
|
126
128
|
other_value = 'Such worth being kept.'
|
127
129
|
|
128
130
|
QuickStore.store.set(key, value)
|
@@ -141,7 +143,7 @@ describe QuickStore::Store do
|
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
144
|
-
it
|
146
|
+
it 'raises an error if the related getter for a setter is already defined' do
|
145
147
|
expect { QuickStore::Store.clone = 'defined' }.to raise_error
|
146
148
|
end
|
147
149
|
end
|
data/spec/quick_store_spec.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe QuickStore do
|
4
|
-
|
5
|
-
|
6
|
-
it "returns a QuickStore::Configuration instance" do
|
4
|
+
describe '.config' do
|
5
|
+
it 'returns a QuickStore::Configuration instance' do
|
7
6
|
expect(QuickStore.config).to be_a QuickStore::Configuration
|
8
7
|
end
|
9
8
|
end
|
10
9
|
|
11
|
-
describe '
|
12
|
-
it
|
10
|
+
describe '.store' do
|
11
|
+
it 'retuns the QuickStore::Store class' do
|
13
12
|
expect(QuickStore.store).to be QuickStore::Store
|
14
13
|
end
|
15
14
|
|
16
|
-
it
|
15
|
+
it 'can be used to set values' do
|
17
16
|
expect { QuickStore.store.muffin = 'blueberry muffin' }.not_to raise_error
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
describe '
|
22
|
-
it
|
23
|
-
expect { QuickStore.configure
|
20
|
+
describe '.configure' do
|
21
|
+
it 'allows passing in a block' do
|
22
|
+
expect { QuickStore.configure }.not_to raise_error
|
24
23
|
end
|
25
24
|
|
26
|
-
it
|
25
|
+
it 'allows setting the file_path' do
|
27
26
|
QuickStore.configure do |config|
|
28
27
|
config.file_path = file_path
|
29
28
|
end
|
@@ -31,7 +30,7 @@ describe QuickStore do
|
|
31
30
|
expect(QuickStore.config.file_path).to eq file_path
|
32
31
|
end
|
33
32
|
|
34
|
-
it
|
33
|
+
it 'allows setting the key_separator' do
|
35
34
|
QuickStore.configure do |config|
|
36
35
|
config.key_separator = '.'
|
37
36
|
end
|
@@ -39,10 +38,8 @@ describe QuickStore do
|
|
39
38
|
expect(QuickStore.config.key_separator).to eq '.'
|
40
39
|
end
|
41
40
|
|
42
|
-
it
|
43
|
-
config = QuickStore.configure
|
44
|
-
end
|
45
|
-
|
41
|
+
it 'returns the QuickStore::Configuration' do
|
42
|
+
config = QuickStore.configure
|
46
43
|
expect(config).to be_a QuickStore::Configuration
|
47
44
|
end
|
48
45
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,8 @@ require 'rspec'
|
|
2
2
|
|
3
3
|
def require_files_from(paths = [])
|
4
4
|
paths.each do |path|
|
5
|
-
Dir[File.join(File.expand_path("#{path}*.rb", __FILE__))].sort
|
6
|
-
|
7
|
-
end
|
5
|
+
files = Dir[File.join(File.expand_path("#{path}*.rb", __FILE__))].sort
|
6
|
+
files.each { |file| require file }
|
8
7
|
end
|
9
8
|
end
|
10
9
|
|
@@ -12,7 +11,7 @@ RSpec.configure do |config|
|
|
12
11
|
config.color = true
|
13
12
|
|
14
13
|
require File.expand_path('../../lib/quick_store', __FILE__)
|
15
|
-
require_files_from [
|
14
|
+
require_files_from ['../support/**/']
|
16
15
|
|
17
16
|
config.include TestHelpers
|
18
17
|
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quick_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Götze
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '4.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,9 +65,11 @@ files:
|
|
79
65
|
- README.md
|
80
66
|
- Rakefile
|
81
67
|
- lib/quick_store.rb
|
68
|
+
- lib/quick_store/configuration.rb
|
82
69
|
- lib/quick_store/store.rb
|
83
70
|
- lib/quick_store/version.rb
|
84
71
|
- quick_store.gemspec
|
72
|
+
- spec/quick_store/configuration_spec.rb
|
85
73
|
- spec/quick_store/store_spec.rb
|
86
74
|
- spec/quick_store_spec.rb
|
87
75
|
- spec/spec_helper.rb
|
@@ -106,11 +94,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
94
|
version: '0'
|
107
95
|
requirements: []
|
108
96
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.5.1
|
110
98
|
signing_key:
|
111
99
|
specification_version: 4
|
112
100
|
summary: Simple local key-value store based on YAML::Store.
|
113
101
|
test_files:
|
102
|
+
- spec/quick_store/configuration_spec.rb
|
114
103
|
- spec/quick_store/store_spec.rb
|
115
104
|
- spec/quick_store_spec.rb
|
116
105
|
- spec/spec_helper.rb
|