setting_accessors 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/lib/setting_accessors/converter.rb +5 -1
- data/lib/setting_accessors/version.rb +1 -1
- 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: 2feddebf42f204a1bfc734b7d5102d3279672665
|
4
|
+
data.tar.gz: 22e487c0075cfa1c8cac7de98f54774eee68b3ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d0bcdb2ec16834a20339e3911c996b6ac84c00cfb8d6f6cb4e66ff5f97311e2103be76e6aa1dfe07e7723752696cda9f83277d001b1deac7bcd70ea3b36ba6c
|
7
|
+
data.tar.gz: 9a6b3249cc6dc734d6cd5e69b5470a720bb1783f8d7d99f9a39103cc51a740382de8cb79a932fdd8045f97fc6baa37e95c1527bf97edc7ea2e0132510833511a
|
data/README.md
CHANGED
@@ -243,9 +243,18 @@ setting did not receive a value yet:
|
|
243
243
|
:validations => {:custom => [:must_be_42]}
|
244
244
|
```
|
245
245
|
|
246
|
-
There are some built-in validations (see above), but
|
247
|
-
|
248
|
-
|
246
|
+
There are some built-in validations (see above), but they should be mostly used for globally defined
|
247
|
+
and globally used settings (`Setting.somethingsomething`).
|
248
|
+
For model specific settings, you may treat the setting accessors just like normal columns
|
249
|
+
and define your validations accordingly, e.g.
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
setting_accessor :my_string, :type => :string
|
253
|
+
setting_accessor :my_number, :type => :integer
|
254
|
+
|
255
|
+
validates :my_string, :presence => true
|
256
|
+
validates :my_number, :numericality => {:only_integer => true}
|
257
|
+
```
|
249
258
|
|
250
259
|
Contributing
|
251
260
|
------------
|
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# If the value cannot be parsed in the required type, +nil+ is assigned.
|
7
7
|
# Please make sure that you specify the correct validations in settings.yml
|
8
|
-
# to avoid this.
|
8
|
+
# or assigned model to avoid this.
|
9
9
|
#
|
10
10
|
# Currently supported types:
|
11
11
|
# - Fixnum
|
@@ -27,6 +27,10 @@ class SettingAccessors::Converter
|
|
27
27
|
#If the value is set to be polymorphic, we don't have to convert anything.
|
28
28
|
return new_value if @value_type == 'polymorphic'
|
29
29
|
|
30
|
+
#ActiveRecord only converts non-nil values to their database type
|
31
|
+
#during assignment
|
32
|
+
return new_value if new_value.nil?
|
33
|
+
|
30
34
|
parse_method = :"parse_#{@value_type}"
|
31
35
|
|
32
36
|
if private_methods.include?(parse_method)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: setting_accessors
|
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
|
- Stefan Exner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|