arq 0.2.0 → 0.2.1

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: 37b1eabfaf83924a5d2c61b390cf9a74043860578c247b851a77bd9b7f8308ce
4
- data.tar.gz: e6bafd5efe08658bf7a6065d7026e3aa7dec67e4ead6f4621cf7c94f2df3c464
3
+ metadata.gz: 83941043c326bd9f80903aa4755c49ae3affe39584f12d3757ab8a05e0878987
4
+ data.tar.gz: d94724fe95ba5dfe444c3d2587357ec60c825a61c5a0a5743a55b8c44c2b3b05
5
5
  SHA512:
6
- metadata.gz: 3b900d412628cc1da83c1f9aff8e96a058934cde992f0cbdc1524e34614fbd8c12ad5f0f5b18f25e45b991fa470ebdf0bb01d02d26073d128736aa03c0ad49cc
7
- data.tar.gz: b7e55db8850980446f857cd0d89094e95c1983077a748810607a0f8a34e97444d633bbe669ffabffe865b6621cc5ff024ab37c5aeefb125e466989e524eee624
6
+ metadata.gz: 418c2ba2e7f9373056b1eb52503c9af47749921c8c696bdf4dce98bcf0649684eab3f2a48742f3943aed00839c1e776178e0fc4b0932409203d7c04891fa52bf
7
+ data.tar.gz: 543ada56b97ebef9d58fd01e614583aca4a123707917bd3d11607e2645c6ae4688db1b942be279fd0fac86c0986d6d5f7d9c9c198d8ee5742efaffbcced27f88
data/lib/arq/action.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Arq
4
4
  # Module to extend to create an action. Exposes confing functions #call, #params, and #returns.
5
5
  module Action
6
- def call(ctx)
6
+ def call(ctx = Arq::Context.new)
7
7
  ctx = transform_input_context(ctx)
8
8
 
9
9
  generate_runnable(ctx).call
data/lib/arq/runnable.rb CHANGED
@@ -16,9 +16,7 @@ module Arq
16
16
 
17
17
  validate_required_params
18
18
 
19
- import_context
20
19
  val = run_block
21
- export_context
22
20
 
23
21
  # If the block returned an array, attempt to run
24
22
  run_sequence(val) if val.is_a?(Array)
@@ -33,20 +31,22 @@ module Arq
33
31
  Arq::Runnable.new(@ctx, [], [], &block)
34
32
  end
35
33
 
36
- def fail!(message)
34
+ def fail!(message = nil)
37
35
  @ctx.fail!(message)
38
36
  end
39
37
 
40
- def fail_now!(message)
38
+ def fail_now!(message = nil)
41
39
  @ctx.fail_now!(message)
42
40
  end
43
41
 
44
42
  private
45
43
 
46
44
  def run_block
47
- instance_eval(&@block)
48
- rescue Arq::FailureError
49
- nil
45
+ with_context do
46
+ instance_eval(&@block)
47
+ rescue Arq::FailureError
48
+ nil
49
+ end
50
50
  end
51
51
 
52
52
  def run_sequence(sequence)
@@ -60,20 +60,39 @@ module Arq
60
60
  end
61
61
  end
62
62
 
63
- def import_context
63
+ # Runs the block with context parameters set as instance variables, then
64
+ # imports all context parameters and any new instance vars into the context.
65
+ # Returns the return value of the block.
66
+ def with_context
67
+ # Grab all current variables to know what is being returned
68
+ before_vars = instance_variables
69
+
70
+ # Load all context parameters into runnable instance
71
+ import_context_to_vars
72
+
73
+ # Run block
74
+ val = yield
75
+
76
+ # Grab all ctx + new vars
77
+ ctx_vars = instance_variables - before_vars
78
+
79
+ # Import instance vars into ctx
80
+ import_vars_to_context(ctx_vars)
81
+
82
+ # Return block value
83
+ val
84
+ end
85
+
86
+ def import_context_to_vars
64
87
  @ctx.each do |key, val|
65
88
  instance_variable_set(:"@#{key}", val)
66
89
  end
67
90
  end
68
91
 
69
- def export_context
70
- keys = [*@ctx.keys, *@returns]
71
-
72
- keys.each do |key|
73
- instance_key = :"@#{key}"
74
- # Must check for existence since getting non-existent
75
- # instance variables will return nil.
76
- @ctx[key] = instance_variable_get(instance_key) if instance_variables.include?(instance_key)
92
+ def import_vars_to_context(vars)
93
+ vars.each do |var|
94
+ key = var[1..].to_sym
95
+ @ctx[key] = instance_variable_get(var)
77
96
  end
78
97
  end
79
98
 
data/lib/arq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arq
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kavin Phan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-06 00:00:00.000000000 Z
11
+ date: 2022-09-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A service skeleton framework heavily inspired by LightService with the
14
14
  primary goal of being less verbose.