wolf_core 1.0.86 → 1.0.88
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c9b18a3bc27663bbadcfb5d14982424574280b16346fd93a63edee396425b44
|
4
|
+
data.tar.gz: 7ab5549f523329749819b6ac450d3880bb022c0f6d555b81f919b7ddbbda3214
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 236260ec58fd951be549cacd1fcf1d326ea5698d50b78fa4a9dd89f1f6382825a3ce9a35518576f8a59ffa076769e823e6dbb75794de6f4026bbabefbf2c56d1
|
7
|
+
data.tar.gz: 7598d705a89daabc408cc9e3b96ad0624f2cdfbe3df5173ddd9f36e196c751786c49340f04f45128f86afaa0d1ae8ce13b932917a249d9dbcca3258bc2d6c995
|
@@ -3,12 +3,21 @@
|
|
3
3
|
module WolfCore
|
4
4
|
class DomainObject
|
5
5
|
include ActiveModel::Model
|
6
|
-
include ActiveModel::Serializers::JSON
|
6
|
+
# include ActiveModel::Serializers::JSON
|
7
7
|
include ActiveModel::Dirty
|
8
8
|
include ActiveModel::Callbacks
|
9
9
|
|
10
10
|
define_model_callbacks :initialize, only: [:after, :before]
|
11
|
-
|
11
|
+
define_model_callbacks :validation, only: [:after, :before]
|
12
|
+
define_model_callbacks :attribute_change, only: [:after, :before]
|
13
|
+
|
14
|
+
after_initialize do
|
15
|
+
parse_attributes
|
16
|
+
end
|
17
|
+
|
18
|
+
after_attribute_change do
|
19
|
+
parse_attributes
|
20
|
+
end
|
12
21
|
|
13
22
|
class_attribute :fields, default: []
|
14
23
|
|
@@ -22,15 +31,30 @@ module WolfCore
|
|
22
31
|
attributes.each do |attribute|
|
23
32
|
define_method(:"#{attribute}=") do |value|
|
24
33
|
send(:"#{attribute}_will_change!") unless value == send(attribute)
|
25
|
-
|
26
|
-
|
34
|
+
run_callbacks :attribute_change do
|
35
|
+
instance_variable_set(:"@#{attribute}", value)
|
36
|
+
end
|
27
37
|
value
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
42
|
+
def self.cast_all(objects)
|
43
|
+
objects.map { |object| cast(object) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.cast(object)
|
47
|
+
if object.is_a?(self)
|
48
|
+
object
|
49
|
+
else
|
50
|
+
result = self.create(object)
|
51
|
+
success_key = extract_success_key
|
52
|
+
result.success? ? result.data.send(success_key) : object
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
32
56
|
def self.create_all(objects)
|
33
|
-
success_key = extract_success_key
|
57
|
+
success_key = extract_success_key
|
34
58
|
final_array = []
|
35
59
|
objects.each do |object|
|
36
60
|
result = create(object)
|
@@ -44,12 +68,10 @@ module WolfCore
|
|
44
68
|
end
|
45
69
|
|
46
70
|
def self.create(params = {}, **kwargs)
|
47
|
-
|
48
|
-
params = params.merge(kwargs)
|
49
|
-
object = self.new(parse_params(params))
|
71
|
+
object = self.new(parse_params(params, **kwargs))
|
50
72
|
object.reset_changes
|
51
73
|
if object.valid?
|
52
|
-
success_key = extract_success_key
|
74
|
+
success_key = extract_success_key
|
53
75
|
Result.success(data: { success_key => object })
|
54
76
|
else
|
55
77
|
Result.failure(error: { message: object.errors.full_messages.to_sentence })
|
@@ -58,11 +80,13 @@ module WolfCore
|
|
58
80
|
Result.failure(error: { message: e.message, error_type: e.class.to_s })
|
59
81
|
end
|
60
82
|
|
61
|
-
def self.extract_success_key
|
62
|
-
|
83
|
+
def self.extract_success_key
|
84
|
+
self.to_s.split('::').last.underscore
|
63
85
|
end
|
64
86
|
|
65
|
-
def self.parse_params(params)
|
87
|
+
def self.parse_params(params = {}, **kwargs)
|
88
|
+
params = {} unless params.is_a?(Hash)
|
89
|
+
params = params.merge(kwargs)
|
66
90
|
(params.to_h).with_indifferent_access
|
67
91
|
end
|
68
92
|
|
@@ -72,12 +96,27 @@ module WolfCore
|
|
72
96
|
end
|
73
97
|
end
|
74
98
|
|
99
|
+
def valid?(*args)
|
100
|
+
run_callbacks(:validation) do
|
101
|
+
super
|
102
|
+
end
|
103
|
+
errors.empty?
|
104
|
+
end
|
105
|
+
|
75
106
|
def attributes
|
76
107
|
instance_values.slice(*self.class.fields.map(&:to_s)).with_indifferent_access
|
77
108
|
end
|
78
109
|
|
110
|
+
def attributes=(attrs)
|
111
|
+
run_callbacks :attribute_change do
|
112
|
+
super
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
79
116
|
def reset_changes
|
80
117
|
self.changes_applied
|
81
118
|
end
|
119
|
+
|
120
|
+
def parse_attributes; end
|
82
121
|
end
|
83
122
|
end
|
@@ -1,24 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'domain_object'
|
4
|
-
|
5
3
|
module WolfCore
|
6
4
|
class Entity < DomainObject
|
7
5
|
define_attributes :id
|
8
6
|
validates :id, presence: true
|
9
7
|
|
10
|
-
define_model_callbacks :validation, only: [:after, :before]
|
11
|
-
|
12
8
|
after_initialize do
|
13
9
|
@id ||= generate_id
|
14
10
|
end
|
15
11
|
|
16
|
-
def valid?(*args)
|
17
|
-
run_callbacks(:validation) do
|
18
|
-
super
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
12
|
def ==(other)
|
23
13
|
id == other.id
|
24
14
|
end
|
data/lib/wolf_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wolf_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.88
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Roncallo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/wolf_core/domain/domain_object.rb
|
137
137
|
- lib/wolf_core/domain/entity.rb
|
138
138
|
- lib/wolf_core/domain/value_object.rb
|
139
|
+
- lib/wolf_core/infrastructure/application_repository.rb
|
139
140
|
- lib/wolf_core/infrastructure/fkm_operations.rb
|
140
141
|
- lib/wolf_core/infrastructure/http_data_source.rb
|
141
142
|
- lib/wolf_core/infrastructure/http_operations.rb
|