golden_fleece 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: 6dadad30183120be89348ef186c0be8de8d1cf6e
4
- data.tar.gz: 13e14e0c497115e0e7dff33822b2864efd0bb7c6
3
+ metadata.gz: eca661bb7140e8bb690e74d0609e2b4fbfcefd9a
4
+ data.tar.gz: 8b8051cab3fe52d6612616e84a624612bcb66c14
5
5
  SHA512:
6
- metadata.gz: c5b3b5e14665764464cbf89ba630db8c549463572696dc98de7a31a607549426d0d9cc821f06838850313aec07f4f5fcdbaa37cb05acff66544b01638f66fc03
7
- data.tar.gz: 7c115cdb975db18cda2b27aca36329e2c7d23e3ac0c160601e922e18f50a9bb348cdc8df721efbeef5071ff19172889c6f7f8529a9e84b9379307d7493fe35ae
6
+ metadata.gz: 39d48fd3a1ec1900f0945fa5c1cf28f259073065dc3d39e01b0b3acd18946dc45c97d08afdff284c6162d20c973880b4c1de2abc37f6bc2e2f1cc79640b6279b
7
+ data.tar.gz: 45b4d63d453b2a9740aa1e7a8809bcdd85f89b6ee63b5737ac8f7caa9a791a17870b3f40572ddbd73f094b82fb3738e964657bf268913d091cadf1eb427fc947
data/CHANGELOG.md CHANGED
@@ -5,7 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
- ### [0.1.2] - 2015-05-26
8
+ ### [0.1.3] - 2017-05-26
9
+ ### Fixed
10
+ - Remove caching from value computations, which didn't make sense because we were caching model instance values at the model class level.
11
+ - Wrong dates in this change log :-)
12
+
13
+ ### [0.1.2] - 2017-05-26
9
14
  ### Changed
10
15
  - Allow redefining individual schemas
11
16
 
@@ -26,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
26
31
  - Getters
27
32
  - Specs
28
33
 
29
- [Unreleased]: https://github.com/earksiinni/golden_fleece/compare/v0.1.2...HEAD
34
+ [Unreleased]: https://github.com/earksiinni/golden_fleece/compare/v0.1.3...HEAD
35
+ [0.1.2]: https://github.com/earksiinni/golden_fleece/compare/v0.1.2...v0.1.3
30
36
  [0.1.2]: https://github.com/earksiinni/golden_fleece/compare/v0.1.1...v0.1.2
31
37
  [0.1.1]: https://github.com/earksiinni/golden_fleece/compare/v0.1.0...v0.1.1
data/README.md CHANGED
@@ -178,6 +178,25 @@ person.profile['zip_code'] = 90210
178
178
  person.zip_code # '2b02dbc1030b278245b2b9cb11667eebf7275a52'
179
179
  ```
180
180
 
181
+ Be careful! Normalizers can change your data when saving your record. Make sure your normalizer doesn't make invalid assumptions about types, etc.:
182
+
183
+ ```ruby
184
+ define_normalizers({
185
+ csv_to_array: -> record, value { value.to_s.split(/\s*,\s*/) }
186
+ })
187
+
188
+ define_schemas :settings, {
189
+ important_ids: { type: :array, normalizer: :csv_to_array }
190
+ }
191
+
192
+ define_getters :settings
193
+
194
+ person.profile['important_ids'] = '1001, 1002,1003'
195
+ person.important_ids # [1001, 1002, 1003] (as expected)
196
+ person.save # normalizer persists the array in place of the CSV string
197
+ person.important_ids # [0, 1002, 1003] (not expected! normalizer is trying to convert your array to a string, then splitting it on commas)
198
+ ```
199
+
181
200
  ### Formats
182
201
 
183
202
  Formats are Procs that can be used to enforce complex validations:
@@ -7,34 +7,23 @@ module GoldenFleece
7
7
 
8
8
  def initialize(schema)
9
9
  @schema = schema
10
- self.value_initialized = false
11
10
  end
12
11
 
13
12
  def compute(record)
14
13
  @record = record
14
+ @value = Hana::Pointer.new(schema.json_path).eval(record.read_attribute(schema.attribute))
15
15
 
16
- if dirty?
17
- @value = Hana::Pointer.new(schema.json_path).eval(record.read_attribute(schema.attribute))
18
-
19
- cast_booleans
20
- apply_normalizers
21
- apply_default
22
-
23
- self.value_initialized = true
24
- end
16
+ cast_booleans
17
+ apply_normalizers
18
+ apply_default
25
19
 
26
20
  value
27
21
  end
28
22
 
29
23
  private
30
24
 
31
- attr_accessor :value_initialized
32
25
  attr_reader :schema, :record, :value
33
26
 
34
- def dirty?
35
- record.send("#{schema.attribute}_changed?") || !value_initialized
36
- end
37
-
38
27
  # Cast boolean values the way that Rails normally does on boolean columns
39
28
  def cast_booleans
40
29
  if schema.types.include? Definitions::TYPES[:boolean]
@@ -1,3 +1,3 @@
1
1
  module GoldenFleece
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: golden_fleece
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ersin Akinci