action_logic 0.1.0 → 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/Gemfile.lock +1 -1
- data/README.md +14 -14
- data/lib/action_logic/action_validation.rb +2 -13
- data/lib/action_logic/version.rb +1 -1
- data/spec/fixtures/constants.rb +10 -10
- data/spec/fixtures/coordinators.rb +1 -1
- data/spec/fixtures/tasks.rb +5 -5
- data/spec/fixtures/use_cases.rb +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46629f7e8b78b79da65d73f694f03ffd3598a836
|
4
|
+
data.tar.gz: e7cd5893f3661781d40ed6050a10067e31d4df3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a81e6790403bb1611887adc70072541414c8df853cbfae06474eeb6bcb4d481ba17fb29c8b79be8352e155dd554b455f164ad472cfdabdd84b7431ccac35f9a2
|
7
|
+
data.tar.gz: 561ca45352089282b7a036013799664efc7787fd80f1b38adb7df8d522ee1ae8a72b6ed7c22d49ffa3a6a24490f3575adb422bd15c72a85478c92b17ed249586
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -483,20 +483,20 @@ to expirement and play with the flexibility provided to you by `ActionContext` i
|
|
483
483
|
```ruby
|
484
484
|
class RailsControllerExample < ApplicationController
|
485
485
|
def create
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
486
|
+
case create_use_case.status
|
487
|
+
when :disposition_1 then ActionUseCaseSuccess1.execute(create_use_case)
|
488
|
+
when :disposition_2 then ActionUseCaseSuccess2.execute(create_use_case)
|
489
|
+
when :disposition_9 then ActionUseCaseFailure.execute(create_use_case)
|
490
|
+
else
|
491
|
+
ActionUseCaseDefault.execute(create_use_case)
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
private
|
496
|
+
|
497
|
+
def create_use_case
|
498
|
+
@create_use_case ||= ActionUseCaseExample.execute(params)
|
499
|
+
end
|
500
500
|
end
|
501
501
|
```
|
502
502
|
|
@@ -68,8 +68,8 @@ module ActionLogic
|
|
68
68
|
type_errors = validations.reduce([]) do |collection, (expected_attribute, expected_validation)|
|
69
69
|
next unless expected_validation[:type]
|
70
70
|
|
71
|
-
if
|
72
|
-
collection << "Attribute: #{expected_attribute} with value: #{context.to_h[expected_attribute]} was expected to be of type #{expected_validation[:type]} but is #{
|
71
|
+
if context.to_h[expected_attribute].class != expected_validation[:type]
|
72
|
+
collection << "Attribute: #{expected_attribute} with value: #{context.to_h[expected_attribute]} was expected to be of type #{expected_validation[:type]} but is #{context.to_h[expected_attribute].class}"
|
73
73
|
end
|
74
74
|
collection
|
75
75
|
end
|
@@ -96,16 +96,5 @@ module ActionLogic
|
|
96
96
|
|
97
97
|
raise ActionLogic::PresenceError.new(presence_errors) if presence_errors.any?
|
98
98
|
end
|
99
|
-
|
100
|
-
def type_to_sym(value)
|
101
|
-
case value.class.name.downcase.to_sym
|
102
|
-
when :fixnum then :integer
|
103
|
-
when :falseclass then :boolean
|
104
|
-
when :trueclass then :boolean
|
105
|
-
when :nilclass then :nil
|
106
|
-
else
|
107
|
-
value.class.name.downcase.to_sym
|
108
|
-
end
|
109
|
-
end
|
110
99
|
end
|
111
100
|
end
|
data/lib/action_logic/version.rb
CHANGED
data/spec/fixtures/constants.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'fixtures/custom_types'
|
2
2
|
|
3
3
|
class Constants
|
4
|
-
ALL_VALIDATIONS = { :integer_test => { :type =>
|
5
|
-
:float_test => { :type =>
|
6
|
-
:string_test => { :type =>
|
7
|
-
:bool_test => { :type =>
|
8
|
-
:hash_test => { :type =>
|
9
|
-
:array_test => { :type =>
|
10
|
-
:symbol_test => { :type =>
|
11
|
-
:nil_test => { :type =>
|
4
|
+
ALL_VALIDATIONS = { :integer_test => { :type => Fixnum, :presence => true },
|
5
|
+
:float_test => { :type => Float, :presence => true },
|
6
|
+
:string_test => { :type => String, :presence => true },
|
7
|
+
:bool_test => { :type => TrueClass, :presence => true },
|
8
|
+
:hash_test => { :type => Hash, :presence => true },
|
9
|
+
:array_test => { :type => Array, :presence => true },
|
10
|
+
:symbol_test => { :type => Symbol, :presence => true },
|
11
|
+
:nil_test => { :type => NilClass } }
|
12
12
|
|
13
13
|
INVALID_ATTRIBUTES = { :integer_test => nil,
|
14
14
|
:float_test => nil,
|
@@ -28,11 +28,11 @@ class Constants
|
|
28
28
|
:symbol_test => :symbol,
|
29
29
|
:nil_test => nil }
|
30
30
|
|
31
|
-
CUSTOM_TYPE_VALIDATION1 = { :custom_type => { :type =>
|
31
|
+
CUSTOM_TYPE_VALIDATION1 = { :custom_type => { :type => CustomType1, :presence => true } }
|
32
32
|
|
33
33
|
CUSTOM_TYPE_ATTRIBUTES1 = { :custom_type => CustomType1.new }
|
34
34
|
|
35
|
-
CUSTOM_TYPE_VALIDATION2 = { :custom_type => { :type =>
|
35
|
+
CUSTOM_TYPE_VALIDATION2 = { :custom_type => { :type => CustomType2, :presence => true } }
|
36
36
|
|
37
37
|
CUSTOM_TYPE_ATTRIBUTES2 = { :custom_type => CustomType2.new }
|
38
38
|
|
@@ -161,7 +161,7 @@ class ValidateAfterTestCoordinator
|
|
161
161
|
context.integer_test = 1
|
162
162
|
context.float_test = 1.0
|
163
163
|
context.string_test = "string"
|
164
|
-
context.bool_test =
|
164
|
+
context.bool_test = true
|
165
165
|
context.hash_test = {}
|
166
166
|
context.array_test = []
|
167
167
|
context.symbol_test = :symbol
|
data/spec/fixtures/tasks.rb
CHANGED
@@ -22,7 +22,7 @@ end
|
|
22
22
|
class ValidateAroundCustomTypeTestTask
|
23
23
|
include ActionLogic::ActionTask
|
24
24
|
|
25
|
-
validates_around :custom_type => { :type =>
|
25
|
+
validates_around :custom_type => { :type => CustomType1, :presence => true }
|
26
26
|
|
27
27
|
def call
|
28
28
|
end
|
@@ -71,7 +71,7 @@ end
|
|
71
71
|
class ValidateBeforeCustomTypeTestTask
|
72
72
|
include ActionLogic::ActionTask
|
73
73
|
|
74
|
-
validates_before :custom_type => { :type =>
|
74
|
+
validates_before :custom_type => { :type => CustomType1, :presence => true }
|
75
75
|
|
76
76
|
def call
|
77
77
|
end
|
@@ -117,7 +117,7 @@ class ValidateAfterTestTask
|
|
117
117
|
context.integer_test = 1
|
118
118
|
context.float_test = 1.0
|
119
119
|
context.string_test = "string"
|
120
|
-
context.bool_test =
|
120
|
+
context.bool_test = true
|
121
121
|
context.hash_test = {}
|
122
122
|
context.array_test = []
|
123
123
|
context.symbol_test = :symbol
|
@@ -154,7 +154,7 @@ end
|
|
154
154
|
class ValidateAfterCustomTypeTestTask
|
155
155
|
include ActionLogic::ActionTask
|
156
156
|
|
157
|
-
validates_after :custom_type => { :type =>
|
157
|
+
validates_after :custom_type => { :type => CustomType1, :presence => true }
|
158
158
|
|
159
159
|
def call
|
160
160
|
context.custom_type = CustomType1.new
|
@@ -164,7 +164,7 @@ end
|
|
164
164
|
class ValidateAfterInvalidCustomTypeTestTask
|
165
165
|
include ActionLogic::ActionTask
|
166
166
|
|
167
|
-
validates_after :custom_type => { :type =>
|
167
|
+
validates_after :custom_type => { :type => CustomType2, :presence => true }
|
168
168
|
|
169
169
|
def call
|
170
170
|
context.custom_type = CustomType1.new
|
data/spec/fixtures/use_cases.rb
CHANGED
@@ -65,7 +65,7 @@ end
|
|
65
65
|
class ValidateAroundCustomTypeTestUseCase
|
66
66
|
include ActionLogic::ActionUseCase
|
67
67
|
|
68
|
-
validates_around :custom_type => { :type =>
|
68
|
+
validates_around :custom_type => { :type => CustomType1, :presence => true }
|
69
69
|
|
70
70
|
def call
|
71
71
|
end
|
@@ -197,7 +197,7 @@ class ValidateAfterTestUseCase
|
|
197
197
|
context.integer_test = 1
|
198
198
|
context.float_test = 1.0
|
199
199
|
context.string_test = "string"
|
200
|
-
context.bool_test =
|
200
|
+
context.bool_test = true
|
201
201
|
context.hash_test = {}
|
202
202
|
context.array_test = []
|
203
203
|
context.symbol_test = :symbol
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Winfrey
|
@@ -137,3 +137,4 @@ test_files:
|
|
137
137
|
- spec/fixtures/tasks.rb
|
138
138
|
- spec/fixtures/use_cases.rb
|
139
139
|
- spec/spec_helper.rb
|
140
|
+
has_rdoc:
|