typed_operation 0.4.0 → 0.4.2
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/generators/templates/operation.rb +4 -4
- data/lib/generators/templates/operation_test.rb +19 -17
- data/lib/typed_operation/base.rb +1 -1
- data/lib/typed_operation/partially_applied.rb +5 -2
- data/lib/typed_operation/version.rb +1 -1
- data/lib/typed_operation.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5af7163e167fa37ba366469393a59d8ea25d4eede88472a7c739bee91e987d7
|
4
|
+
data.tar.gz: fb1de81a7eb3ce710c36355474c7f3b01e970c4696a82ede8fd680273cae1cb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd8a364079683dbe13c02c6090a707499db4f847bf86c395baa80ffed3e7bc997b11ae545c2a7f20d9b2c46e66f9e4b3b5496776524fe70b276eef46eff33f88
|
7
|
+
data.tar.gz: 7a7cf690621318b56b44cfe8cf4d4231694d65befd2ee62dd1cfb53d283be653b41011de4ad77f9f46636eb0b4146093f37162f4059aa74afc8190f9a789b68e
|
@@ -4,8 +4,8 @@
|
|
4
4
|
module <%= namespace_name %>
|
5
5
|
class <%= name %> < ::ApplicationOperation
|
6
6
|
# Replace with implementation...
|
7
|
-
param :
|
8
|
-
param :an_optional_param, Integer, allow_nil: true
|
7
|
+
param :required_param, String
|
8
|
+
param :an_optional_param, Integer, convert: true, allow_nil: true
|
9
9
|
|
10
10
|
def prepare
|
11
11
|
# Prepare...
|
@@ -20,8 +20,8 @@ end
|
|
20
20
|
<% else %>
|
21
21
|
class <%= name %> < ::ApplicationOperation
|
22
22
|
# Replace with implementation...
|
23
|
-
param :
|
24
|
-
param :an_optional_param, Integer, allow_nil: true
|
23
|
+
param :required_param, String
|
24
|
+
param :an_optional_param, Integer, convert: true, allow_nil: true
|
25
25
|
|
26
26
|
def prepare
|
27
27
|
# Prepare...
|
@@ -1,45 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "test_helper"
|
4
|
+
|
3
5
|
<% if namespace_name.present? %>
|
4
6
|
module <%= namespace_name %>
|
5
7
|
class <%= name %>Test < ActiveSupport::TestCase
|
6
8
|
def setup
|
7
|
-
@operation = <%= name %>.new(
|
9
|
+
@operation = <%= name %>.new(required_param: "test")
|
8
10
|
end
|
9
11
|
|
10
|
-
test
|
12
|
+
test "should raise ParameterError if required param is nil" do
|
11
13
|
assert_raises(ParameterError) do
|
12
|
-
<%= name %>.new(
|
14
|
+
<%= name %>.new(required_param: nil)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
test
|
17
|
-
assert_equal <%= name %>.new(
|
18
|
+
test "should convert optional_param if it is not a string" do
|
19
|
+
assert_equal <%= name %>.new(required_param: "foo", optional_param: 123).converts_param, "123"
|
18
20
|
end
|
19
21
|
|
20
|
-
test
|
22
|
+
test "call returns after operation" do
|
21
23
|
result = @operation.call
|
22
24
|
assert_equal result, "Hello World!"
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
<% else %>
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
class <%= name %>Test < ActiveSupport::TestCase
|
30
|
+
def setup
|
31
|
+
@operation = <%= name %>.new(required_param: "test")
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
34
|
+
test "should raise ParameterError if required param is nil" do
|
35
|
+
assert_raises(ParameterError) do
|
36
|
+
<%= name %>.new(required_param: nil)
|
36
37
|
end
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
test "should convert optional_param if it is not a string" do
|
41
|
+
assert_equal <%= name %>.new(required_param: "foo", optional_param: 123).converts_param, "123"
|
40
42
|
end
|
41
43
|
|
42
|
-
test
|
44
|
+
test "call returns after operation" do
|
43
45
|
result = @operation.call
|
44
46
|
assert_equal result, "Hello World!"
|
45
47
|
end
|
data/lib/typed_operation/base.rb
CHANGED
@@ -10,7 +10,10 @@ module TypedOperation
|
|
10
10
|
def curry(**params)
|
11
11
|
all_args = @applied_args.merge(params)
|
12
12
|
# check if required attrs are in @applied_args
|
13
|
-
required_keys = @operation.attribute_names.select
|
13
|
+
required_keys = @operation.attribute_names.select do |name|
|
14
|
+
meta = @operation.attribute_metadata(name)
|
15
|
+
meta[:required] != false && !meta[:typed_attribute_options].key?(:default)
|
16
|
+
end
|
14
17
|
missing_keys = required_keys - all_args.keys
|
15
18
|
|
16
19
|
if missing_keys.size > 0
|
@@ -26,7 +29,7 @@ module TypedOperation
|
|
26
29
|
def call(...)
|
27
30
|
prepared = curry(...)
|
28
31
|
return prepared.operation.call if prepared.is_a?(Prepared)
|
29
|
-
raise "Cannot call PartiallyApplied operation #{@operation.name} (key: #{@operation.operation_key}), are you expecting it to be Prepared?"
|
32
|
+
raise TypedOperation::MissingParameterError, "Cannot call PartiallyApplied operation #{@operation.name} (key: #{@operation.operation_key}), are you expecting it to be Prepared?"
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
data/lib/typed_operation.rb
CHANGED
@@ -5,5 +5,7 @@ require "typed_operation/partially_applied"
|
|
5
5
|
require "typed_operation/prepared"
|
6
6
|
|
7
7
|
module TypedOperation
|
8
|
-
class
|
8
|
+
class InvalidOperationError < StandardError; end
|
9
|
+
class MissingParameterError < ArgumentError; end
|
10
|
+
class ParameterError < TypeError; end
|
9
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typed_operation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|