ucasy 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70419e05c271d22afe46d15e1240acd4aabf448afe0a1a48d777021cdbf34436
4
- data.tar.gz: ff6993e059cae6ba5d9b5c308b3bb3655865a2a1470f824beaefbec17e075ad3
3
+ metadata.gz: 67593caa8d99804e6a530e3407876287c836b2063d4c12bf3bb1e55f3ffb90c7
4
+ data.tar.gz: 7949ccfcb35f64041dd200650eadde71e3e4c88fa0ab6ca93bb9bb863bce0b5d
5
5
  SHA512:
6
- metadata.gz: 6cb72b1bf8058f627118163f05d466bc4aecbcf283e4adfbdbbd7f6040f1e8aa96b207c5b65cd9a1752ff4998056d71ffbaeb21df4cbed831614a6dd4698b6f3
7
- data.tar.gz: 6d95bbe0e815efa7a45b71de34a026a3735f41d90c3a2a4cf7add330be44abb8385d95435b08ec44de4e9104fa3b0fb9e6fcbd383c7d9e9740c95b97fc89b769
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
- validate_context!
30
- before if respond_to?(:before)
31
- call
32
- after if respond_to?(:after)
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 validate_context!
44
- self.class._required_attributes.each do |attribute|
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)
@@ -1,5 +1,11 @@
1
1
  module Ucasy
2
- module Callable
2
+ class Callable
3
+ class << self
4
+ def call(...)
5
+ new(...).call
6
+ end
7
+ end
8
+
3
9
  def call
4
10
  raise NotImplementedError, "You must implement call method"
5
11
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Ucasy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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/keyword_base.rb
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
@@ -1,9 +0,0 @@
1
- module Ucasy
2
- class KeywordBase
3
- include Ucasy::Callable
4
-
5
- def self.call(**)
6
- new(**).call
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Ucasy
2
- class PositionalBase
3
- include Ucasy::Callable
4
-
5
- def self.call(*)
6
- new(*).call
7
- end
8
- end
9
- end