iprog_base 0.1.0
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 +7 -0
- data/lib/iprog/base.rb +93 -0
- data/lib/iprog/version.rb +3 -0
- data/lib/iprog_base.rb +2 -0
- metadata +51 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b5b60b075b0af0667872c51f4fe6cb8dc91751de5ff1805723af73d8c577b848
|
|
4
|
+
data.tar.gz: 85701bfd87a2b11762d56015c3555bbd44ff67486f0148276299ede50ca2fed5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 70a8f1191228a3a4ac1a0251ffbe03de1a4f2ed0244023e3e089526bf0254c95cdfb8d0ab13ecb6c324c361f9e243114cea11c6aba123af4d2f08a82494f5323
|
|
7
|
+
data.tar.gz: 55888ad8c028aa5ed20fa242291ab7565de3e51698dab25d92d0acc6324d31c5798a5ee119ba7c2ab4606df36ffb6f97a2109ad77f4142c6818099717d33bd30
|
data/lib/iprog/base.rb
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module Iprog
|
|
2
|
+
class Error < StandardError; end
|
|
3
|
+
|
|
4
|
+
# The core base class for command/service objects using the Template Method Pattern.
|
|
5
|
+
# Override `process_data`, `check_errors`, and other hooks to build reusable logic.
|
|
6
|
+
class Base
|
|
7
|
+
attr_writer :data
|
|
8
|
+
attr_reader :result, :errors, :params
|
|
9
|
+
|
|
10
|
+
def self.call(*args, **kwargs)
|
|
11
|
+
if kwargs.any?
|
|
12
|
+
new(**kwargs).call
|
|
13
|
+
elsif args.length == 1 && args.first.is_a?(Hash)
|
|
14
|
+
new(**args.first).call
|
|
15
|
+
else
|
|
16
|
+
raise ArgumentError, "❌ Expected keyword args or a single hash"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def initialize(**kwargs)
|
|
21
|
+
@params = kwargs.transform_keys(&:to_sym)
|
|
22
|
+
@data = {}
|
|
23
|
+
|
|
24
|
+
set_params_data
|
|
25
|
+
set_static_data
|
|
26
|
+
extract_and_initialize_instance_variables
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def call
|
|
30
|
+
check_errors
|
|
31
|
+
return self if errors?
|
|
32
|
+
|
|
33
|
+
process_data
|
|
34
|
+
send_result filtered_response
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def process_data
|
|
38
|
+
{}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def filtered_response
|
|
42
|
+
filtered_fields.any? ? result_data.slice(*filtered_fields) : result_data
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def filtered_fields
|
|
46
|
+
[]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def check_errors
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def set(key, value)
|
|
54
|
+
result_data[key] = value
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def result_data
|
|
58
|
+
@data
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def set_params_data
|
|
62
|
+
{}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def set_static_data
|
|
66
|
+
{}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def extract_and_initialize_instance_variables
|
|
70
|
+
result_data.each do |key, value|
|
|
71
|
+
instance_variable_set("@#{key}", value)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def success?
|
|
76
|
+
errors.nil?
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def errors?
|
|
80
|
+
!errors.nil?
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def send_result(data)
|
|
84
|
+
@result = data || []
|
|
85
|
+
self
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def send_error(data)
|
|
89
|
+
@errors = data || []
|
|
90
|
+
self
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
data/lib/iprog_base.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: iprog_base
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jayson Presto
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Provides a reusable, extensible base class for service or command objects
|
|
13
|
+
in Ruby applications, following the Template Method Pattern. Includes lifecycle
|
|
14
|
+
hooks for parameter handling, static data setup, error checking, data processing,
|
|
15
|
+
and response filtering. Designed for clean, maintainable, and testable business
|
|
16
|
+
logic.
|
|
17
|
+
email:
|
|
18
|
+
- jaysonpresto.iprog21@gmail.com
|
|
19
|
+
executables: []
|
|
20
|
+
extensions: []
|
|
21
|
+
extra_rdoc_files: []
|
|
22
|
+
files:
|
|
23
|
+
- lib/iprog/base.rb
|
|
24
|
+
- lib/iprog/version.rb
|
|
25
|
+
- lib/iprog_base.rb
|
|
26
|
+
homepage: https://iprogtech.com/
|
|
27
|
+
licenses:
|
|
28
|
+
- MIT
|
|
29
|
+
metadata:
|
|
30
|
+
homepage_uri: https://iprogtech.com/
|
|
31
|
+
source_code_uri: https://github.com/iprog21/iprog_base.git
|
|
32
|
+
changelog_uri: https://github.com/iprog21/iprog_base/blob/master/CHANGELOG.md
|
|
33
|
+
code_of_conduct_uri: https://github.com/iprog21/iprog_base/blob/main/CODE_OF_CONDUCT.md
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubygems_version: 3.7.0
|
|
49
|
+
specification_version: 4
|
|
50
|
+
summary: Base service/command class using the Template Method Pattern.
|
|
51
|
+
test_files: []
|