normalizr 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '068b8f6b2685d273ee884c7a8c0f751da02fd254fe56f0ee6366f304910f81f6'
4
- data.tar.gz: 9edd590a85219a2ea44651412e32fced140dad016b3035acadcd1ebc43df2408
3
+ metadata.gz: 03dfb54450a14ca113c1e45f01f0b7f14356e6f12f6cfa90dddb0d2f49f85635
4
+ data.tar.gz: d72f8210ab5e58c404efb64e6854de2f48a342f2388cd4ca5d3931fd07b59f47
5
5
  SHA512:
6
- metadata.gz: eb22312649da1951b0fe9d0d1214851ebeb62d408217156a0427a55b442814505e68786a513898e8ca8b095701cd47d4880e5c82ba943993b1516cbfd8b04774
7
- data.tar.gz: 06c555da8af5e30f7527927518e28186577ac1baf2c36b0a0ae9ce3a4596c6cc15eb13c08f9a361e833e84665eb4ed769c9f3ff9d3d4f725db2d8cfa5eb82e37
6
+ metadata.gz: 2627756373049880c2c048b738354282df325bcdf1e56d875cd702a8ecd5fc73b63fda8f300d0c2ce2738fc0777774e8a5f993a37bd598cfac5016fba76ae292
7
+ data.tar.gz: 2a9ec23470882aefb1c8a2b85aa2ba280ba1d490cea311eb4986a6f30382a9e73916b008b92aaed4c9ee5b5a8231b4a0a5c2f0bd251c7f9373330c714a885b4a
@@ -1,3 +1,7 @@
1
+ ### 0.3.1 / 2018-03-22
2
+
3
+ * Fix conditional normalization
4
+
1
5
  ### 0.3.0 / 2018-03-21
2
6
 
3
7
  * Add a possibility to use if/unless cases for normalizer options (@TheTharin)
data/README.md CHANGED
@@ -140,8 +140,8 @@ class Book
140
140
 
141
141
  normalize :author, if: :author_should_be_normalized?
142
142
  normalize :description, unless: :description_should_not_be_normalized?
143
-
144
- normalize :author, if: proc { date.today? }
143
+
144
+ normalize :author, if: -> { date.today? }
145
145
  end
146
146
  ```
147
147
 
@@ -11,8 +11,10 @@ module Normalizr
11
11
  prepend Module.new {
12
12
  options.attributes.each do |method|
13
13
  define_method :"#{method}=" do |value|
14
- positive = options.positive_condition.all? { |condition| instance_eval(&condition) }
15
- negative = options.negative_condition.none? { |condition| instance_eval(&condition) }
14
+ condition_lambda = -> condition { Proc === condition ? instance_exec(&condition) : send(condition) }
15
+
16
+ positive = options.positive_condition.all? &condition_lambda
17
+ negative = options.negative_condition.none? &condition_lambda
16
18
 
17
19
  if positive && negative
18
20
  value = Normalizr.normalize(value, *options.before)
@@ -1,3 +1,3 @@
1
1
  module Normalizr
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -3,7 +3,9 @@ class User < Person
3
3
 
4
4
  normalize :lastname, if: :should_normalize_lastname?
5
5
  normalize :maidenname, if: :should_normalize_maidenname_positive?, unless: :should_normalize_maidenname_negative?
6
- normalize :favouritebook, if: proc { true }
6
+ normalize :favouritebook, if: -> { true }
7
+
8
+ private
7
9
 
8
10
  def should_normalize_lastname?
9
11
  true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: normalizr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-21 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry