druthers 0.0.2 → 0.0.3
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 +9 -9
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +10 -2
- data/README.md +5 -3
- data/ci/Gemfile.rails-4.0.x +1 -2
- data/ci/Gemfile.rails-4.1.x +4 -0
- data/lib/druthers/support.rb +4 -1
- data/lib/druthers/version.rb +1 -1
- data/test/setting_test.rb +7 -1
- data/test/test_models.rb +15 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2Q2ODBjN2ViMjc4NmQ0MzI3NzBjYTBhYjgzMDFmNDlkNjRmYmJmOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
MjkzYTgzOWJhYmUyMTgzMTQ4NDYwYjczMzUxNzkxNDUxNDZkZDJhNQ==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTM4MmRmNzM0MTI1YjgzMGVmYjZhZWQ4NDdkN2JjN2Y2MWRmYmMxNWExYTgy
|
10
|
+
ZGJhYmRiNmI5NzFjOTUyOGYyNThmZGY0OTNlODU4ZjIyMjg2YWZlZGM4MGMx
|
11
|
+
MmI1N2E5NjllMzBlNTNjZTcwMjY0YjQzZWRiNWY0MzM3YTg0Yjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzAxNWMyZDMxMDdiOTE2YzIzYmFkODA0MmNhM2ZlMmM2NjEzODJhYjcxMGJm
|
14
|
+
NDBhZGE2MmVmOGMwM2ZjMTUxYmM0ZDcyNzg2YzVmYWMzMmU5NTZjZGI2MGQx
|
15
|
+
MWQ0NjdjNjBjY2JkNTcxOTNmNWEyMzIyYTUyZTZjOTRlYjVhZmI=
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.0.3
|
4
|
+
|
5
|
+
* Rails 4.1 is supported
|
6
|
+
|
7
|
+
* Fixes a bug where serialized values weren't cached properly. Thanks for the
|
8
|
+
[description, fix and tests](https://github.com/mceachen/druthers/pull/2),
|
9
|
+
[JKillian](https://github.com/JKillian)!
|
10
|
+
|
3
11
|
## v0.0.2
|
4
12
|
|
5
|
-
```def_druthers``` only add
|
13
|
+
* ```def_druthers``` will only add getter and setters if they aren't already defined
|
6
14
|
|
7
15
|
## v0.0.1
|
8
16
|
|
9
|
-
|
17
|
+
Druthers is born. YOU WILL LOVE IT
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ As opposed to ```rails-settings``` and forks, ```method_missing``` isn't used an
|
|
23
23
|
## Supported versions
|
24
24
|
|
25
25
|
The latest versions of
|
26
|
-
* Rails 3.2 & 4.
|
26
|
+
* Rails 3.2, 4.0, & 4.1
|
27
27
|
* Ruby 1.9.3 & 2.0.0
|
28
28
|
* SQLite, MySQL, and PostgreSQL
|
29
29
|
|
@@ -43,11 +43,13 @@ class Setting < ActiveRecord::Base
|
|
43
43
|
serialize :value
|
44
44
|
|
45
45
|
# This will be used as the value of `Setting.quest` if it is not set.
|
46
|
-
def default_quest
|
46
|
+
def self.default_quest
|
47
47
|
"to find the holy grail"
|
48
48
|
end
|
49
49
|
|
50
|
-
# This validation will be only run for instances whose key == "favourite_color"
|
50
|
+
# This validation will be only run for instances whose key == "favourite_color"
|
51
|
+
# Note that this isn't a class method, as the validation needs access to the
|
52
|
+
# instance value.
|
51
53
|
def validate_favourite_colour
|
52
54
|
add_error("we're right out of teal, sorry") if value == "teal"
|
53
55
|
end
|
data/ci/Gemfile.rails-4.0.x
CHANGED
data/lib/druthers/support.rb
CHANGED
@@ -38,7 +38,10 @@ module Druthers
|
|
38
38
|
obj.update_attributes!(value: value)
|
39
39
|
end
|
40
40
|
# Only update the cache if the update! succeeded:
|
41
|
-
|
41
|
+
# Note that we cached the obj.value, rather than the value, to make sure
|
42
|
+
# returned values are consistent with the serializer's result.
|
43
|
+
# See https://github.com/mceachen/druthers/pull/2
|
44
|
+
druthers_cache.write(key, obj.value)
|
42
45
|
obj
|
43
46
|
end
|
44
47
|
|
data/lib/druthers/version.rb
CHANGED
data/test/setting_test.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'minitest_helper'
|
2
2
|
|
3
3
|
describe Setting do
|
4
|
-
before
|
4
|
+
before do
|
5
|
+
Setting.druthers_cache.clear
|
5
6
|
Setting.delete_all
|
6
7
|
end
|
7
8
|
|
@@ -52,5 +53,10 @@ describe Setting do
|
|
52
53
|
Setting.hashish = h
|
53
54
|
Setting.where(key: 'hashish').first.value.must_equal h
|
54
55
|
end
|
56
|
+
|
57
|
+
it 'returns serialized value correctly' do
|
58
|
+
Setting.change = 'foo'
|
59
|
+
Setting.change.must_equal 'bar'
|
60
|
+
end
|
55
61
|
end
|
56
62
|
end
|
data/test/test_models.rb
CHANGED
@@ -8,8 +8,7 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class Setting < ActiveRecord::Base
|
11
|
-
def_druthers :quest, :favourite_colour, :things, :hashish
|
12
|
-
serialize :value
|
11
|
+
def_druthers :quest, :favourite_colour, :things, :hashish, :change
|
13
12
|
|
14
13
|
def self.default_quest
|
15
14
|
"to find the holy grail"
|
@@ -22,4 +21,18 @@ class Setting < ActiveRecord::Base
|
|
22
21
|
def validate_favourite_colour
|
23
22
|
errors.add(:value, "invalid is invalid WERD") if value == "invalid"
|
24
23
|
end
|
24
|
+
|
25
|
+
class CustomSerialize
|
26
|
+
def self.load(val)
|
27
|
+
ActiveRecord::Coders::YAMLColumn.new.load(val)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.dump(val)
|
31
|
+
val = 'bar' if val == 'foo'
|
32
|
+
ActiveRecord::Coders::YAMLColumn.new.dump(val)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
serialize :value, CustomSerialize
|
37
|
+
|
25
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: druthers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew McEachen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- Rakefile
|
153
153
|
- ci/Gemfile.rails-3.2.x
|
154
154
|
- ci/Gemfile.rails-4.0.x
|
155
|
+
- ci/Gemfile.rails-4.1.x
|
155
156
|
- druthers.gemspec
|
156
157
|
- lib/druthers.rb
|
157
158
|
- lib/druthers/def.rb
|
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
182
|
version: '0'
|
182
183
|
requirements: []
|
183
184
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.0
|
185
|
+
rubygems_version: 2.2.0
|
185
186
|
signing_key:
|
186
187
|
specification_version: 4
|
187
188
|
summary: ''
|