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 +4 -4
- data/CHANGELOG.md +8 -2
- data/README.md +19 -0
- data/lib/golden_fleece/value.rb +4 -15
- data/lib/golden_fleece/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eca661bb7140e8bb690e74d0609e2b4fbfcefd9a
|
4
|
+
data.tar.gz: 8b8051cab3fe52d6612616e84a624612bcb66c14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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:
|
data/lib/golden_fleece/value.rb
CHANGED
@@ -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
|
-
|
17
|
-
|
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]
|