sumaki 0.5.0 → 0.5.1

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: dc2e15ea308cacd7c524ba33698734f08020c2c9d6fb9b39accb4c79bc108a67
4
- data.tar.gz: 1090e186dd028117e5f6cb7df816004dcc9508313757e6af8b802d6eeef74a2d
3
+ metadata.gz: 2be73f4aecd4989e377b39115c0fc5dfbd49ac540c897c0ec7c28f2401bac2af
4
+ data.tar.gz: be673d004a1fe0ba7fd93c195dfac2e2f097318da1e5a7d308220cfc9cb16539
5
5
  SHA512:
6
- metadata.gz: 720e0a53bf096093e5e25c5b2dbd2d562666e696d274147d1b3634e49a350309be22b1ada5e069c43f23025e4fdeafbde25c7a9f0b8a4f2d05ffc47fcc7a25d6
7
- data.tar.gz: e00e0ef3b7f0af18c438e680e4bfdc40aa83b3409853c5cc587c529b43c9c2f73cd9ad72d0e383d738fbe8879247a8f25beb829001daa3d397e836f1486850a6
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.0)
5
- minenum (>= 0.2.0)
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.2.0)
22
+ minenum (0.2.1)
23
23
  parallel (1.24.0)
24
24
  parser (3.3.1.0)
25
25
  ast (~> 2.4.1)
@@ -14,11 +14,11 @@ module Sumaki
14
14
 
15
15
  module AccessorAdder
16
16
  module Singular # :nodoc:
17
- def add(model_class, methods_module, reflection)
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
- model_class.reflections[reflection.name] = reflection
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(model_class, methods_module, reflection)
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
- model_class.reflections[reflection.name] = reflection
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(self, association_methods_module, reflection)
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(self, association_methods_module, reflection)
131
+ AccessorAdder::Repeated.add(_sumaki_methods_module, _sumaki_association_reflections, reflection)
132
132
  end
133
133
 
134
- def reflections
135
- @reflections ||= {}
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.reflections[name.to_sym].association_for(self)
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
@@ -46,17 +46,8 @@ module Sumaki
46
46
  # character.type = 1
47
47
  # character.type.name #=> :vampire
48
48
  def enum(name, values)
49
- super(name, values, adapter_builder: EnumAttrAccessor)
50
- end
51
-
52
- private
53
-
54
- def enum_methods_module
55
- @enum_methods_module ||= begin
56
- mod = Module.new
57
- include mod
58
- mod
59
- end
49
+ _minenum_enum(name, values, _sumaki_methods_module, _sumaki_attribute_reflections,
50
+ adapter_builder: EnumAttrAccessor)
60
51
  end
61
52
  end
62
53
  end
@@ -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 = @model.class.field_reflections[field_name]
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 = @model.class.field_reflections[field_name]
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(model_class, methods_module, reflection)
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
- model_class.field_reflections[reflection.name] = reflection
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(self, attribute_methods_module, reflection)
103
+ AccessorAdder.add(_sumaki_methods_module, _sumaki_attribute_reflections, reflection)
103
104
  end
104
105
 
105
- def field_names
106
- field_reflections.keys
106
+ def attribute_names
107
+ _sumaki_attribute_reflections.keys
107
108
  end
108
109
 
109
- def field_reflections
110
- @field_reflections ||= {}
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 fields
126
- self.class.field_names.map.with_object({}) { |e, r| r[e] = public_send(e) }
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 = fields
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(fields, -> { pp.text ',' }) do |field, value|
250
+ pp.seplist(attributes, -> { pp.text ',' }) do |attribute, value|
243
251
  pp.breakable
244
252
  pp.group(1) do
245
- pp.text field.to_s
253
+ pp.text attribute.to_s
246
254
  pp.text ':'
247
255
  pp.breakable
248
256
  pp.pp value
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sumaki
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
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.5.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-06-03 00:00:00.000000000 Z
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: 0.2.0
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: 0.2.0
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.