sumaki 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +6 -0
- data/lib/sumaki/model/associations/reflection.rb +2 -2
- data/lib/sumaki/model/associations.rb +9 -19
- data/lib/sumaki/model/enum.rb +7 -17
- data/lib/sumaki/model/fields.rb +14 -23
- data/lib/sumaki/model.rb +11 -3
- data/lib/sumaki/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2be73f4aecd4989e377b39115c0fc5dfbd49ac540c897c0ec7c28f2401bac2af
|
4
|
+
data.tar.gz: be673d004a1fe0ba7fd93c195dfac2e2f097318da1e5a7d308220cfc9cb16539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faf86d0ed3126295b4a4bc5f39f6cdda4b55d19aef9856af17c576cff16721cb72b0ecb78a55fb0d812ddfa05ea420581a456890f2dfc0f615ad76646db699e8
|
7
|
+
data.tar.gz: 8e6d8faafd3138cdb6bc1f32eea54b348cab3816db7f713b8f9c4a45ab06263de73bc882f6008abeb2bf230588ac7245acfad1618f3a26abd563be84b0690835
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sumaki (0.
|
5
|
-
minenum
|
4
|
+
sumaki (0.5.1)
|
5
|
+
minenum (>= 0.2.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
reline (>= 0.4.2)
|
20
20
|
json (2.7.2)
|
21
21
|
language_server-protocol (3.17.0.3)
|
22
|
-
minenum (0.1
|
22
|
+
minenum (0.2.1)
|
23
23
|
parallel (1.24.0)
|
24
24
|
parser (3.3.1.0)
|
25
25
|
ast (~> 2.4.1)
|
data/README.md
CHANGED
@@ -298,6 +298,12 @@ character.type.familier? #=> true
|
|
298
298
|
character = Character.new({})
|
299
299
|
character.type = 1
|
300
300
|
character.type.name #=> :vampire
|
301
|
+
|
302
|
+
character.type = :vampire_hunter
|
303
|
+
character.type.name #=> :vampire_hunter
|
304
|
+
|
305
|
+
character.type.familier!
|
306
|
+
character.type.name #=> :familier
|
301
307
|
```
|
302
308
|
|
303
309
|
|
@@ -18,8 +18,8 @@ module Sumaki
|
|
18
18
|
def model_class
|
19
19
|
@model_class ||= begin
|
20
20
|
basename = @class_name&.to_s || classify(@name.to_s)
|
21
|
-
klass = if @owner_class.const_defined?(basename)
|
22
|
-
@owner_class.const_get(basename)
|
21
|
+
klass = if @owner_class.const_defined?(basename, false)
|
22
|
+
@owner_class.const_get(basename, false)
|
23
23
|
else
|
24
24
|
@owner_class.const_set(basename, Class.new { include Model })
|
25
25
|
end
|
@@ -14,11 +14,11 @@ module Sumaki
|
|
14
14
|
|
15
15
|
module AccessorAdder
|
16
16
|
module Singular # :nodoc:
|
17
|
-
def add(
|
17
|
+
def add(methods_module, reflections, reflection)
|
18
18
|
add_getter(methods_module, reflection.name)
|
19
19
|
add_builder(methods_module, reflection.name)
|
20
20
|
|
21
|
-
|
21
|
+
reflections[reflection.name] = reflection
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
@@ -43,14 +43,14 @@ module Sumaki
|
|
43
43
|
end
|
44
44
|
|
45
45
|
module Repeated # :nodoc:
|
46
|
-
def add(
|
46
|
+
def add(methods_module, reflections, reflection)
|
47
47
|
methods_module.module_eval <<~RUBY, __FILE__, __LINE__ + 1
|
48
48
|
def #{reflection.name} # def book
|
49
49
|
association(:#{reflection.name}).collection # association(:book).collection
|
50
50
|
end # end
|
51
51
|
RUBY
|
52
52
|
|
53
|
-
|
53
|
+
reflections[reflection.name] = reflection
|
54
54
|
end
|
55
55
|
module_function :add
|
56
56
|
end
|
@@ -90,7 +90,7 @@ module Sumaki
|
|
90
90
|
# to wrap is not inferred from the nested field names.
|
91
91
|
def singular(name, class_name: nil)
|
92
92
|
reflection = Reflection::Singular.new(self, name, class_name: class_name)
|
93
|
-
AccessorAdder::Singular.add(
|
93
|
+
AccessorAdder::Singular.add(_sumaki_methods_module, _sumaki_association_reflections, reflection)
|
94
94
|
end
|
95
95
|
|
96
96
|
# Access to the repeated sub objects
|
@@ -128,21 +128,11 @@ module Sumaki
|
|
128
128
|
# to wrap is not inferred from the nested field names.
|
129
129
|
def repeated(name, class_name: nil)
|
130
130
|
reflection = Reflection::Repeated.new(self, name, class_name: class_name)
|
131
|
-
AccessorAdder::Repeated.add(
|
131
|
+
AccessorAdder::Repeated.add(_sumaki_methods_module, _sumaki_association_reflections, reflection)
|
132
132
|
end
|
133
133
|
|
134
|
-
def
|
135
|
-
@
|
136
|
-
end
|
137
|
-
|
138
|
-
private
|
139
|
-
|
140
|
-
def association_methods_module
|
141
|
-
@association_methods_module ||= begin
|
142
|
-
mod = Module.new
|
143
|
-
include mod
|
144
|
-
mod
|
145
|
-
end
|
134
|
+
def _sumaki_association_reflections
|
135
|
+
@_sumaki_association_reflections ||= {}
|
146
136
|
end
|
147
137
|
end
|
148
138
|
|
@@ -151,7 +141,7 @@ module Sumaki
|
|
151
141
|
|
152
142
|
def association(name)
|
153
143
|
@associations ||= {}
|
154
|
-
@associations[name.to_sym] ||= self.class.
|
144
|
+
@associations[name.to_sym] ||= self.class._sumaki_association_reflections[name.to_sym].association_for(self)
|
155
145
|
end
|
156
146
|
end
|
157
147
|
end
|
data/lib/sumaki/model/enum.rb
CHANGED
@@ -11,15 +11,14 @@ module Sumaki
|
|
11
11
|
base.extend ClassMethods
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
def get
|
16
|
-
|
14
|
+
class EnumAttrAccessor < Minenum::Enum::Adapter::Base # :nodoc:
|
15
|
+
def get
|
16
|
+
@enum_object.get(@name)
|
17
17
|
end
|
18
18
|
|
19
|
-
def set(
|
20
|
-
|
19
|
+
def set(value)
|
20
|
+
@enum_object.set(@name, value)
|
21
21
|
end
|
22
|
-
module_function :get, :set
|
23
22
|
end
|
24
23
|
|
25
24
|
module ClassMethods # :nodoc:
|
@@ -47,17 +46,8 @@ module Sumaki
|
|
47
46
|
# character.type = 1
|
48
47
|
# character.type.name #=> :vampire
|
49
48
|
def enum(name, values)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def enum_methods_module
|
56
|
-
@enum_methods_module ||= begin
|
57
|
-
mod = Module.new
|
58
|
-
include mod
|
59
|
-
mod
|
60
|
-
end
|
49
|
+
_minenum_enum(name, values, _sumaki_methods_module, _sumaki_attribute_reflections,
|
50
|
+
adapter_builder: EnumAttrAccessor)
|
61
51
|
end
|
62
52
|
end
|
63
53
|
end
|
data/lib/sumaki/model/fields.rb
CHANGED
@@ -12,19 +12,20 @@ module Sumaki
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class FieldAccessor # :nodoc:
|
15
|
-
def initialize(model)
|
15
|
+
def initialize(model, reflections)
|
16
16
|
@model = model
|
17
|
+
@reflections = reflections
|
17
18
|
end
|
18
19
|
|
19
20
|
def get(field_name)
|
20
|
-
reflection = @
|
21
|
+
reflection = @reflections[field_name]
|
21
22
|
|
22
23
|
value = @model.get(reflection.name)
|
23
24
|
reflection.type_class.deserialize(value)
|
24
25
|
end
|
25
26
|
|
26
27
|
def set(field_name, value)
|
27
|
-
reflection = @
|
28
|
+
reflection = @reflections[field_name]
|
28
29
|
|
29
30
|
serialized = reflection.type_class.serialize(value)
|
30
31
|
@model.set(reflection.name, serialized)
|
@@ -32,11 +33,11 @@ module Sumaki
|
|
32
33
|
end
|
33
34
|
|
34
35
|
module AccessorAdder # :nodoc:
|
35
|
-
def add(
|
36
|
+
def add(methods_module, reflections, reflection)
|
36
37
|
add_getter(methods_module, reflection.name)
|
37
38
|
add_setter(methods_module, reflection.name)
|
38
39
|
|
39
|
-
|
40
|
+
reflections[reflection.name] = reflection
|
40
41
|
end
|
41
42
|
|
42
43
|
def add_getter(methods_module, field_name)
|
@@ -99,37 +100,27 @@ module Sumaki
|
|
99
100
|
# * <tt>:datetime</tt>
|
100
101
|
def field(name, type = nil)
|
101
102
|
reflection = Reflection.new(name, type)
|
102
|
-
AccessorAdder.add(
|
103
|
+
AccessorAdder.add(_sumaki_methods_module, _sumaki_attribute_reflections, reflection)
|
103
104
|
end
|
104
105
|
|
105
|
-
def
|
106
|
-
|
106
|
+
def attribute_names
|
107
|
+
_sumaki_attribute_reflections.keys
|
107
108
|
end
|
108
109
|
|
109
|
-
def
|
110
|
-
@
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
def attribute_methods_module
|
116
|
-
@attribute_methods_module ||= begin
|
117
|
-
mod = Module.new
|
118
|
-
include mod
|
119
|
-
mod
|
120
|
-
end
|
110
|
+
def _sumaki_attribute_reflections
|
111
|
+
@_sumaki_attribute_reflections ||= {}
|
121
112
|
end
|
122
113
|
end
|
123
114
|
|
124
115
|
module InstanceMethods # :nodoc:
|
125
|
-
def
|
126
|
-
self.class.
|
116
|
+
def attributes
|
117
|
+
self.class.attribute_names.map.with_object({}) { |e, r| r[e] = public_send(e) }
|
127
118
|
end
|
128
119
|
|
129
120
|
private
|
130
121
|
|
131
122
|
def field_accessor
|
132
|
-
@field_accessor ||= FieldAccessor.new(self)
|
123
|
+
@field_accessor ||= FieldAccessor.new(self, self.class._sumaki_attribute_reflections)
|
133
124
|
end
|
134
125
|
end
|
135
126
|
end
|
data/lib/sumaki/model.rb
CHANGED
@@ -175,6 +175,14 @@ module Sumaki
|
|
175
175
|
def adapter
|
176
176
|
@adapter || parent&.adapter || Config.default_adapter
|
177
177
|
end
|
178
|
+
|
179
|
+
def _sumaki_methods_module
|
180
|
+
@_sumaki_methods_module ||= begin
|
181
|
+
mod = Module.new
|
182
|
+
include mod
|
183
|
+
mod
|
184
|
+
end
|
185
|
+
end
|
178
186
|
end
|
179
187
|
|
180
188
|
class ObjectAccessor # :nodoc:
|
@@ -231,7 +239,7 @@ module Sumaki
|
|
231
239
|
end
|
232
240
|
|
233
241
|
def inspect
|
234
|
-
inspection =
|
242
|
+
inspection = attributes
|
235
243
|
.map { |name, value| "#{name}: #{value.inspect}" }
|
236
244
|
.join(', ')
|
237
245
|
"#<#{self.class.name} #{inspection}>"
|
@@ -239,10 +247,10 @@ module Sumaki
|
|
239
247
|
|
240
248
|
def pretty_print(pp) # rubocop:disable Metrics/MethodLength
|
241
249
|
pp.object_address_group(self) do
|
242
|
-
pp.seplist(
|
250
|
+
pp.seplist(attributes, -> { pp.text ',' }) do |attribute, value|
|
243
251
|
pp.breakable
|
244
252
|
pp.group(1) do
|
245
|
-
pp.text
|
253
|
+
pp.text attribute.to_s
|
246
254
|
pp.text ':'
|
247
255
|
pp.breakable
|
248
256
|
pp.pp value
|
data/lib/sumaki/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sumaki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loose Coupling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minenum
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.2.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.2.1
|
27
27
|
description: |
|
28
28
|
Sumaki is a wrapper for structured data like JSON.
|
29
29
|
Since Sumaki wraps the target data as it is, rather than parsing it using a schema, the original data can be referenced at any time.
|