glue_gun_dsl 0.1.22 → 0.1.23
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/lib/glue_gun/core_ext/hash_extensions.rb +1 -1
- data/lib/glue_gun/dsl.rb +6 -6
- data/lib/glue_gun/model.rb +27 -4
- data/lib/glue_gun/shared.rb +8 -0
- data/lib/glue_gun/version.rb +1 -1
- metadata +17 -3
- data/lib/glue_gun/my_model.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e38dfcee3bde86f31b597d6dccf5138fb7200050a05904a055b7d8f201192ab0
|
4
|
+
data.tar.gz: 9b031f91fd59f57d8a10edef069d0ec656e04b8440d55af1354dda0cbfa124e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b25d5acc5cc955c9c3b20147c6bbf81c2911860f7e7f32b48b4f21273bf7c1f992f05c6b21ed2e6353b3ace8ac39023f87dcbd100fc9041731bea3a62b5bdf2b
|
7
|
+
data.tar.gz: 69736bb98acb9e1365879c0f68f7c401cc6b675e4c7c21af9fee87c0ea074dc76fc103413a386b5b76b1c8e44534f2c3e2f163ed2242389e14dc80fc7c02e923
|
data/lib/glue_gun/dsl.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require_relative "shared"
|
1
2
|
module GlueGun
|
2
3
|
module DSL
|
3
4
|
extend ActiveSupport::Concern
|
4
5
|
|
5
6
|
included do
|
7
|
+
include GlueGun::Shared
|
8
|
+
|
6
9
|
unless ancestors.include?(ActiveRecord::Base)
|
7
10
|
include ActiveModel::Model
|
8
11
|
include ActiveModel::Attributes
|
@@ -77,6 +80,8 @@ module GlueGun
|
|
77
80
|
end
|
78
81
|
|
79
82
|
module ClassMethods
|
83
|
+
extend GlueGun::Shared
|
84
|
+
|
80
85
|
DEFAULT_TYPE = if ActiveModel.version >= Gem::Version.new("7")
|
81
86
|
nil
|
82
87
|
elsif ActiveModel.version >= Gem::Version.new("5")
|
@@ -156,7 +161,7 @@ module GlueGun
|
|
156
161
|
end
|
157
162
|
|
158
163
|
def detect_root_dir
|
159
|
-
base_path = Module.const_source_location(name)&.first || ""
|
164
|
+
base_path = Module.const_source_location(self.class.name)&.first || ""
|
160
165
|
File.dirname(base_path)
|
161
166
|
end
|
162
167
|
end
|
@@ -165,11 +170,6 @@ module GlueGun
|
|
165
170
|
@initialized == true
|
166
171
|
end
|
167
172
|
|
168
|
-
def detect_root_dir
|
169
|
-
base_path = Module.const_source_location(self.class.name)&.first || ""
|
170
|
-
File.dirname(base_path)
|
171
|
-
end
|
172
|
-
|
173
173
|
def initialize_dependencies(attributes)
|
174
174
|
self.class.dependency_definitions.each do |component_type, definition|
|
175
175
|
value = attributes[component_type] || self.class.hardcoded_dependencies[component_type]
|
data/lib/glue_gun/model.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require_relative "shared"
|
1
2
|
module GlueGun
|
2
3
|
module Model
|
3
4
|
extend ActiveSupport::Concern
|
4
5
|
|
5
6
|
included do
|
7
|
+
include GlueGun::Shared
|
8
|
+
|
6
9
|
before_save :serialize_service_object
|
7
10
|
after_find :deserialize_service_object
|
8
11
|
|
@@ -32,7 +35,12 @@ module GlueGun
|
|
32
35
|
|
33
36
|
record = where(db_attributes).first_or_initialize(attributes)
|
34
37
|
|
35
|
-
|
38
|
+
if record.new_record?
|
39
|
+
record.save!
|
40
|
+
else
|
41
|
+
record.send(:build_service_object, attributes)
|
42
|
+
end
|
43
|
+
yield record if block_given?
|
36
44
|
|
37
45
|
record
|
38
46
|
end
|
@@ -44,7 +52,12 @@ module GlueGun
|
|
44
52
|
|
45
53
|
record = where(db_attributes).first_or_initialize(attributes)
|
46
54
|
|
47
|
-
|
55
|
+
if record.new_record?
|
56
|
+
record.save
|
57
|
+
else
|
58
|
+
record.send(:build_service_object, attributes)
|
59
|
+
end
|
60
|
+
yield record if block_given?
|
48
61
|
|
49
62
|
record
|
50
63
|
end
|
@@ -59,19 +72,29 @@ module GlueGun
|
|
59
72
|
end
|
60
73
|
|
61
74
|
def initialize(attributes = {})
|
75
|
+
attributes[:root_dir] = detect_root_dir
|
62
76
|
attributes = attributes.deep_symbolize_keys
|
63
77
|
db_attributes = self.class.extract_db_attributes(attributes)
|
64
78
|
super(db_attributes)
|
65
|
-
self.class.send(:attr_reader, service_attribute_name)
|
66
79
|
build_service_object(attributes)
|
67
80
|
end
|
68
81
|
|
69
82
|
private
|
70
83
|
|
71
84
|
def build_service_object(attributes)
|
85
|
+
self.class.send(:attr_reader, service_attribute_name)
|
72
86
|
service_class = resolve_service_class(attributes)
|
87
|
+
raise "Unable to find service class for #{self.class} given #{attributes}" unless service_class.present?
|
88
|
+
|
73
89
|
service_attributes = extract_service_attributes(attributes, service_class)
|
74
|
-
|
90
|
+
begin
|
91
|
+
service_instance = service_class.new(service_attributes)
|
92
|
+
rescue StandardError => e
|
93
|
+
ap %(Error building service object #{service_class}:)
|
94
|
+
ap e.message
|
95
|
+
ap e.backtrace
|
96
|
+
raise e
|
97
|
+
end
|
75
98
|
instance_variable_set("@#{service_attribute_name}", service_instance)
|
76
99
|
end
|
77
100
|
|
data/lib/glue_gun/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.23
|
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-
|
11
|
+
date: 2024-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -70,6 +70,20 @@ dependencies:
|
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '8'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: awesome_print
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
type: :runtime
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
73
87
|
- !ruby/object:Gem::Dependency
|
74
88
|
name: appraisal
|
75
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,7 +208,7 @@ files:
|
|
194
208
|
- lib/glue_gun/core_ext/hash_extensions.rb
|
195
209
|
- lib/glue_gun/dsl.rb
|
196
210
|
- lib/glue_gun/model.rb
|
197
|
-
- lib/glue_gun/
|
211
|
+
- lib/glue_gun/shared.rb
|
198
212
|
- lib/glue_gun/types.rb
|
199
213
|
- lib/glue_gun/types/array_type.rb
|
200
214
|
- lib/glue_gun/types/date_time_type.rb
|
data/lib/glue_gun/my_model.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
module EasyML
|
2
|
-
class Dataset < ActiveRecord::Base
|
3
|
-
before_save :serialize
|
4
|
-
after_find :deserialize
|
5
|
-
|
6
|
-
validates :name, presence: true
|
7
|
-
belongs_to :datasource,
|
8
|
-
foreign_key: :datasource_id,
|
9
|
-
class_name: "EasyML::Datasource"
|
10
|
-
|
11
|
-
def initialize(options = {})
|
12
|
-
super(EasyML::DbOptions.parse(options, self))
|
13
|
-
build_dataset_service(options)
|
14
|
-
end
|
15
|
-
|
16
|
-
attr_accessor :dataset_service
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def build_dataset_service(options)
|
21
|
-
options.deep_symbolize_keys!
|
22
|
-
service_klass = EasyML::Data::Dataset
|
23
|
-
|
24
|
-
allowed_attr_names = service_klass.dependency_definitions.keys.concat(
|
25
|
-
service_klass.attribute_definitions.keys
|
26
|
-
)
|
27
|
-
|
28
|
-
allowed_attrs = options.slice(*allowed_attr_names)
|
29
|
-
@dataset_service = service_klass.new(allowed_attrs)
|
30
|
-
define_dataset_service_delegators(allowed_attr_names)
|
31
|
-
end
|
32
|
-
|
33
|
-
def define_dataset_service_delegators(attr_names)
|
34
|
-
allowed_names(attr_names).each do |attr_name|
|
35
|
-
define_singleton_method(attr_name) do
|
36
|
-
dataset_service.send(attr_name)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def allowed_names(names)
|
42
|
-
assoc_names = self.class.reflect_on_all_associations.map(&:name)
|
43
|
-
[names.map(&:to_sym) - assoc_names.map(&:to_sym)].flatten
|
44
|
-
end
|
45
|
-
|
46
|
-
def serialize
|
47
|
-
attrs = dataset_service.attributes
|
48
|
-
deps = allowed_names(dataset_service.dependency_definitions.keys).inject({}) do |hash, dep|
|
49
|
-
hash.tap do
|
50
|
-
this_dep = dataset_service.send(dep)
|
51
|
-
next unless this_dep.present?
|
52
|
-
|
53
|
-
opts = dataset_service.dependency_definitions[dep].option_configs
|
54
|
-
selected_option = opts.detect do |_k, v|
|
55
|
-
this_dep.class == v.class_name
|
56
|
-
end.first
|
57
|
-
hash[dep] = {
|
58
|
-
selected_option => dataset_service.send(dep).attributes
|
59
|
-
}
|
60
|
-
end
|
61
|
-
end
|
62
|
-
json = attrs.merge(deps).deep_symbolize_keys.deep_compact
|
63
|
-
write_attribute(:configuration, json.to_json)
|
64
|
-
end
|
65
|
-
|
66
|
-
def deserialize
|
67
|
-
options = JSON.parse(read_attribute(:configuration))
|
68
|
-
options.deep_symbolize_keys!
|
69
|
-
|
70
|
-
build_dataset_service(options)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|