entity_schema 0.1.2 → 0.1.4
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/.rubocop.yml +8 -18
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/entity_schema/class_methods.rb +1 -1
- data/lib/entity_schema/dsl.rb +33 -11
- data/lib/entity_schema/fields/abstract.rb +18 -35
- data/lib/entity_schema/fields/builders/belongs_to.rb +20 -65
- data/lib/entity_schema/fields/collection.rb +7 -3
- data/lib/entity_schema/fields/contracts/belongs_to.rb +15 -0
- data/lib/entity_schema/fields/contracts/collection.rb +11 -0
- data/lib/entity_schema/fields/contracts/common.rb +16 -0
- data/lib/entity_schema/fields/contracts/contract.rb +54 -0
- data/lib/entity_schema/fields/contracts/fk_belongs_to.rb +11 -0
- data/lib/entity_schema/fields/contracts/object.rb +17 -0
- data/lib/entity_schema/fields/contracts/object_belongs_to.rb +11 -0
- data/lib/entity_schema/fields/contracts/property.rb +13 -0
- data/lib/entity_schema/fields/fk_belongs_to.rb +8 -0
- data/lib/entity_schema/fields/object.rb +7 -6
- data/lib/entity_schema/fields/object_belongs_to.rb +2 -0
- data/lib/entity_schema/fields/property.rb +6 -9
- data/lib/entity_schema/fields/specifications/abstract.rb +89 -0
- data/lib/entity_schema/fields/specifications/belongs_to.rb +22 -0
- data/lib/entity_schema/fields/specifications/collection.rb +14 -0
- data/lib/entity_schema/fields/specifications/common.rb +24 -0
- data/lib/entity_schema/fields/specifications/fk_belongs_to.rb +15 -0
- data/lib/entity_schema/fields/specifications/object.rb +40 -0
- data/lib/entity_schema/fields/specifications/object_belongs_to.rb +13 -0
- data/lib/entity_schema/fields/specifications/property.rb +19 -0
- data/lib/entity_schema/instance_methods.rb +2 -1
- data/lib/entity_schema/setup_field.rb +36 -0
- data/lib/entity_schema/version.rb +1 -1
- metadata +19 -11
- data/.rubocop_todo.yml +0 -26
- data/lib/entity_schema/dsl_helper.rb +0 -26
- data/lib/entity_schema/fields/builders/.rubocop.yml +0 -7
- data/lib/entity_schema/fields/builders/abstract.rb +0 -116
- data/lib/entity_schema/fields/builders/collection.rb +0 -20
- data/lib/entity_schema/fields/builders/fk_belongs_to.rb +0 -21
- data/lib/entity_schema/fields/builders/object.rb +0 -56
- data/lib/entity_schema/fields/builders/object_belongs_to.rb +0 -17
- data/lib/entity_schema/fields/builders/property.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c8d4ea3758bc4fc8c7b1d77707e8fa4dbb1b109d3d7c1e4222e6f8b2033e49a
|
4
|
+
data.tar.gz: c1391072f91aebc7c6b9bf928e1d068066333603fc99a81529700cf1ba3c3b23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1c215d77421ee842d7ff67a02d4f6f96bde80f337925796d3fd50e06815bb53c8577b7adc8ca27c96d9b00d7420efcadcc308e5f5cd3080a47a9f0db3e58db7
|
7
|
+
data.tar.gz: 0d1aff21c0d460cf190ea7f54501dc894202546dbb8e934e85b862f40fed5134c56f521d9a743332f102a100fa196a9ae101781bbb3b2a06f16c6836f4b9c786
|
data/.rubocop.yml
CHANGED
@@ -13,37 +13,22 @@ Naming/ConstantName:
|
|
13
13
|
Exclude:
|
14
14
|
- 'lib/entity_schema.rb'
|
15
15
|
|
16
|
-
Style/Documentation:
|
17
|
-
Exclude:
|
18
|
-
- 'lib/entity_schema.rb'
|
19
|
-
|
20
16
|
Metrics/BlockLength:
|
21
17
|
Exclude:
|
22
18
|
- 'entity_schema.gemspec'
|
23
19
|
|
24
20
|
Metrics/AbcSize:
|
25
21
|
Exclude:
|
26
|
-
- 'lib/entity_schema/
|
27
|
-
|
28
|
-
Metrics/CyclomaticComplexity:
|
29
|
-
Exclude:
|
30
|
-
- 'lib/entity_schema/dsl_helper.rb'
|
31
|
-
|
32
|
-
Metrics/PerceivedComplexity:
|
33
|
-
Exclude:
|
34
|
-
- 'lib/entity_schema/dsl_helper.rb'
|
35
|
-
|
36
|
-
Metrics/MethodLength:
|
37
|
-
Exclude:
|
38
|
-
- 'lib/entity_schema/dsl_helper.rb'
|
22
|
+
- 'lib/entity_schema/setup_field.rb'
|
39
23
|
|
40
24
|
Style/Documentation:
|
41
25
|
Exclude:
|
42
26
|
- 'lib/entity_schema.rb'
|
43
27
|
- 'lib/entity_schema/class_methods.rb'
|
44
|
-
- 'lib/entity_schema/
|
28
|
+
- 'lib/entity_schema/setup_field.rb'
|
45
29
|
- 'lib/entity_schema/fields/abstract.rb'
|
46
30
|
- 'lib/entity_schema/fields/builders/abstract.rb'
|
31
|
+
- 'lib/entity_schema/fields/builders/base.rb'
|
47
32
|
- 'lib/entity_schema/fields/builders/belongs_to.rb'
|
48
33
|
- 'lib/entity_schema/fields/builders/collection.rb'
|
49
34
|
- 'lib/entity_schema/fields/builders/fk_belongs_to.rb'
|
@@ -54,3 +39,8 @@ Style/Documentation:
|
|
54
39
|
- 'lib/entity_schema/fields/object.rb'
|
55
40
|
- 'lib/entity_schema/fields/property.rb'
|
56
41
|
- 'lib/entity_schema/instance_methods.rb'
|
42
|
+
- 'lib/entity_schema/fields/specifications/belongs_to.rb'
|
43
|
+
- 'lib/entity_schema/fields/specifications/common.rb'
|
44
|
+
- 'lib/entity_schema/fields/specifications/fk_belongs_to.rb'
|
45
|
+
- 'lib/entity_schema/fields/specifications/object.rb'
|
46
|
+
- 'lib/entity_schema/fields/specifications/property.rb'
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,13 @@ 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.4]
|
8
|
+
### Improved
|
9
|
+
+ unknown options calling with `:[]`, `:[]=` now constrainted without additional check `raise if`
|
10
|
+
|
11
|
+
### Refactored
|
12
|
+
+ mechanism of fields building: Builder separated to Contract and Specification
|
13
|
+
|
7
14
|
## [0.1.2]
|
8
15
|
### Added
|
9
16
|
+ added `.object serializer:` and `mapper:` options
|
data/Gemfile.lock
CHANGED
data/lib/entity_schema/dsl.rb
CHANGED
@@ -1,40 +1,62 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'fields/
|
4
|
-
require_relative 'fields/
|
5
|
-
require_relative 'fields/
|
3
|
+
require_relative 'fields/specifications/property'
|
4
|
+
require_relative 'fields/specifications/object'
|
5
|
+
require_relative 'fields/specifications/collection'
|
6
|
+
require_relative 'fields/specifications/belongs_to'
|
7
|
+
|
8
|
+
require_relative 'fields/contracts/property'
|
9
|
+
require_relative 'fields/contracts/object'
|
10
|
+
require_relative 'fields/contracts/collection'
|
11
|
+
require_relative 'fields/contracts/belongs_to'
|
12
|
+
|
13
|
+
require_relative 'fields/property'
|
14
|
+
require_relative 'fields/object'
|
15
|
+
require_relative 'fields/collection'
|
6
16
|
require_relative 'fields/builders/belongs_to'
|
7
|
-
|
17
|
+
|
18
|
+
require_relative 'setup_field'
|
8
19
|
|
9
20
|
module EntitySchema
|
10
21
|
# class-level methods for define entity_schema
|
11
22
|
module Dsl
|
12
|
-
include
|
23
|
+
include SetupField
|
13
24
|
|
14
25
|
def property?(name, **opts)
|
15
26
|
property(name, opts.merge!(predicate: true))
|
16
27
|
end
|
17
28
|
|
18
29
|
def property(name, **opts)
|
19
|
-
|
30
|
+
Fields::Contracts::Property.(opts)
|
31
|
+
specicifation = Fields::Specifications::Property.new(name, to_s, opts)
|
32
|
+
field = Fields::Property.new(specicifation)
|
33
|
+
setup_field(field, specicifation)
|
20
34
|
end
|
21
35
|
|
22
36
|
def object(name, **opts)
|
23
|
-
|
37
|
+
Fields::Contracts::Object.(opts)
|
38
|
+
specicifation = Fields::Specifications::Object.new(name, to_s, opts)
|
39
|
+
field = Fields::Object.new(specicifation)
|
40
|
+
setup_field(field, specicifation)
|
24
41
|
end
|
25
42
|
|
26
43
|
alias has_one object
|
27
44
|
|
28
45
|
def collection(name, **opts)
|
29
|
-
|
46
|
+
Fields::Contracts::Collection.(opts)
|
47
|
+
specicifation = Fields::Specifications::Collection.new(name, to_s, opts)
|
48
|
+
field = Fields::Collection.new(specicifation)
|
49
|
+
setup_field(field, specicifation)
|
30
50
|
end
|
31
51
|
|
32
52
|
alias has_many collection
|
33
53
|
|
34
54
|
def belongs_to(name, **opts)
|
35
|
-
|
36
|
-
|
37
|
-
|
55
|
+
Fields::Contracts::BelongsTo.(opts)
|
56
|
+
specicifation = Fields::Specifications::BelongsTo.new(name, to_s, opts)
|
57
|
+
fk, object = Fields::Builders::BelongsTo.(specicifation)
|
58
|
+
setup_field(object, specicifation)
|
59
|
+
setup_field(fk, specicifation)
|
38
60
|
end
|
39
61
|
end
|
40
62
|
end
|
@@ -2,30 +2,29 @@
|
|
2
2
|
|
3
3
|
module EntitySchema
|
4
4
|
module Fields
|
5
|
-
#
|
5
|
+
# Specification for fiend behaviour: internal and external
|
6
|
+
# will be used for build Field object and for setup Field object
|
6
7
|
class Abstract
|
7
|
-
attr_reader :src_key, :name
|
8
|
-
|
9
|
-
def initialize(
|
10
|
-
@name
|
11
|
-
@owner_name
|
12
|
-
@src_key
|
13
|
-
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
@
|
18
|
-
@ivar_name = :"@#{name}"
|
8
|
+
attr_reader :src_key, :name
|
9
|
+
|
10
|
+
def initialize(specification)
|
11
|
+
@name ||= specification.name
|
12
|
+
@owner_name = specification.owner_name
|
13
|
+
@src_key ||= specification.src_key
|
14
|
+
|
15
|
+
@public_getter = specification.public_getter?
|
16
|
+
@public_setter = specification.public_setter?
|
17
|
+
|
18
|
+
@ivar_name = :"@#{name}"
|
19
19
|
end
|
20
20
|
|
21
|
-
# set from public caller
|
22
21
|
def public_set(obj, value)
|
23
|
-
|
22
|
+
raise_public('Setter') unless @public_setter
|
24
23
|
set(obj, value)
|
25
24
|
end
|
26
25
|
|
27
26
|
def public_get(obj)
|
28
|
-
|
27
|
+
raise_public('Getter') unless @public_getter
|
29
28
|
get(obj)
|
30
29
|
end
|
31
30
|
|
@@ -33,10 +32,6 @@ module EntitySchema
|
|
33
32
|
obj.instance_variable_defined?(ivar_name)
|
34
33
|
end
|
35
34
|
|
36
|
-
def delete(obj)
|
37
|
-
obj.remove_instance_variable(ivar_name)
|
38
|
-
end
|
39
|
-
|
40
35
|
def set(obj, value)
|
41
36
|
write(obj, value)
|
42
37
|
end
|
@@ -47,10 +42,6 @@ module EntitySchema
|
|
47
42
|
end
|
48
43
|
# :nocov:
|
49
44
|
|
50
|
-
def predicate?
|
51
|
-
false
|
52
|
-
end
|
53
|
-
|
54
45
|
def serialize(obj, output)
|
55
46
|
output[src_key] = read(obj) if given?(obj)
|
56
47
|
end
|
@@ -65,18 +56,10 @@ module EntitySchema
|
|
65
56
|
|
66
57
|
private
|
67
58
|
|
68
|
-
attr_reader :owner_name, :serialize_method
|
69
|
-
|
70
|
-
def raise_public_set
|
71
|
-
raise NameError, "Private Setter called for field `#{name}` of `#{owner_name}`"
|
72
|
-
end
|
73
|
-
|
74
|
-
def raise_public_get
|
75
|
-
raise NameError, "Private Getter called for field `#{name}` of `#{owner_name}`"
|
76
|
-
end
|
59
|
+
attr_reader :ivar_name, :owner_name, :serialize_method
|
77
60
|
|
78
|
-
def
|
79
|
-
raise "
|
61
|
+
def raise_public(subject)
|
62
|
+
raise NameError, "Private #{subject} called for field `#{name}` of `#{owner_name}`"
|
80
63
|
end
|
81
64
|
|
82
65
|
def read(obj)
|
@@ -1,49 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative '
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
require_relative '../fk_belongs_to'
|
6
|
+
require_relative '../object_belongs_to'
|
6
7
|
require_relative '../observer_belongs_to'
|
7
8
|
|
8
9
|
module EntitySchema
|
9
10
|
module Fields
|
10
11
|
module Builders
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
create_observer(fk, object, opts)
|
12
|
+
# Build two fields: for foreign key property and for related object
|
13
|
+
# link foreign key with his object for interaction
|
14
|
+
class BelongsTo
|
15
|
+
include Singleton
|
16
|
+
|
17
|
+
def call(options)
|
18
|
+
fk = create_fk(options)
|
19
|
+
object = create_object(options)
|
20
|
+
create_observer(fk, object, options)
|
22
21
|
[fk, object]
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
# rubocop:disable Naming/UncommunicativeMethodParamName
|
28
|
-
def extract_options(h)
|
29
|
-
delete_keys(h, all_keys).merge!(
|
30
|
-
pk: check!(:pk, h, [Symbol, nil]),
|
31
|
-
fk: check!(:fk, h, [Symbol, nil])
|
32
|
-
)
|
24
|
+
def self.call(options)
|
25
|
+
instance.call(options)
|
33
26
|
end
|
34
|
-
# rubocop:enable Naming/UncommunicativeMethodParamName
|
35
27
|
|
36
|
-
|
37
|
-
name = fk_name(opts[:fk], object_name)
|
38
|
-
Fields::Builders::FkBelongsTo.(name, schema, create_fk_params(opts, name))
|
39
|
-
end
|
28
|
+
private
|
40
29
|
|
41
|
-
def
|
42
|
-
|
30
|
+
def create_fk(opts)
|
31
|
+
Fields::FkBelongsTo.new(opts)
|
43
32
|
end
|
44
33
|
|
45
|
-
def create_object(
|
46
|
-
Fields::
|
34
|
+
def create_object(opts)
|
35
|
+
Fields::ObjectBelongsTo.new(opts)
|
47
36
|
end
|
48
37
|
|
49
38
|
def create_observer(fk, object, opts)
|
@@ -51,40 +40,6 @@ module EntitySchema
|
|
51
40
|
fk.observer_belongs_to = observer
|
52
41
|
object.observer_belongs_to = observer
|
53
42
|
end
|
54
|
-
|
55
|
-
def all_keys
|
56
|
-
common_keys + only_object_keys + only_fk_keys
|
57
|
-
end
|
58
|
-
|
59
|
-
def object_keys
|
60
|
-
common_keys + only_object_keys
|
61
|
-
end
|
62
|
-
|
63
|
-
def fk_keys
|
64
|
-
common_keys + only_fk_keys
|
65
|
-
end
|
66
|
-
|
67
|
-
def only_object_keys
|
68
|
-
%i[mapper map_to map_method serialize_method serializer serialize]
|
69
|
-
end
|
70
|
-
|
71
|
-
def only_fk_keys
|
72
|
-
[:predicate]
|
73
|
-
end
|
74
|
-
|
75
|
-
def common_keys
|
76
|
-
%i[key getter setter private]
|
77
|
-
end
|
78
|
-
|
79
|
-
def fk_name(fk_name, object_name)
|
80
|
-
fk_name || :"#{object_name}_id"
|
81
|
-
end
|
82
|
-
|
83
|
-
def delete_keys(input_hash, keys)
|
84
|
-
input_hash.slice(*keys).tap do
|
85
|
-
keys.each { |k| input_hash.delete(k) }
|
86
|
-
end
|
87
|
-
end
|
88
43
|
end
|
89
44
|
end
|
90
45
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'abstract'
|
4
|
+
|
3
5
|
module EntitySchema
|
4
6
|
module Fields
|
5
|
-
#
|
7
|
+
# associated array of objects
|
6
8
|
class Collection < Object
|
7
9
|
def set(obj, collection)
|
8
|
-
|
9
|
-
|
10
|
+
case collection
|
11
|
+
when Array, nil then super
|
12
|
+
else raise ArgumentError, 'collection field must be Array'
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
def get(obj)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'fk_belongs_to'
|
4
|
+
require_relative 'object_belongs_to'
|
5
|
+
|
6
|
+
module EntitySchema
|
7
|
+
module Fields
|
8
|
+
module Contracts
|
9
|
+
BelongsTo = FkBelongsTo + ObjectBelongsTo + {
|
10
|
+
fk: { eq: nil, type: Symbol },
|
11
|
+
pk: { eq: nil, type: Symbol }
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'contract'
|
4
|
+
|
5
|
+
module EntitySchema
|
6
|
+
module Fields
|
7
|
+
module Contracts
|
8
|
+
Common = Contract.new(
|
9
|
+
key: { eq: nil, type: Symbol },
|
10
|
+
getter: { eq: [:private, nil] },
|
11
|
+
setter: { eq: [:private, nil] },
|
12
|
+
private: { eq: [true, false, :getter, :setter, nil] }
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EntitySchema
|
4
|
+
module Fields
|
5
|
+
module Contracts
|
6
|
+
# Check data with strict contract, described with Hash-based DSL
|
7
|
+
class Contract
|
8
|
+
def initialize(rules)
|
9
|
+
@rules = rules
|
10
|
+
end
|
11
|
+
|
12
|
+
def +(other)
|
13
|
+
self.class.new(rules.merge(other.to_h))
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(raw_options, skip_unknown: false) # rubocop:disable Metrics/AbcSize
|
17
|
+
raw_options.each do |key, value|
|
18
|
+
rules.key?(key) || skip_unknown || raise_unknown!(key, value)
|
19
|
+
|
20
|
+
r = rules[key]
|
21
|
+
next if Array(r[:eq]).any? { |expectation| expectation == value }
|
22
|
+
next if Array(r[:type]).any? { |type| value.is_a?(type) }
|
23
|
+
next if Array(r[:respond_to]).any? { |meth| value.respond_to?(meth) }
|
24
|
+
raise_unexpected_value(r, key, value)
|
25
|
+
end
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_h
|
30
|
+
rules
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :rules
|
36
|
+
|
37
|
+
def raise_unknown!(key, value)
|
38
|
+
raise "Unknown option `#{key.inspect} => #{value.inspect}` given." \
|
39
|
+
" Known options: #{rules.keys}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def raise_unexpected_value(rules, key, value)
|
43
|
+
msg = "Unexpected option value `#{value.inspect}` of option `#{key.inspect}`. \n" \
|
44
|
+
' Expected to:'
|
45
|
+
msgs = []
|
46
|
+
msgs << "\n be equal to the one of #{rules[:eq]}" if rules.key?(:eq)
|
47
|
+
msgs << "\n be one of #{rules[:type]}" if rules.key?(:ty)
|
48
|
+
msgs << "\n respond to one of the methods #{rules[:respond_to]}"
|
49
|
+
raise TypeError, (msg + msgs * ' OR')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'common'
|
4
|
+
|
5
|
+
module EntitySchema
|
6
|
+
module Fields
|
7
|
+
module Contracts
|
8
|
+
Object = Common + {
|
9
|
+
mapper: { type: Symbol, eq: nil, respond_to: :call },
|
10
|
+
map_to: { type: Class, eq: nil },
|
11
|
+
map_method: { type: Symbol, eq: nil },
|
12
|
+
serializer: { type: Symbol, eq: nil, respond_to: :call },
|
13
|
+
serialize: { type: Symbol, eq: nil }
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,11 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'abstract'
|
4
|
+
|
3
5
|
module EntitySchema
|
4
6
|
module Fields
|
5
7
|
# Fk
|
6
8
|
class FkBelongsTo < Property
|
7
9
|
attr_accessor :observer_belongs_to
|
8
10
|
|
11
|
+
def initialize(options)
|
12
|
+
@name = options.fk
|
13
|
+
@src_key = options.fk
|
14
|
+
super(options)
|
15
|
+
end
|
16
|
+
|
9
17
|
def set(obj, value, notify_observer: true)
|
10
18
|
super(obj, value).tap do |fk|
|
11
19
|
observer_belongs_to.fk_changed(fk, obj) if notify_observer
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'abstract'
|
4
|
+
|
3
5
|
module EntitySchema
|
4
6
|
module Fields
|
5
|
-
#
|
7
|
+
# Associated object
|
6
8
|
class Object < Abstract
|
7
|
-
def initialize(
|
8
|
-
@mapper =
|
9
|
-
@serializer =
|
10
|
-
super(
|
11
|
-
guard_unknown_options!(options)
|
9
|
+
def initialize(specification)
|
10
|
+
@mapper = specification.mapper
|
11
|
+
@serializer = specification.serializer
|
12
|
+
super(specification)
|
12
13
|
end
|
13
14
|
|
14
15
|
def get(obj)
|
@@ -2,18 +2,15 @@
|
|
2
2
|
|
3
3
|
require_relative 'abstract'
|
4
4
|
|
5
|
+
require_relative 'abstract'
|
6
|
+
|
5
7
|
module EntitySchema
|
6
8
|
module Fields
|
7
|
-
#
|
9
|
+
# Simple field with any value
|
8
10
|
class Property < Abstract
|
9
|
-
def initialize(
|
10
|
-
@predicate = options.
|
11
|
-
super(
|
12
|
-
guard_unknown_options!(options)
|
13
|
-
end
|
14
|
-
|
15
|
-
def predicate?
|
16
|
-
@predicate
|
11
|
+
def initialize(options)
|
12
|
+
@predicate = options.predicate
|
13
|
+
super(options)
|
17
14
|
end
|
18
15
|
|
19
16
|
def get(obj)
|