jaso 0.1.1 → 0.2.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/jaso/attributable.rb +11 -15
- data/lib/jaso/callable.rb +10 -4
- data/lib/jaso/configurable.rb +30 -0
- data/lib/jaso/core.rb +13 -13
- data/lib/jaso/validator/active_model.rb +12 -0
- data/lib/jaso/version.rb +1 -1
- data/lib/jaso.rb +1 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35d01ca5f14dca4e5668a1d06169548adb6534bf4d9f6437f51d89b5a35488e7
|
4
|
+
data.tar.gz: bdb921465c8970455c939ff00fe626f74dd49ee6a64b0f235aa831f458d94640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f593f93fa46fa6e9d0d1826970a7c2b263d65c7c9b836b00ba78b727c8bca84d42f444acc59f197b88f685bc093116cb6db89a6549847dc4934ad5c51c8966d
|
7
|
+
data.tar.gz: 176f2201ad1bceac240660828ba4e5c9d134cb925d94badb356ac0ba6a3b7b1e0a09066b747500d3329d223006efe526e31f470c731932c4216f99e8a5041d71
|
data/CHANGELOG.md
CHANGED
data/lib/jaso/attributable.rb
CHANGED
@@ -7,38 +7,34 @@ module Jaso::Attributable
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
-
|
11
|
-
|
12
|
-
def attributes
|
13
|
-
@attributes ||= {}
|
10
|
+
def __attributes
|
11
|
+
@__attributes ||= {}
|
14
12
|
end
|
15
13
|
|
16
14
|
def attribute(name, **options)
|
17
|
-
|
18
|
-
private define_method(name) {
|
15
|
+
__attributes[name] = options
|
16
|
+
private define_method(name) { __attributes[name] }
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
20
|
module PrependMethods
|
23
21
|
def __call
|
24
|
-
|
22
|
+
__assign_attributes
|
25
23
|
super
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
def attributes
|
32
|
-
@attributes ||= {}
|
27
|
+
def __attributes
|
28
|
+
@__attributes ||= {}
|
33
29
|
end
|
34
30
|
|
35
|
-
def
|
36
|
-
self.class.
|
37
|
-
input = @
|
31
|
+
def __assign_attributes
|
32
|
+
self.class.__attributes.each do |name, options|
|
33
|
+
input = @__inputs[name]
|
38
34
|
default = options[:default]
|
39
35
|
transform = options[:transform]
|
40
36
|
|
41
|
-
|
37
|
+
__attributes[name] = if @__inputs.key?(name)
|
42
38
|
transform.is_a?(Proc) ? transform.call(input) : input
|
43
39
|
else
|
44
40
|
default.is_a?(Proc) ? default.call : default
|
data/lib/jaso/callable.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
module Jaso::Callable
|
4
4
|
def self.included(base)
|
5
5
|
base.extend(ClassMethods)
|
6
|
-
base.private_class_method :new
|
7
6
|
end
|
8
7
|
|
9
8
|
module ClassMethods
|
@@ -12,12 +11,19 @@ module Jaso::Callable
|
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
# Must be overwritten by subclass
|
15
|
+
def call
|
16
|
+
end
|
17
|
+
|
18
|
+
# Must be overwritten by validator
|
19
|
+
def __validate!
|
20
|
+
end
|
16
21
|
|
17
22
|
def __call
|
23
|
+
__validate!
|
18
24
|
call
|
19
25
|
raise Jaso::NotFinished
|
20
|
-
rescue Jaso::Finished =>
|
21
|
-
|
26
|
+
rescue Jaso::Finished => finished
|
27
|
+
finished.result
|
22
28
|
end
|
23
29
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jaso::Configurable
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :validator
|
6
|
+
|
7
|
+
def validator=(validator)
|
8
|
+
raise ArgumentError, "#{validator} is not a Jaso::Validator" unless validator_defined?(validator)
|
9
|
+
@validator = validator
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def validator_defined?(validator)
|
15
|
+
validator.instance_of?(Module) && validator.to_s.start_with?("Jaso::Validator::")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def configuration
|
20
|
+
@configuration ||= Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure
|
24
|
+
yield(configuration)
|
25
|
+
end
|
26
|
+
|
27
|
+
def inherited(base)
|
28
|
+
base.include(configuration.validator) if configuration.validator
|
29
|
+
end
|
30
|
+
end
|
data/lib/jaso/core.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "attributable"
|
4
|
-
require_relative "callable"
|
5
|
-
require_relative "finished"
|
6
|
-
require_relative "not_finished"
|
7
|
-
require_relative "result"
|
8
|
-
|
9
3
|
module Jaso::Core
|
4
|
+
require_relative "attributable"
|
5
|
+
require_relative "callable"
|
6
|
+
require_relative "configurable"
|
7
|
+
require_relative "finished"
|
8
|
+
require_relative "not_finished"
|
9
|
+
require_relative "result"
|
10
|
+
|
11
|
+
require_relative "validator/active_model"
|
12
|
+
|
10
13
|
def self.included(base)
|
11
14
|
base.include(Jaso::Attributable)
|
12
15
|
base.include(Jaso::Callable)
|
13
|
-
|
16
|
+
base.extend(Jaso::Configurable)
|
14
17
|
|
15
|
-
|
16
|
-
@inputs = inputs
|
18
|
+
base.private_class_method :new
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
def initialize(inputs = {})
|
22
|
+
@__inputs = inputs
|
21
23
|
end
|
22
24
|
|
23
|
-
private
|
24
|
-
|
25
25
|
def success!(**data)
|
26
26
|
result = Jaso::Result.new(Jaso::Result::SUCCESS, data)
|
27
27
|
raise Jaso::Finished, result
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jaso::Validator
|
4
|
+
module ActiveModel
|
5
|
+
def self.included(base)
|
6
|
+
require "active_model"
|
7
|
+
base.include(::ActiveModel::Validations)
|
8
|
+
base.define_method(:__validate!) { failure!(errors: errors) if invalid? }
|
9
|
+
rescue LoadError
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/jaso/version.rb
CHANGED
data/lib/jaso.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jaso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinicius Meneses
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -108,10 +108,12 @@ files:
|
|
108
108
|
- lib/jaso.rb
|
109
109
|
- lib/jaso/attributable.rb
|
110
110
|
- lib/jaso/callable.rb
|
111
|
+
- lib/jaso/configurable.rb
|
111
112
|
- lib/jaso/core.rb
|
112
113
|
- lib/jaso/finished.rb
|
113
114
|
- lib/jaso/not_finished.rb
|
114
115
|
- lib/jaso/result.rb
|
116
|
+
- lib/jaso/validator/active_model.rb
|
115
117
|
- lib/jaso/version.rb
|
116
118
|
homepage: https://github.com/viniciusmeneses/jaso
|
117
119
|
licenses:
|
@@ -137,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
- !ruby/object:Gem::Version
|
138
140
|
version: '0'
|
139
141
|
requirements: []
|
140
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.0.8
|
141
143
|
signing_key:
|
142
144
|
specification_version: 4
|
143
145
|
summary: Just Another Service Object
|