glue_gun_dsl 0.1.27 → 0.1.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 697e6798ae2b2c4c3db3f4e3cd9b2c65ccc8081386636c08366e4d023cb04afe
4
- data.tar.gz: f7a025244f1b5627691676d784658d2a14a289914533e17f4c1daca896c6ebdf
3
+ metadata.gz: 1c7ef75df045c142a9b1175b91ad7f7745179ea3dacfa5c30c2b2409e1d4fe78
4
+ data.tar.gz: 3e55b0b662c7ccf655e784cc9672a5e6f7a792268bd0140d28e66b8b4439b627
5
5
  SHA512:
6
- metadata.gz: 8d32f478f2e294ae9510abb04b0ac5b5490c8468918879363f790eebc5167d7c3e28ec5edf9675301a2a211b7f5493bcf24c1884295598e9cf859f5b6b146f21
7
- data.tar.gz: ee627464ed957cffac221bd2d701e9a9deba768e1cac558349878d101b67281a2c5977379f79496af43ed7bdbc392489c60e7d3fec2d09445b2e35526d2d256f
6
+ metadata.gz: f97de5312eaaae95f2c57bd8691a4751f55902ffdd7f8140d0f11a6548c2004afc47f31612f1e7ad14b42e2d530bdbf588349a9e8c4c0645a8dc760da3b383c4
7
+ data.tar.gz: 11916bd9c893ce87058a1fbf1e4f2b4b9fbcd16b8867493e35c932622e8ebcbe43ed8cee3291219aa24a274cb60a79f6d1f9ae15c67c712e1bf3f3398805f6a6
@@ -139,6 +139,10 @@ module GlueGun
139
139
 
140
140
  private
141
141
 
142
+ def awesome_print(message)
143
+ ap message
144
+ end
145
+
142
146
  def build_service_object(attributes)
143
147
  self.class.send(:attr_reader, service_attribute_name)
144
148
  service_class = resolve_service_class(attributes)
@@ -148,9 +152,9 @@ module GlueGun
148
152
  begin
149
153
  service_instance = service_class.new(service_attributes)
150
154
  rescue StandardError => e
151
- ap %(Error building service object #{service_class}:)
152
- ap e.message
153
- ap e.backtrace
155
+ awesome_print %(Error building service object #{service_class}:)
156
+ awesome_print e.message
157
+ awesome_print e.backtrace
154
158
  raise e
155
159
  end
156
160
  instance_variable_set("@#{service_attribute_name}", service_instance)
@@ -159,8 +163,10 @@ module GlueGun
159
163
  def resolve_service_type(attributes, initializing = false)
160
164
  attrs = if initializing || !persisted? || attributes.key?(self.class.option_key)
161
165
  attributes
162
- else
166
+ elsif respond_to?(self.class.option_key)
163
167
  { self.class.option_key => send(self.class.option_key) }
168
+ else
169
+ { self.class.option_key => self.class.service_registry.default_key }
164
170
  end
165
171
  attrs[self.class.option_key] || self.class.service_registry.default_key
166
172
  end
@@ -211,6 +217,18 @@ module GlueGun
211
217
  end.symbolize_keys
212
218
  end
213
219
 
220
+ def serialize_object(object)
221
+ if object.respond_to?(:serialize)
222
+ object.serialize
223
+ elsif object.respond_to?(:attributes)
224
+ object.attributes.deep_compact
225
+ else
226
+ Hash[object.instance_variables.map do |var|
227
+ [var.to_s.delete("@"), object.instance_variable_get(var)]
228
+ end].deep_compact
229
+ end
230
+ end
231
+
214
232
  def serialize_dependency(dependency, dep_instance = nil)
215
233
  dep_instance = service_object.send(dependency) if dep_instance.nil?
216
234
  return nil unless dep_instance.present?
@@ -225,7 +243,7 @@ module GlueGun
225
243
  raise "Don't know how to serialize dependency of type #{dependency}, available options are #{opts.keys}. You didn't specify an option."
226
244
  end
227
245
 
228
- serialized = dep_instance.respond_to?(:serialize) ? dep_instance.serialize : dep_instance.attributes.deep_compact
246
+ serialized = serialize_object(dep_instance)
229
247
  {
230
248
  selected_option => serialized
231
249
  }
@@ -240,7 +258,7 @@ module GlueGun
240
258
  end
241
259
 
242
260
  def serialize_service_object
243
- attrs = service_object.respond_to?(:serialize) ? service_object.serialize : service_object.attributes.deep_compact
261
+ attrs = serialize_object(service_object)
244
262
  deps = allowed_names(service_object.dependency_definitions.keys).inject({}) do |hash, dep|
245
263
  hash.tap do
246
264
  serialized = serialize_dependency(dep)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GlueGun
4
- VERSION = "0.1.27"
4
+ VERSION = "0.1.29"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glue_gun_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.27
4
+ version: 0.1.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Shollenberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-24 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel