wolf_core 1.0.85 → 1.0.86

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: 4bf1687b51adb4d505140463475ebd50b00c54c5e809fbf4bb3981866847a265
4
- data.tar.gz: 35b32d6b4ade624eb07ced2b86db567fea77bdb502ebc110822f1874c9c49da5
3
+ metadata.gz: c81a077657054ee1653188910f9843979df9e9b8fef277427b2ef6191b53825c
4
+ data.tar.gz: 23de16a0ee4e5c14823ba600beecd21343b93c0d09c16a5bd2fd22a9d4b19bc0
5
5
  SHA512:
6
- metadata.gz: 94841588033bbb2962822c4c7b11c0c5fb10930b30bd3947d208bba73f283d63e0be4a46a4d6b8d6aa5fae70b551670b92c5d2c9faa259cfea6b15f30e473210
7
- data.tar.gz: 778338dabcdfa8447f5f2ac1d4f1af45d0c264d5755adad61a8c7cb679c7c555da014fb1ea03c9fa811450c487c2df2c5883119fd5f1bbdac3cab652d830642b
6
+ metadata.gz: fac822154372b8d46780147384d36d92e93d90809989236578c534895330c03f9a99087e730483de6d45f4a3fa7bd09860515f1a7de87de4489427f9c5f1a0aa
7
+ data.tar.gz: 0d3cf005b0d0579ba5366e05b2fc60556a889d7aacb28fd5f16cb3846111656f5aa290c81dadc6afe4675b807e519d0fe5f8151b26680dd4f03974c4b836cf2d
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WolfCore
4
+ class DomainObject
5
+ include ActiveModel::Model
6
+ include ActiveModel::Serializers::JSON
7
+ include ActiveModel::Dirty
8
+ include ActiveModel::Callbacks
9
+
10
+ define_model_callbacks :initialize, only: [:after, :before]
11
+ delegate :[], to: :attributes
12
+
13
+ class_attribute :fields, default: []
14
+
15
+ def self.define_attributes(*attributes)
16
+ self.fields += attributes
17
+
18
+ attr_accessor(*attributes)
19
+
20
+ define_attribute_methods(*attributes)
21
+
22
+ attributes.each do |attribute|
23
+ define_method(:"#{attribute}=") do |value|
24
+ send(:"#{attribute}_will_change!") unless value == send(attribute)
25
+ instance_variable_set(:"@#{attribute}", value)
26
+ valid?
27
+ value
28
+ end
29
+ end
30
+ end
31
+
32
+ def self.create_all(objects)
33
+ success_key = extract_success_key(objects.first)
34
+ final_array = []
35
+ objects.each do |object|
36
+ result = create(object)
37
+ if result.failure?
38
+ return result
39
+ else
40
+ final_array << result.data[success_key.to_sym]
41
+ end
42
+ end
43
+ Result.success(data: { success_key.pluralize.to_s => final_array })
44
+ end
45
+
46
+ def self.create(params = {}, **kwargs)
47
+ params = {} unless params.is_a?(Hash)
48
+ params = params.merge(kwargs)
49
+ object = self.new(parse_params(params))
50
+ object.reset_changes
51
+ if object.valid?
52
+ success_key = extract_success_key(object)
53
+ Result.success(data: { success_key => object })
54
+ else
55
+ Result.failure(error: { message: object.errors.full_messages.to_sentence })
56
+ end
57
+ rescue ActiveModel::UnknownAttributeError => e
58
+ Result.failure(error: { message: e.message, error_type: e.class.to_s })
59
+ end
60
+
61
+ def self.extract_success_key(object)
62
+ object.class.to_s.split('::').last.underscore
63
+ end
64
+
65
+ def self.parse_params(params)
66
+ (params.to_h).with_indifferent_access
67
+ end
68
+
69
+ def initialize(attributes = {})
70
+ run_callbacks :initialize do
71
+ super
72
+ end
73
+ end
74
+
75
+ def attributes
76
+ instance_values.slice(*self.class.fields.map(&:to_s)).with_indifferent_access
77
+ end
78
+
79
+ def reset_changes
80
+ self.changes_applied
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'domain_object'
4
+
5
+ module WolfCore
6
+ class Entity < DomainObject
7
+ define_attributes :id
8
+ validates :id, presence: true
9
+
10
+ define_model_callbacks :validation, only: [:after, :before]
11
+
12
+ after_initialize do
13
+ @id ||= generate_id
14
+ end
15
+
16
+ def valid?(*args)
17
+ run_callbacks(:validation) do
18
+ super
19
+ end
20
+ end
21
+
22
+ def ==(other)
23
+ id == other.id
24
+ end
25
+
26
+ def created_at
27
+ return if id.blank?
28
+
29
+ timestamp = id.split('-')[1].to_i
30
+ @created_at ||= Time.at(timestamp).utc
31
+ end
32
+
33
+ private
34
+
35
+ def generate_id
36
+ prefix = self.class.to_s.underscore.split('/').last.downcase[0..4]
37
+ timestamp = Time.now.utc.to_i
38
+ uuid = SecureRandom.uuid.delete('-')[0..9]
39
+ "#{prefix}-#{timestamp}-#{uuid}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'domain_object'
4
+
5
+ module WolfCore
6
+ class ValueObject < DomainObject
7
+ def ==(other)
8
+ return false unless other.is_a?(self.class)
9
+ self.class.fields.each do |key|
10
+ return false unless attributes[key] == other.attributes[key]
11
+ end
12
+ true
13
+ end
14
+ end
15
+ end
@@ -15,7 +15,7 @@ module WolfCore
15
15
  safe_require(files_to_require)
16
16
  end
17
17
 
18
- def safe_require(missing_files) # rubocop:disable Metrics/MethodLength
18
+ def safe_require(missing_files)
19
19
  error_counter = {}
20
20
  while missing_files.any?
21
21
  files_to_require = missing_files
@@ -28,6 +28,7 @@ module WolfCore
28
28
  if error_counter[file] >= 10
29
29
  log_object "Error requiring file: #{file}"
30
30
  log_object e, title: "Error is"
31
+ log_object e.backtrace, title: "Error backtrace is"
31
32
  end
32
33
  missing_files << file if error_counter[file] < 15
33
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.0.85"
4
+ VERSION = "1.0.86"
5
5
  end
data/lib/wolf_core.rb CHANGED
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'ostruct'
5
5
  require 'httparty'
6
6
  require 'active_support'
7
+ require 'active_model'
7
8
  require 'active_support/core_ext'
8
9
  require 'aws-sdk-lambda'
9
10
  require 'redis'
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.85
4
+ version: 1.0.86
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-07 00:00:00.000000000 Z
11
+ date: 2025-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activemodel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Repository to store shared code among Ruby projects.
98
112
  email:
99
113
  - jroncallo96@gmail.com
@@ -119,6 +133,9 @@ files:
119
133
  - lib/wolf_core/application/integrations/webhooks_operations.rb
120
134
  - lib/wolf_core/application/salesforce_oauth_service.rb
121
135
  - lib/wolf_core/application/service_exception.rb
136
+ - lib/wolf_core/domain/domain_object.rb
137
+ - lib/wolf_core/domain/entity.rb
138
+ - lib/wolf_core/domain/value_object.rb
122
139
  - lib/wolf_core/infrastructure/fkm_operations.rb
123
140
  - lib/wolf_core/infrastructure/http_data_source.rb
124
141
  - lib/wolf_core/infrastructure/http_operations.rb