setting_accessors 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3114ad72cb4a99f7e984b750a81bb1ea4acff3d3
4
- data.tar.gz: 04bd6c11d031bca8467190cd32fa47010aa1af27
3
+ metadata.gz: 2feddebf42f204a1bfc734b7d5102d3279672665
4
+ data.tar.gz: 22e487c0075cfa1c8cac7de98f54774eee68b3ab
5
5
  SHA512:
6
- metadata.gz: 3bbfb279bb02f9e4ac1235a5200c56100607ca2b27797974635732999399bd832e190ea3fd4c70ae9616ae9dd34c77b1a2450d204b657c3cca39b2c9686a54e9
7
- data.tar.gz: 0fd5e574b4687d9054c8e0983c9b8d455eebd441be70d43a7dacc50bb4f3bc556532b3d10d22024199e3d8fd10dd465326def7d245c9f914ab44ab7ac8295cd0
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 you may also define custom
247
- validations either by passing in anonymous functions or symbols representing
248
- class methods either in the setting class or the assigned model.
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)
@@ -1,3 +1,3 @@
1
1
  module SettingAccessors
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
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.2
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-21 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler