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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ee8ab3545011ba2dd7016082e6c00bd3d371a789561657fb40f7747c43ab524
4
- data.tar.gz: 94e051259093bb827d951e05be4b9175d40f103fd31f61fb2c35f6bcec73c5fa
3
+ metadata.gz: f0a6b46788f0b19b60b483b5a57df1bed781632c6d98be6af73fd46d3764c4e0
4
+ data.tar.gz: 3f7bed4d2e72995b7fa361ee080027edbb7483a555f6667c5886b2378c46e79a
5
5
  SHA512:
6
- metadata.gz: f13cd0e8fdad2b33483131c2477f58218beff9160ad2d71c0a83bd083c966bb6d3de4d1878acc86e35c987d15d9f9b42c43c3035245482fa3515611133c2a096
7
- data.tar.gz: 9abbe10cad5d6b48ee2836a83823d3c8ee6b45302c17085d86b732f4c1f53e15ea3d2bbf023b8c7f88f9f0bb78ab64c15a7bec8de0546afb434704e9b19ca450
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- entity_schema (0.1.6)
4
+ entity_schema (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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, map_to: Color, pk: :color_uid, fk: :uid
21
- has_many :seasons, map_to: Season
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) # rubocop:disable Metrics/AbcSize
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 the one of: #{rules[:eq]&.map(&:inspect)}" if rules.key?(:eq)
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, eq: [nil] },
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
- return output[src_key] = value if value.is_a?(Hash)
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
- ->(hash) { map_to.public_send(map_method, hash) }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EntitySchema
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  end
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.6
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-08-25 00:00:00.000000000 Z
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler