ucasy 0.0.3 → 0.0.4
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/ucasy/base.rb +8 -13
- data/lib/ucasy/callable.rb +7 -1
- data/lib/ucasy/validators/required_attributes.rb +16 -0
- data/lib/ucasy/version.rb +1 -1
- metadata +2 -3
- data/lib/ucasy/keyword_base.rb +0 -9
- data/lib/ucasy/positional_base.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67593caa8d99804e6a530e3407876287c836b2063d4c12bf3bb1e55f3ffb90c7
|
4
|
+
data.tar.gz: 7949ccfcb35f64041dd200650eadde71e3e4c88fa0ab6ca93bb9bb863bce0b5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac7c3e73fa889ef1ea92b7d9a2b02249ad049d79180366079eef7f0513c53836ec5cb6a89a5126382c27d78f26ffdc9648eeb186abb757d61bf606e2c5d35bea
|
7
|
+
data.tar.gz: f0c7713da0f80ed978df0b23e3f8c6ea380ba5fd693ac7cb13473447020df6be0a3f807552445c4225c911d7e4803297d927e801c0bb663539ac34d8ce1cb7a4
|
data/lib/ucasy/base.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require_relative "context"
|
2
2
|
require_relative "failure"
|
3
|
+
require_relative "validators/required_attributes"
|
3
4
|
|
4
5
|
module Ucasy
|
5
|
-
class Base
|
6
|
-
include Ucasy::Callable
|
7
|
-
|
6
|
+
class Base < Ucasy::Callable
|
8
7
|
class << self
|
9
8
|
def call(context)
|
10
9
|
new(context).perform
|
@@ -26,10 +25,10 @@ module Ucasy
|
|
26
25
|
def perform
|
27
26
|
return if failure?
|
28
27
|
|
29
|
-
|
30
|
-
before if
|
31
|
-
call
|
32
|
-
after if
|
28
|
+
validate_required_attributes!
|
29
|
+
try(:before) if success?
|
30
|
+
call if success?
|
31
|
+
try(:after) if success?
|
33
32
|
|
34
33
|
self
|
35
34
|
rescue Failure
|
@@ -40,12 +39,8 @@ module Ucasy
|
|
40
39
|
|
41
40
|
attr_reader :context
|
42
41
|
|
43
|
-
def
|
44
|
-
self.class._required_attributes
|
45
|
-
next if context.respond_to?(attribute)
|
46
|
-
|
47
|
-
raise ArgumentError, "You must set '#{attribute}' variable"
|
48
|
-
end
|
42
|
+
def validate_required_attributes!
|
43
|
+
Validators::RequiredAttributes.call(context, self.class._required_attributes)
|
49
44
|
end
|
50
45
|
|
51
46
|
def method_missing(method_name, *, &block)
|
data/lib/ucasy/callable.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ucasy::Validators
|
2
|
+
class RequiredAttributes < Ucasy::Callable
|
3
|
+
def initialize(context, required_attributes)
|
4
|
+
@context = context
|
5
|
+
@required_attributes = required_attributes
|
6
|
+
end
|
7
|
+
|
8
|
+
def call
|
9
|
+
@required_attributes.each do |attribute|
|
10
|
+
next if @context.respond_to?(attribute)
|
11
|
+
|
12
|
+
raise ArgumentError, "You must set '#{attribute}' variable in '#{self.class}'"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ucasy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucasy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lavenda Software
|
@@ -32,8 +32,7 @@ files:
|
|
32
32
|
- lib/ucasy/context.rb
|
33
33
|
- lib/ucasy/failure.rb
|
34
34
|
- lib/ucasy/flow.rb
|
35
|
-
- lib/ucasy/
|
36
|
-
- lib/ucasy/positional_base.rb
|
35
|
+
- lib/ucasy/validators/required_attributes.rb
|
37
36
|
- lib/ucasy/version.rb
|
38
37
|
- sig/ucasy/spec.rbs
|
39
38
|
- ucasy.gemspec
|
data/lib/ucasy/keyword_base.rb
DELETED