metaractor 3.3.0 → 3.3.2

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: 8a67b3860db00780ce1c03f5c551fdb7bbace32bdd7e16d6adabadb541516cb0
4
- data.tar.gz: 2c24a4a91199c196eae047b09830891ff5ea3c0fd2e2d734acfe57059775fc74
3
+ metadata.gz: cbcfbfe6d5747efa204a9b2213e1b25a1579ab80d6ea200b73d66af38e4da26c
4
+ data.tar.gz: 96523e7f340d36266de4a3e4170c2a400cf847c153897806e62d10853ca5986b
5
5
  SHA512:
6
- metadata.gz: 40fdf35588580edf4b57e719958bad16f6dece4e74fd7a4c202c03a3aab47c6c7647fe90c2152a84eb6e8fd20a1bafd84e137efea9676cbd75966b39f22cacff
7
- data.tar.gz: 30fdcf53265820b0e510823730ed027e64171316f757b4047b304ba7f9a1bcc9e95b63016114ee4f2807c2a7a1cb94fc8779ecbb9adca47fd4ea8c0a17fa5245
6
+ metadata.gz: 87493268ef51c78e87e19fd2afec14ee0338602a39ded8a58ec1045afa1f0b334908fe3bcddb08f7c3197fb4a64d6a3954a25f38e0879dfd03d4f76e8404ddf3
7
+ data.tar.gz: 27dc794eea32848f07a7ae6c75173d18ff4ccce2a8a0485a0579043cf5b485ca5d7fdf9379d2a8e6a9fbc835d59759a4dc5f57379793a32c99a0144dd593dc6c
data/.envrc ADDED
@@ -0,0 +1,3 @@
1
+ source_url "https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc" "sha256-YBzqskFZxmNb3kYVoKD9ZixoPXJh1C9ZvTLGFRkauZ0="
2
+
3
+ use devenv
@@ -0,0 +1,13 @@
1
+ name: Specs
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v3
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
13
+ - run: bundle exec rspec spec
data/.gitignore CHANGED
@@ -7,3 +7,8 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ # Devenv
12
+ .devenv*
13
+ devenv.local.nix
14
+ .direnv*
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
1
  --color
2
2
  --require spec_helper
3
3
  --format progress
