entity_schema 0.1.6 → 0.1.7
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/entity_schema/contracts/contract.rb +2 -2
- data/lib/entity_schema/contracts/object.rb +2 -2
- data/lib/entity_schema/fields/object.rb +1 -2
- data/lib/entity_schema/transformers/object.rb +8 -1
- data/lib/entity_schema/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0a6b46788f0b19b60b483b5a57df1bed781632c6d98be6af73fd46d3764c4e0
|
4
|
+
data.tar.gz: 3f7bed4d2e72995b7fa361ee080027edbb7483a555f6667c5886b2378c46e79a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3051a78f0a428db5ab2fa121bfb3148cc94cd94fb237345705ebd84fef241a20a99b8404087d62f59266979302f8c10281a3be200e6e4e42d434eb461f396cb
|
7
|
+
data.tar.gz: d1a725d165cc1f7a66dd017daac7b04749f7ed70c8bef5b439084b325962d911eddf3f2e5b01e9231c69134a51d9a82a29b430b3f867e3230e12cc79c982aeb7
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.1.7]
|
8
|
+
### Added
|
9
|
+
+ `map_to:` option can receive String or Symbol with class name, that will be used for `#const_get` in runtime, after schema building
|
10
|
+
It needed for prevent constant cross-requirements lock in Ruby: when file `foo.rb` contains class `Foo`, that depends on class `Bar` from file `bar.rb`, and `Bar` depends on `Foo`.
|
11
|
+
|
7
12
|
## [0.1.4]
|
8
13
|
### Improved
|
9
14
|
+ unknown options calling with `:[]`, `:[]=` now constrainted without additional check `raise if`
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -17,8 +17,8 @@ class Product
|
|
17
17
|
|
18
18
|
object :size, map_to: Values::Size
|
19
19
|
|
20
|
-
belongs_to :color,
|
21
|
-
has_many :seasons,
|
20
|
+
belongs_to :color, Color, pk: :color_uid, fk: :uid
|
21
|
+
has_many :seasons, Season
|
22
22
|
end
|
23
23
|
```
|
24
24
|
|
@@ -83,11 +83,11 @@ module EntitySchema
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# rubocop:disable Metrics/LineLength
|
86
|
-
def raise_unexpected_value(rules, key, value)
|
86
|
+
def raise_unexpected_value(rules, key, value)
|
87
87
|
msg = "Unexpected #{key.inspect} value `#{value.inspect}`. \n" \
|
88
88
|
' Expected to:'
|
89
89
|
msgs = []
|
90
|
-
msgs << "\n be equal to
|
90
|
+
msgs << "\n be equal to: #{rules[:eq]}" if rules.key?(:eq)
|
91
91
|
msgs << "\n be one of: #{rules[:type]}" if rules[:type]
|
92
92
|
msgs << "\n respond to one of the methods: #{rules[:respond_to]}" if rules.key?(:respond_to)
|
93
93
|
raise TypeError, (msg + msgs * ' OR')
|
@@ -6,9 +6,9 @@ module EntitySchema
|
|
6
6
|
module Contracts
|
7
7
|
Object = Common + [
|
8
8
|
{ type: Symbol },
|
9
|
-
{ type: Class, eq: [nil] },
|
9
|
+
{ type: [Class, Symbol, String], eq: [nil] },
|
10
10
|
mapper: { type: Symbol, eq: [nil], respond_to: :call },
|
11
|
-
map_to: { type: Class,
|
11
|
+
map_to: { type: [Class, Symbol, String], eq: [nil] },
|
12
12
|
map_method: { type: Symbol, eq: [nil] },
|
13
13
|
serializer: { type: Symbol, eq: [nil], respond_to: :call },
|
14
14
|
serialize: { type: Symbol, eq: [nil] }
|
@@ -20,8 +20,7 @@ module EntitySchema
|
|
20
20
|
def serialize(obj, output)
|
21
21
|
return unless given?(obj)
|
22
22
|
value = read(obj)
|
23
|
-
|
24
|
-
output[src_key] = unwrap(value)
|
23
|
+
output[src_key] = (value.is_a?(Hash) ? value : unwrap(value))
|
25
24
|
end
|
26
25
|
|
27
26
|
private
|
@@ -21,7 +21,14 @@ module EntitySchema
|
|
21
21
|
def mapper(map_to, map_method)
|
22
22
|
return if map_to.nil?
|
23
23
|
map_method ||= :new
|
24
|
-
|
24
|
+
|
25
|
+
lambda do |hash|
|
26
|
+
if map_to.is_a?(Class)
|
27
|
+
map_to.public_send(map_method, hash)
|
28
|
+
else
|
29
|
+
Object.const_get(map_to).public_send(map_method, hash)
|
30
|
+
end
|
31
|
+
end
|
25
32
|
end
|
26
33
|
|
27
34
|
def default_mapper
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entity_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Captain Philipp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|