4
- --format RSpec::Buildkite::AnnotationFormatter
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
- gem 'rspec-buildkite', github: 'outstand/rspec-buildkite', branch: 'error-output'
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # Metaractor [![Build status](https://badge.buildkite.com/70063a5154eb7366b8b7fd65a875c5f64301bc60f6d29a2ad7.svg)](https://buildkite.com/outstand/metaractor)
1
+ ![logo-color](https://user-images.githubusercontent.com/146013/225313017-ea1e42d6-741d-4db6-a492-a1e75106d720.png)
2
+
2
3
  Adds parameter validation and error control to [interactor](https://github.com/collectiveidea/interactor).
3
4
 
4
5
  ## Installation
@@ -54,7 +55,7 @@ See Interactor's [README](https://github.com/collectiveidea/interactor/blob/mast
54
55
  Metaractor is meant to be extensible (hence the 'meta'). You can add additional modules in the following way:
55
56
 
56
57
  ```ruby
57
- # This is an example from Outstand's production app to add some sidekiq magic.
58
+ # This is an example from a production app to add some sidekiq magic.
58
59
  # Feel free to place this in start up code or a Rails initializer.
59
60
  Metaractor.configure do |config|
60
61
  config.prepend_module Metaractor::SidekiqCallbacks
@@ -358,5 +359,5 @@ To release a new version:
358
359
 
359
360
  ## Contributing
360
361
 
361
- Bug reports and pull requests are welcome on GitHub at https://github.com/outstand/metaractor.
362
+ Bug reports and pull requests are welcome on GitHub at https://github.com/metaractor/metaractor.
362
363
 
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
- task :default => :spec
2
+ task default: :spec
data/devenv.lock ADDED
@@ -0,0 +1,210 @@
1
+ {
2
+ "nodes": {
3
+ "devenv": {
4
+ "locked": {
5
+ "dir": "src/modules",
6
+ "lastModified": 1686054274,
7
+ "narHash": "sha256-93aebyN7EMmeFFXisFIvp28UEbrozu79vd3pKPjvNR0=",
8
+ "owner": "cachix",
9
+ "repo": "devenv",
10
+ "rev": "c51a56bac8853c019241fe8d821c0a0d82422835",
11
+ "type": "github"
12
+ },
13
+ "original": {
14
+ "dir": "src/modules",
15
+ "owner": "cachix",
16
+ "repo": "devenv",
17
+ "type": "github"
18
+ }
19
+ },
20
+ "flake-compat": {
21
+ "flake": false,
22
+ "locked": {
23
+ "lastModified": 1673956053,
24
+ "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
25
+ "owner": "edolstra",
26
+ "repo": "flake-compat",
27
+ "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
28
+ "type": "github"
29
+ },
30
+ "original": {
31
+ "owner": "edolstra",
32
+ "repo": "flake-compat",
33
+ "type": "github"
34
+ }
35
+ },
36
+ "flake-compat_2": {
37
+ "flake": false,
38
+ "locked": {
39
+ "lastModified": 1673956053,
40
+ "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
41
+ "owner": "edolstra",
42
+ "repo": "flake-compat",
43
+ "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
44
+ "type": "github"
45
+ },
46
+ "original": {
47
+ "owner": "edolstra",
48
+ "repo": "flake-compat",
49
+ "type": "github"
50
+ }
51
+ },
52
+ "flake-utils": {
53
+ "locked": {
54
+ "lastModified": 1667395993,
55
+ "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
56
+ "owner": "numtide",
57
+ "repo": "flake-utils",
58
+ "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
59
+ "type": "github"
60
+ },
61
+ "original": {
62
+ "owner": "numtide",
63
+ "repo": "flake-utils",
64
+ "type": "github"
65
+ }
66
+ },
67
+ "flake-utils_2": {
68
+ "inputs": {
69
+ "systems": "systems"
70
+ },
71
+ "locked": {
72
+ "lastModified": 1685518550,
73
+ "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
74
+ "owner": "numtide",
75
+ "repo": "flake-utils",
76
+ "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
77
+ "type": "github"
78
+ },
79
+ "original": {
80
+ "owner": "numtide",
81
+ "repo": "flake-utils",
82
+ "type": "github"
83
+ }
84
+ },
85
+ "gitignore": {
86
+ "inputs": {
87
+ "nixpkgs": [
88
+ "pre-commit-hooks",
89
+ "nixpkgs"
90
+ ]
91
+ },
92
+ "locked": {
93
+ "lastModified": 1660459072,
94
+ "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
95
+ "owner": "hercules-ci",
96
+ "repo": "gitignore.nix",
97
+ "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
98
+ "type": "github"
99
+ },
100
+ "original": {
101
+ "owner": "hercules-ci",
102
+ "repo": "gitignore.nix",
103
+ "type": "github"
104
+ }
105
+ },
106
+ "nixpkgs": {
107
+ "locked": {
108
+ "lastModified": 1685938391,
109
+ "narHash": "sha256-96Jw6TbWDLSopt5jqCW8w1Fc1cjQyZlhfBnJ3OZGpME=",
110
+ "owner": "NixOS",
111
+ "repo": "nixpkgs",
112
+ "rev": "31cd1b4afbaf0b1e81272ee9c31d1ab606503aed",
113
+ "type": "github"
114
+ },
115
+ "original": {
116
+ "owner": "NixOS",
117
+ "ref": "nixpkgs-unstable",
118
+ "repo": "nixpkgs",
119
+ "type": "github"
120
+ }
121
+ },
122
+ "nixpkgs-ruby": {
123
+ "inputs": {
124
+ "flake-compat": "flake-compat",
125
+ "flake-utils": "flake-utils",
126
+ "nixpkgs": [
127
+ "nixpkgs"
128
+ ]
129
+ },
130
+ "locked": {
131
+ "lastModified": 1685159223,
132
+ "narHash": "sha256-rwHYapZEvxDJ8dw3hMGY/AE9c6qls9CifAUvObnx7e0=",
133
+ "owner": "bobvanderlinden",
134
+ "repo": "nixpkgs-ruby",
135
+ "rev": "dfaf58567eda18bad5340a9432e601d96c497943",
136
+ "type": "github"
137
+ },
138
+ "original": {
139
+ "owner": "bobvanderlinden",
140
+ "repo": "nixpkgs-ruby",
141
+ "type": "github"
142
+ }
143
+ },
144
+ "nixpkgs-stable": {
145
+ "locked": {
146
+ "lastModified": 1685801374,
147
+ "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
148
+ "owner": "NixOS",
149
+ "repo": "nixpkgs",
150
+ "rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
151
+ "type": "github"
152
+ },
153
+ "original": {
154
+ "owner": "NixOS",
155
+ "ref": "nixos-23.05",
156
+ "repo": "nixpkgs",
157
+ "type": "github"
158
+ }
159
+ },
160
+ "pre-commit-hooks": {
161
+ "inputs": {
162
+ "flake-compat": "flake-compat_2",
163
+ "flake-utils": "flake-utils_2",
164
+ "gitignore": "gitignore",
165
+ "nixpkgs": [
166
+ "nixpkgs"
167
+ ],
168
+ "nixpkgs-stable": "nixpkgs-stable"
169
+ },
170
+ "locked": {
171
+ "lastModified": 1686050334,
172
+ "narHash": "sha256-R0mczWjDzBpIvM3XXhO908X5e2CQqjyh/gFbwZk/7/Q=",
173
+ "owner": "cachix",
174
+ "repo": "pre-commit-hooks.nix",
175
+ "rev": "6881eb2ae5d8a3516e34714e7a90d9d95914c4dc",
176
+ "type": "github"
177
+ },
178
+ "original": {
179
+ "owner": "cachix",
180
+ "repo": "pre-commit-hooks.nix",
181
+ "type": "github"
182
+ }
183
+ },
184
+ "root": {
185
+ "inputs": {
186
+ "devenv": "devenv",
187
+ "nixpkgs": "nixpkgs",
188
+ "nixpkgs-ruby": "nixpkgs-ruby",
189
+ "pre-commit-hooks": "pre-commit-hooks"
190
+ }
191
+ },
192
+ "systems": {
193
+ "locked": {
194
+ "lastModified": 1681028828,
195
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
196
+ "owner": "nix-systems",
197
+ "repo": "default",
198
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
199
+ "type": "github"
200
+ },
201
+ "original": {
202
+ "owner": "nix-systems",
203
+ "repo": "default",
204
+ "type": "github"
205
+ }
206
+ }
207
+ },
208
+ "root": "root",
209
+ "version": 7
210
+ }
data/devenv.nix ADDED
@@ -0,0 +1,25 @@
1
+ { pkgs, ... }:
2
+
3
+ {
4
+ # https://devenv.sh/packages/
5
+ packages = with pkgs; [
6
+ git
7
+ ];
8
+
9
+ # https://devenv.sh/languages/
10
+ languages.ruby.enable = true;
11
+ # Uses bobvanderlinden/nixpkgs-ruby to supply any version of ruby
12
+ languages.ruby.versionFile = ./.ruby-version;
13
+
14
+ enterShell = ''
15
+ export BUNDLE_BIN="$DEVENV_ROOT/.devenv/bin"
16
+ export PATH="$DEVENV_PROFILE/bin:$DEVENV_ROOT/bin:$BUNDLE_BIN:$PATH"
17
+ export BOOTSNAP_CACHE_DIR="$DEVENV_ROOT/.devenv/state"
18
+ '';
19
+
20
+ # The unix socket path can't be "too long".
21
+ # Make sure it's short for when we need it.
22
+ env.RUBY_DEBUG_SOCK_DIR = "/tmp/";
23
+
24
+ # See full reference at https://devenv.sh/reference/options/
25
+ }
data/devenv.yaml ADDED
@@ -0,0 +1,8 @@
1
+ inputs:
2
+ nixpkgs:
3
+ url: github:NixOS/nixpkgs/nixpkgs-unstable
4
+ nixpkgs-ruby:
5
+ url: github:bobvanderlinden/nixpkgs-ruby
6
+ inputs:
7
+ nixpkgs:
8
+ follows: nixpkgs
@@ -28,7 +28,7 @@ module Metaractor
28
28
 
29
29
  def add_errors(messages: [], errors: {}, **args)
30
30
  if !messages.empty?
31
- self.errors.add(errors: { base: messages }, **args)
31
+ self.errors.add(errors: {base: messages}, **args)
32
32
  else
33
33
  self.errors.add(errors: errors, **args)
34
34
  end
@@ -1,5 +1,5 @@
1
- require 'sycamore'
2
- require 'forwardable'
1
+ require "sycamore"
2
+ require "forwardable"
3
3
  module Metaractor
4
4
  class Errors
5
5
  extend Forwardable
@@ -21,15 +21,15 @@ module Metaractor
21
21
 
22
22
  names = object.class.i18n_parent_names
23
23
  until names.empty?
24
- defaults << ['errors', names.join('.'), 'parameters', path_elements.join('.'), @value.to_s].reject do |item|
25
- item.nil? || item == ''
26
- end.join('.').to_sym
24
+ defaults << ["errors", names.join("."), "parameters", path_elements.join("."), @value.to_s].reject do |item|
25
+ item.nil? || item == ""
26
+ end.join(".").to_sym
27
27
  names.pop
28
28
  end
29
29
  end
30
30
 
31
31
  unless path_elements.empty?
32
- defaults << :"errors.parameters.#{path_elements.join('.')}.#{@value}"
32
+ defaults << :"errors.parameters.#{path_elements.join(".")}.#{@value}"
33
33
  end
34
34
  defaults << :"errors.parameters.#{@value}"
35
35
 
@@ -41,18 +41,18 @@ module Metaractor
41
41
  parameter: path_elements.last
42
42
  )
43
43
  else
44
- "#{path_elements.join('.')} #{@value}".lstrip
44
+ "#{path_elements.join(".")} #{@value}".lstrip
45
45
  end
46
46
  end
47
47
 
48
48
  def ==(other)
49
- if other.is_a?(self.class)
50
- @value == other.value
49
+ @value == if other.is_a?(self.class)
50
+ other.value
51
51
  else
52
- @value == other
52
+ other
53
53
  end
54
54
  end
55
- alias eql? ==
55
+ alias_method :eql?, :==
56
56
 
57
57
  def hash
58
58
  @value.hash
@@ -73,10 +73,10 @@ module Metaractor
73
73
  trees = []
74
74
  [error, errors].each do |h|
75
75
  tree = nil
76
- if h.is_a? Metaractor::Errors
77
- tree = Sycamore::Tree.from(h.instance_variable_get(:@tree))
76
+ tree = if h.is_a? Metaractor::Errors
77
+ Sycamore::Tree.from(h.instance_variable_get(:@tree))
78
78
  else
79
- tree = Sycamore::Tree.from(normalize_error_hash(h))
79
+ Sycamore::Tree.from(normalize_error_hash(h))
80
80
  end
81
81
 
82
82
  unless tree.empty?
@@ -112,7 +112,7 @@ module Metaractor
112
112
 
113
113
  messages
114
114
  end
115
- alias to_a full_messages
115
+ alias_method :to_a, :full_messages
116
116
 
117
117
  def full_messages_for(*path)
118
118
  child_tree = @tree.fetch_path(path)
@@ -133,19 +133,17 @@ module Metaractor
133
133
  unwrapped_tree(result).to_h
134
134
  end
135
135
  end
136
- alias [] dig
136
+ alias_method :[], :dig
137
137
 
138
138
  def include?(*elements)
139
139
  if elements.size == 1 &&
140
140
  elements.first.is_a?(Hash)
141
141
  unwrapped_tree.include?(*elements)
142
+ elsif elements.all? { |e| e.is_a? String }
143
+ full_messages.include?(*elements)
142
144
  else
143
- if elements.all? {|e| e.is_a? String }
144
- full_messages.include?(*elements)
145
- else
146
- elements.all? do |element|
147
- @tree.include_path?(element)
148
- end
145
+ elements.all? do |element|
146
+ @tree.include_path?(element)
149
147
  end
150
148
  end
151
149
  end
@@ -169,12 +167,12 @@ module Metaractor
169
167
  @tree.to_h
170
168
  end
171
169
  end
172
- alias to_hash to_h
170
+ alias_method :to_hash, :to_h
173
171
 
174
172
  def inspect
175
173
  str = "<##{self.class.name}: "
176
174
 
177
- if !self.empty?
175
+ if !empty?
178
176
  str << "Errors:\n"
179
177
  str << Metaractor.format_hash(to_h(unwrap: false))
180
178
  str << "\n"
@@ -1,7 +1,7 @@
1
1
  module Metaractor
2
2
  module FailureOutput
3
3
  def to_s
4
- str = ''
4
+ str = ""
5
5
 
6
6
  if !context.errors.empty?
7
7
  str << "Errors:\n"
@@ -19,7 +19,7 @@ module Metaractor
19
19
  end
20
20
 
21
21
  str << "Context:\n"
22
- str << Metaractor.format_hash(context.to_h.reject{|k,_| k == :errors})
22
+ str << Metaractor.format_hash(context.to_h.except(:errors))
23
23
  str
24
24
  end
25
25
  end
@@ -1,5 +1,6 @@
1
1
  module Metaractor
2
2
  class Error < StandardError; end
3
+
3
4
  class InvalidError < Error; end
4
5
 
5
6
  module HandleErrors
@@ -11,7 +11,7 @@ module Metaractor
11
11
  if defined?(@parent_name)
12
12
  @parent_name
13
13
  else
14
- parent_name = name =~ /::[^:]+\z/ ? -$` : nil
14
+ parent_name = (name =~ /::[^:]+\z/) ? -$` : nil
15
15
  @parent_name = parent_name unless frozen?
16
16
  parent_name
17
17
  end
@@ -26,7 +26,7 @@ module Metaractor
26
26
  end
27
27
 
28
28
  def i18n_parent_names
29
- module_parent_names.map {|name| underscore_module_name(name).to_sym }
29
+ module_parent_names.map { |name| underscore_module_name(name).to_sym }
30
30
  end
31
31
 
32
32
  private
@@ -40,7 +40,6 @@ module Metaractor
40
40
  word.downcase!
41
41
  word
42
42
  end
43
-
44
43
  end
45
44
  end
46
45
  end
@@ -31,7 +31,7 @@ module Metaractor
31
31
  def <=>(other)
32
32
  return nil unless other.instance_of? self.class
33
33
  return nil if name == other.name && options != other.options
34
- self.name.to_s <=> other.name.to_s
34
+ name.to_s <=> other.name.to_s
35
35
  end
36
36
 
37
37
  def [](key)
@@ -59,16 +59,17 @@ module Metaractor
59
59
  end
60
60
 
61
61
  protected
62
+
62
63
  attr_reader :options
63
64
  end
64
65
 
65
66
  module ClassMethods
66
67
  def parameter(name, **options)
67
- if param = self.parameter_hash[name.to_sym]
68
+ if (param = parameter_hash[name.to_sym])
68
69
  param.merge!(**options)
69
70
  else
70
71
  Parameter.new(name, **options).tap do |parameter|
71
- self.parameter_hash[parameter.name] = parameter
72
+ parameter_hash[parameter.name] = parameter
72
73
  end
73
74
  end
74
75
  end
@@ -90,7 +91,7 @@ module Metaractor
90
91
  def required(*params, **options)
91
92
  if params.empty?
92
93
  tree = options
93
- self.requirement_trees << tree
94
+ requirement_trees << tree
94
95
  parameters(*parameters_in_tree(tree), required: tree)
95
96
  else
96
97
  parameters(*params, required: true, **options)
@@ -103,7 +104,7 @@ module Metaractor
103
104
 
104
105
  def validate_parameters(*hooks, &block)
105
106
  hooks << block if block
106
- hooks.each {|hook| validate_hooks.push(hook) }
107
+ hooks.each { |hook| validate_hooks.push(hook) }
107
108
  end
108
109
 
109
110
  def validate_hooks
@@ -112,7 +113,7 @@ module Metaractor
112
113
 
113
114
  def parameters_in_tree(tree)
114
115
  if tree.respond_to?(:to_h)
115
- tree.to_h.values.first.to_a.flat_map {|t| parameters_in_tree(t)}
116
+ tree.to_h.values.first.to_a.flat_map { |t| parameters_in_tree(t) }
116
117
  else
117
118
  [tree]
118
119
  end
@@ -128,7 +129,7 @@ module Metaractor
128
129
  end
129
130
 
130
131
  def requirement_trees=(trees)
131
- self.class.requirement_trees=(trees)
132
+ self.class.requirement_trees = (trees)
132
133
  end
133
134
 
134
135
  def remove_blank_values
@@ -156,12 +157,14 @@ module Metaractor
156
157
  end
157
158
 
158
159
  def _parameter_default(name)
159
- default = self.parameters[name][:default]
160
+ default = parameters[name][:default]
160
161
 
161
- case
162
- when default.respond_to?(:call) then instance_exec(&default)
163
- when default.respond_to?(:dup) then default.dup
164
- else default
162
+ if default.respond_to?(:call)
163
+ instance_exec(&default)
164
+ elsif default.respond_to?(:dup)
165
+ default.dup
166
+ else
167
+ default
165
168
  end
166
169
  end
167
170
 
@@ -169,7 +172,7 @@ module Metaractor
169
172
  parameters.each do |name, parameter|
170
173
  next unless parameter[:type]
171
174
 
172
- if context.has_key?(name) && context[name] != nil
175
+ if context.has_key?(name) && !context[name].nil?
173
176
  callable = parameter[:type]
174
177
 
175
178
  if callable.is_a?(Symbol)
@@ -206,7 +209,7 @@ module Metaractor
206
209
  valid, message = parameter_valid? param
207
210
 
208
211
  if !valid
209
- if message_override != nil
212
+ if !message_override.nil?
210
213
  add_parameter_error(param: param, message: message_override)
211
214
  else
212
215
  add_parameter_error(message: "Required parameters: #{message}")
@@ -234,16 +237,16 @@ module Metaractor
234
237
 
235
238
  case operator
236
239
  when :or
237
- return valids.any?, "(#{messages.join(' or ')})"
240
+ [valids.any?, "(#{messages.join(" or ")})"]
238
241
  when :xor
239
- return valids.one?, "(#{messages.join(' xor ')})"
242
+ [valids.one?, "(#{messages.join(" xor ")})"]
240
243
  when :and
241
- return valids.all?, "(#{messages.join(' and ')})"
244
+ [valids.all?, "(#{messages.join(" and ")})"]
242
245
  else
243
246
  raise "invalid required parameter #{param.inspect}"
244
247
  end
245
248
  else
246
- return context[param] != nil, param.to_s
249
+ [!context[param].nil?, param.to_s]
247
250
  end
248
251
  end
249
252
 
@@ -256,7 +259,7 @@ module Metaractor
256
259
  run_hooks(self.class.validate_hooks)
257
260
  end
258
261
 
259
- def add_parameter_error(param: nil, message:)
262
+ def add_parameter_error(message:, param: nil)
260
263
  add_error(
261
264
  message: "#{param} #{message}".lstrip
262
265
  )
@@ -1,5 +1,5 @@
1
- require 'metaractor'
2
- require 'forwardable'
1
+ require "metaractor"
2
+ require "forwardable"
3
3
 
4
4
  module Metaractor
5
5
  module Spec
@@ -13,15 +13,19 @@ module Metaractor
13
13
  result.add_errors(messages: error_messages)
14
14
  result.add_errors(errors: errors)
15
15
 
16
- if (valid != nil && !valid) || (invalid != nil && invalid)
16
+ if (!valid.nil? && !valid) || (!invalid.nil? && invalid)
17
17
  result.invalidate!
18
18
  end
19
19
 
20
20
  if !result.errors.empty? ||
21
21
  result.invalid? ||
22
- (success != nil && !success) ||
23
- (failure != nil && failure)
24
- result.fail! rescue Interactor::Failure
22
+ (!success.nil? && !success) ||
23
+ (!failure.nil? && failure)
24
+ begin
25
+ result.fail!
26
+ rescue
27
+ Interactor::Failure
28
+ end
25
29
  end
26
30
 
27
31
  result
@@ -69,6 +73,5 @@ module Metaractor
69
73
  end
70
74
  end
71
75
  end
72
-
73
76
  end
74
77
  end
@@ -1,3 +1,3 @@
1
1
  module Metaractor
2
- VERSION = "3.3.0"
2
+ VERSION = "3.3.2"
3
3
  end
data/lib/metaractor.rb CHANGED
@@ -1,17 +1,17 @@
1
- require 'metaractor/version'
2
- require 'interactor'
3
- require 'metaractor/errors'
4
- require 'metaractor/handle_errors'
5
- require 'metaractor/context_errors'
6
- require 'metaractor/parameters'
7
- require 'metaractor/run_with_context'
8
- require 'metaractor/context_validity'
9
- require 'metaractor/chain_failures'
10
- require 'metaractor/fail_from_context'
11
- require 'metaractor/context_has_key'
12
- require 'metaractor/failure_output'
13
- require 'i18n'
14
- require 'metaractor/namespace'
1
+ require "metaractor/version"
2
+ require "interactor"
3
+ require "metaractor/errors"
4
+ require "metaractor/handle_errors"
5
+ require "metaractor/context_errors"
6
+ require "metaractor/parameters"
7
+ require "metaractor/run_with_context"
8
+ require "metaractor/context_validity"
9
+ require "metaractor/chain_failures"
10
+ require "metaractor/fail_from_context"
11
+ require "metaractor/context_has_key"
12
+ require "metaractor/failure_output"
13
+ require "i18n"
14
+ require "metaractor/namespace"
15
15
 
16
16
  module Metaractor
17
17
  def self.included(base)
@@ -42,20 +42,20 @@ module Metaractor
42
42
 
43
43
  def self.default_modules
44
44
  [
45
- { module: Metaractor::HandleErrors, method: :include },
46
- { module: Metaractor::Parameters, method: :include },
47
- { module: Metaractor::RunWithContext, method: :include },
48
- { module: Metaractor::ChainFailures, method: :include },
49
- { module: Metaractor::Namespace, method: :include }
45
+ {module: Metaractor::HandleErrors, method: :include},
46
+ {module: Metaractor::Parameters, method: :include},
47
+ {module: Metaractor::RunWithContext, method: :include},
48
+ {module: Metaractor::ChainFailures, method: :include},
49
+ {module: Metaractor::Namespace, method: :include}
50
50
  ]
51
51
  end
52
52
 
53
53
  def self.include_module(mod)
54
- modules << { module: mod, method: :include }
54
+ modules << {module: mod, method: :include}
55
55
  end
56
56
 
57
57
  def self.prepend_module(mod)
58
- modules << { module: mod, method: :prepend }
58
+ modules << {module: mod, method: :prepend}
59
59
  end
60
60
 
61
61
  def self.format_hash(hash)
@@ -67,7 +67,7 @@ module Metaractor
67
67
  end
68
68
 
69
69
  def self.default_hash_formatter
70
- ->(hash){ hash.inspect }
70
+ ->(hash) { hash.inspect }
71
71
  end
72
72
 
73
73
  def self.hash_formatter
data/metaractor.gemspec CHANGED
@@ -1,34 +1,33 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'metaractor/version'
3
+ require "metaractor/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = 'metaractor'
8
- spec.version = Metaractor::VERSION
9
- spec.license = 'Apache-2.0'
10
- spec.authors = ['Ryan Schlesinger']
11
- spec.email = ['ryan@outstand.com']
6
+ spec.name = "metaractor"
7
+ spec.version = Metaractor::VERSION
8
+ spec.license = "Apache-2.0"
9
+ spec.authors = ["Ryan Schlesinger"]
10
+ spec.email = ["ryan@ryanschlesinger.com"]
12
11
 
13
- spec.summary = %q{Adds parameter validation and error control to interactor}
14
- spec.metadata = {
15
- "homepage_uri" => "https://github.com/outstand/metaractor",
16
- "source_code_uri" => "https://github.com/outstand/metaractor"
12
+ spec.summary = "Adds parameter validation and error control to interactor"
13
+ spec.metadata = {
14
+ "homepage_uri" => "https://github.com/metaractor/metaractor",
15
+ "source_code_uri" => "https://github.com/metaractor/metaractor"
17
16
  }
18
17
 
19
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
- spec.bindir = 'exe'
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ['lib']
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
23
22
 
24
- spec.add_runtime_dependency 'interactor', '~> 3.1'
25
- spec.add_runtime_dependency 'outstand-sycamore', '0.4.0'
26
- spec.add_runtime_dependency 'i18n', '~> 1.8'
23
+ spec.add_runtime_dependency "interactor", "~> 3.1"
24
+ spec.add_runtime_dependency "metaractor-sycamore", "~> 0.4", ">= 0.4.3"
25
+ spec.add_runtime_dependency "i18n", "~> 1.8"
27
26
 
28
- spec.add_development_dependency 'bundler', '~> 2'
29
- spec.add_development_dependency 'rake', '~> 13.0'
30
- spec.add_development_dependency 'rspec', '~> 3.9'
31
- spec.add_development_dependency 'awesome_print', '~> 1.8'
32
- spec.add_development_dependency 'pry-byebug', '~> 3.9'
33
- spec.add_development_dependency 'activemodel', '~> 6.1'
27
+ spec.add_development_dependency "bundler", "~> 2"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
+ spec.add_development_dependency "rspec", "~> 3.9"
30
+ spec.add_development_dependency "awesome_print", "~> 1.8"
31
+ spec.add_development_dependency "pry-byebug", "~> 3.9"
32
+ spec.add_development_dependency "activemodel", "~> 6.1"
34
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metaractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Schlesinger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-26 00:00:00.000000000 Z
11
+ date: 2023-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: interactor
@@ -25,19 +25,25 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: outstand-sycamore
28
+ name: metaractor-sycamore
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ - - ">="
32
35
  - !ruby/object:Gem::Version
33
- version: 0.4.0
36
+ version: 0.4.3
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - '='
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.4'
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: 0.4.0
46
+ version: 0.4.3
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: i18n
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -136,25 +142,25 @@ dependencies:
136
142
  - - "~>"
137
143
  - !ruby/object:Gem::Version
138
144
  version: '6.1'
139
- description:
145
+ description:
140
146
  email:
141
- - ryan@outstand.com
147
+ - ryan@ryanschlesinger.com
142
148
  executables: []
143
149
  extensions: []
144
150
  extra_rdoc_files: []
145
151
  files:
146
- - ".buildkite/pipeline.yml"
152
+ - ".envrc"
153
+ - ".github/workflows/specs.yml"
147
154
  - ".gitignore"
148
155
  - ".rspec"
149
- - Deskfile
150
- - Dockerfile
156
+ - ".ruby-version"
151
157
  - Gemfile
152
158
  - LICENSE
153
159
  - README.md
154
160
  - Rakefile
155
- - brew-shim
156
- - compose.yml
157
- - docker-entrypoint.sh
161
+ - devenv.lock
162
+ - devenv.nix
163
+ - devenv.yaml
158
164
  - lib/metaractor.rb
159
165
  - lib/metaractor/chain_failures.rb
160
166
  - lib/metaractor/context_errors.rb
@@ -170,13 +176,13 @@ files:
170
176
  - lib/metaractor/spec.rb
171
177
  - lib/metaractor/version.rb
172
178
  - metaractor.gemspec
173
- homepage:
179
+ homepage:
174
180
  licenses:
175
181
  - Apache-2.0
176
182
  metadata:
177
- homepage_uri: https://github.com/outstand/metaractor
178
- source_code_uri: https://github.com/outstand/metaractor
179
- post_install_message:
183
+ homepage_uri: https://github.com/metaractor/metaractor
184
+ source_code_uri: https://github.com/metaractor/metaractor
185
+ post_install_message:
180
186
  rdoc_options: []
181
187
  require_paths:
182
188
  - lib
@@ -191,8 +197,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
197
  - !ruby/object:Gem::Version
192
198
  version: '0'
193
199
  requirements: []
194
- rubygems_version: 3.3.7
195
- signing_key:
200
+ rubygems_version: 3.4.10
201
+ signing_key:
196
202
  specification_version: 4
197
203
  summary: Adds parameter validation and error control to interactor
198
204
  test_files: []
@@ -1,93 +0,0 @@
1
- env:
2
- BUILDKITE_PLUGIN_DOCKER_CACHE_S3_BUCKET: "outstand-buildkite-cache"
3
- # BUILDKITE_PLUGIN_DOCKER_CACHE_VOLUME_DEBUG: "true"
4
- BUILDKITE_PLUGIN_DOCKER_COMPOSE_SHELL: "false"
5
- # BUILDKITE_PLUGIN_DOCKER_COMPOSE_UPLOAD_CONTAINER_LOGS: "always"
6
- BUILDKITE_PLUGIN_DOCKER_COMPOSE_PULL_RETRIES: 5
7
- BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_RETRIES: 5
8
- PLUGIN_DOCKER_COMPOSE_VERSION: "03d746fbf5171b217b732ff7d8a3e417d664df1c"
9
- PLUGIN_DOCKER_CACHE_VERSION: "50ecc80f736a4a3a0ab1f5990e58ae8e536c85e1"
10
- WORKSPACE_DIR: "${BUILDKITE_BUILD_CHECKOUT_PATH}"
11
-
12
- steps:
13
- - label: ":docker: Build"
14
- key: build
15
- plugins:
16
- - seek-oss/aws-sm#v2.3.1:
17
- env:
18
- DOCKER_LOGIN_PASSWORD: "/buildkite/docker_password"
19
-
20
- - docker-login#v2.1.0:
21
- username: outstandci
22
- retries: 2
23
-
24
- - ecr#v2.5.0:
25
- login: true
26
- region: "us-east-1"
27
-
28
- - https://github.com/outstand/docker-compose-buildkite-plugin.git#${PLUGIN_DOCKER_COMPOSE_VERSION}:
29
- build: metaractor
30
- image-repository: 786715713882.dkr.ecr.us-east-1.amazonaws.com/ci-images
31
- config:
32
- - compose.yml
33
-
34
- - label: ":bundler: :rubygems:"
35
- key: bundle_install
36
- command: bundle install
37
- depends_on: build
38
- plugins:
39
- - seek-oss/aws-sm#v2.3.1:
40
- env:
41
- DOCKER_LOGIN_PASSWORD: "/buildkite/docker_password"
42
-
43
- - docker-login#v2.1.0:
44
- username: outstandci
45
- retries: 2
46
-
47
- - ecr#v2.5.0:
48
- login: true
49
- region: "us-east-1"
50
-
51
- - https://github.com/outstand/docker-compose-buildkite-plugin.git#${PLUGIN_DOCKER_COMPOSE_VERSION}:
52
- run: metaractor
53
- dependencies: false
54
- config:
55
- - compose.yml
56
-
57
- - https://github.com/outstand/docker-cache-buildkite-plugin.git#${PLUGIN_DOCKER_CACHE_VERSION}:
58
- name: bundler-cache
59
- keys:
60
- - v2-bundler-cache-{{ arch }}-{{ checksum "metaractor.gemspec" }}-{{ checksum "Gemfile" }}
61
- - v2-bundler-cache-{{ arch }}-
62
- save: true
63
- volumes:
64
- - bundler-data
65
-
66
- - label: ":ruby: Specs"
67
- command: rspec spec
68
- depends_on: bundle_install
69
- plugins:
70
- - seek-oss/aws-sm#v2.3.1:
71
- env:
72
- DOCKER_LOGIN_PASSWORD: "/buildkite/docker_password"
73
-
74
- - docker-login#v2.1.0:
75
- username: outstandci
76
- retries: 2
77
-
78
- - ecr#v2.5.0:
79
- login: true
80
- region: "us-east-1"
81
-
82
- - https://github.com/outstand/docker-compose-buildkite-plugin.git#${PLUGIN_DOCKER_COMPOSE_VERSION}:
83
- run: metaractor
84
- config:
85
- - compose.yml
86
-
87
- - https://github.com/outstand/docker-cache-buildkite-plugin.git#${PLUGIN_DOCKER_CACHE_VERSION}:
88
- name: bundler-cache
89
- keys:
90
- - v2-bundler-cache-{{ arch }}-{{ checksum "metaractor.gemspec" }}-{{ checksum "Gemfile" }}
91
- - v2-bundler-cache-{{ arch }}-
92
- volumes:
93
- - bundler-data
data/Deskfile DELETED
@@ -1,3 +0,0 @@
1
- rspec() {
2
- docker compose run --rm metaractor rspec "$@"
3
- }
data/Dockerfile DELETED
@@ -1,78 +0,0 @@
1
- FROM outstand/su-exec:latest as su-exec
2
- FROM outstand/fixuid as fixuid
3
-
4
- FROM ruby:3.1.2-bullseye
5
- LABEL maintainer="Ryan Schlesinger <ryan@outstand.com>"
6
-
7
- SHELL ["/bin/bash", "-o", "pipefail", "-c"]
8
- ENV DEBIAN_FRONTEND=noninteractive
9
-
10
- RUN set -eux; \
11
- \
12
- groupadd -g 1000 metaractor && \
13
- useradd -u 1000 -g metaractor -ms /bin/bash metaractor && \
14
- \
15
- apt-get update -y; \
16
- apt-get install -y \
17
- ca-certificates \
18
- curl \
19
- git \
20
- build-essential \
21
- tini \
22
- ; \
23
- apt-get clean; \
24
- rm -f /var/lib/apt/lists/*_*
25
-
26
- # install su-exec
27
- COPY --from=su-exec /sbin/su-exec /sbin/su-exec
28
-
29
- # install fixuid
30
- COPY --from=fixuid /usr/local/bin/fixuid /usr/local/bin/fixuid
31
- RUN set -eux; \
32
- \
33
- chmod 4755 /usr/local/bin/fixuid; \
34
- USER=metaractor; \
35
- GROUP=metaractor; \
36
- mkdir -p /etc/fixuid; \
37
- printf "user: $USER\ngroup: $GROUP\n" > /etc/fixuid/config.yml
38
-
39
- ENV BUNDLER_VERSION 2.3.21
40
- ENV GITHUB_CLI_VERSION 2.14.4
41
- ENV GITHUB_CLI_CHECKSUM b0073fdcc07d1de5a19a1a782c7ad9f593f991da06a809ea39f0b6148869aa96
42
- RUN set -eux; \
43
- \
44
- mkdir -p /tmp/build; \
45
- cd /tmp/build; \
46
- \
47
- gem install bundler -v ${BUNDLER_VERSION} -i /usr/local/lib/ruby/gems/$(ls /usr/local/lib/ruby/gems) --force; \
48
- curl -fsSL https://github.com/cli/cli/releases/download/v${GITHUB_CLI_VERSION}/gh_${GITHUB_CLI_VERSION}_linux_amd64.deb -o gh_${GITHUB_CLI_VERSION}_linux_amd64.deb; \
49
- echo "${GITHUB_CLI_CHECKSUM} gh_${GITHUB_CLI_VERSION}_linux_amd64.deb" | sha256sum --check; \
50
- apt-get update -y; \
51
- apt-get install -y --no-install-recommends \
52
- ./gh_${GITHUB_CLI_VERSION}_linux_amd64.deb \
53
- ; \
54
- apt-get clean; \
55
- rm -f /var/lib/apt/lists/*_*; \
56
- rm -rf /tmp/build
57
-
58
- COPY brew-shim /usr/bin/brew
59
-
60
- WORKDIR /metaractor
61
- RUN set -eux; \
62
- \
63
- chown -R metaractor:metaractor /metaractor
64
-
65
- USER metaractor
66
-
67
- COPY --chown=metaractor:metaractor Gemfile metaractor.gemspec /metaractor/
68
- COPY --chown=metaractor:metaractor lib/metaractor/version.rb /metaractor/lib/metaractor/
69
- RUN set -eux; \
70
- \
71
- git config --global push.default simple
72
- COPY --chown=metaractor:metaractor . /metaractor/
73
-
74
- USER root
75
- COPY docker-entrypoint.sh /docker-entrypoint.sh
76
-
77
- ENTRYPOINT ["/usr/bin/tini", "-g", "--", "/docker-entrypoint.sh"]
78
- CMD ["rspec", "spec"]
data/brew-shim DELETED
@@ -1,10 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -euo pipefail
4
-
5
- # Docker host has the following git config:
6
- # helper = !$(brew --prefix)/bin/gh auth git-credential
7
- #
8
- # We're going to lie inside the container so we can find the local gh
9
-
10
- echo "/usr"
data/compose.yml DELETED
@@ -1,35 +0,0 @@
1
- services:
2
- metaractor:
3
- build: .
4
- image: outstand/metaractor:dev
5
- stdin_open: true
6
- tty: true
7
- environment:
8
- FIXUID:
9
- FIXGID:
10
- BUILDKITE:
11
- BUILDKITE_BUILD_URL:
12
- BUILDKITE_JOB_ID:
13
- BUILDKITE_AGENT_ACCESS_TOKEN:
14
- volumes:
15
- - bundler-data:/usr/local/bundle
16
- - .:/metaractor
17
-
18
- release:
19
- image: outstand/metaractor:dev
20
- stdin_open: true
21
- tty: true
22
- command: rake release
23
- environment:
24
- FIXUID:
25
- FIXGID:
26
- volumes:
27
- - bundler-data:/usr/local/bundle
28
- - ~/.gitconfig:/home/metaractor/.gitconfig
29
- - ~/.gitconfig.user:/home/metaractor/.gitconfig.user
30
- - ~/.config/gh/hosts.yml:/home/metaractor/.config/gh/hosts.yml
31
- - ~/.local/share/gem/credentials:/home/metaractor/.local/share/gem/credentials
32
- - ~/.local/share/gem/credentials:/home/metaractor/.gem/credentials
33
-
34
- volumes:
35
- bundler-data:
data/docker-entrypoint.sh DELETED
@@ -1,39 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -euo pipefail
4
-
5
- su-exec ${FIXUID:?Missing FIXUID var}:${FIXGID:?Missing FIXGID var} fixuid
6
-
7
- chown_dir() {
8
- dir=$1
9
- if [[ -d ${dir} ]] && [[ "$(stat -c %u:%g ${dir})" != "${FIXUID}:${FIXGID}" ]]; then
10
- echo chown $dir
11
- chown metaractor:metaractor $dir
12
- fi
13
- }
14
-
15
- chown_dir /usr/local/bundle
16
- chown_dir /home/metaractor/.local/share/gem
17
- chown_dir /home/metaractor/.gem
18
-
19
- if [ "$(which "$1")" = '' ]; then
20
- if [ "$(ls -A /usr/local/bundle/bin)" = '' ]; then
21
- echo 'command not in path and bundler not initialized'
22
- echo 'running bundle install'
23
- su-exec metaractor bundle install
24
- fi
25
- fi
26
-
27
- if [ "$1" = 'bundle' ]; then
28
- set -- su-exec metaractor "$@"
29
- elif [ "$1" = 'rake' ]; then
30
- set -- su-exec metaractor bundle exec "$@"
31
-
32
- su-exec metaractor bash -c 'bundle check || bundle install'
33
- elif ls /usr/local/bundle/bin | grep -q "\b$1\b"; then
34
- set -- su-exec metaractor bundle exec "$@"
35
-
36
- su-exec metaractor bash -c 'bundle check || bundle install'
37
- fi
38
-
39
- exec "$@"