mandate 0.3.0 → 0.4.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mandate/call_injector.rb +9 -1
- data/lib/mandate/callbacks.rb +3 -2
- data/lib/mandate/initializer_injector.rb +37 -8
- data/lib/mandate/version.rb +1 -1
- data/mandate.gemspec +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b09d224e7ec0f4d9b2f7c3b4e15a87a2f28afb4447391172b8cb7c400d9d3a1f
|
4
|
+
data.tar.gz: bf5866603824cb3ee5702476c04759bee58a263606265642dacd92f7b89f5abe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f71376313ee4ebe4409a16a1b2bfe394a6b7c847e6ca3c93e633614f36adc8a7845cf8a0191365e03da77c65e3a7c413e93e771d5e811d1ef4b6c3e0657db866
|
7
|
+
data.tar.gz: c1f28ac5099779f02b1d57712d9dabd27df43be73ba1bd7032ff1d2d1098683f3170da39abf1ea07030f54948f77dae914958880cacc8cd508fb91c6f6a05a1d
|
@@ -7,7 +7,15 @@ module Mandate
|
|
7
7
|
# Foobar.new(some, args).call()
|
8
8
|
class << base
|
9
9
|
def call(*args)
|
10
|
-
|
10
|
+
# If the last argument is a hash and the last param is a keyword params (signified by
|
11
|
+
# its type being :key, the we should pass the hash in in using the **kwords syntax.
|
12
|
+
# This fixes a deprecation issue in Ruby 2.7.
|
13
|
+
if args.last.is_a?(Hash) &&
|
14
|
+
:key == instance_method(:initialize).parameters.last&.first
|
15
|
+
new(*args[0..-2], **args[-1]).call
|
16
|
+
else
|
17
|
+
new(*args).call
|
18
|
+
end
|
11
19
|
end
|
12
20
|
end
|
13
21
|
end
|
data/lib/mandate/callbacks.rb
CHANGED
@@ -71,20 +71,21 @@ module Mandate
|
|
71
71
|
@__mandate_results
|
72
72
|
end
|
73
73
|
|
74
|
-
private
|
75
|
-
|
76
74
|
base.send(:define_method, :add_error!) do |error|
|
77
75
|
@__mandate_results.add_error(error)
|
78
76
|
end
|
77
|
+
base.send(:private, :add_error!)
|
79
78
|
|
80
79
|
base.send(:define_method, :abort!) do |error = nil|
|
81
80
|
add_error!(error) if error
|
82
81
|
raise AbortError
|
83
82
|
end
|
83
|
+
base.send(:private, :abort!)
|
84
84
|
|
85
85
|
base.send(:define_method, :abort_if_errored!) do
|
86
86
|
raise AbortError if @__mandate_results.errors.size > 0
|
87
87
|
end
|
88
|
+
base.send(:private, :abort_if_errored!)
|
88
89
|
end
|
89
90
|
end
|
90
91
|
end
|
@@ -2,14 +2,34 @@ module Mandate
|
|
2
2
|
module InitializerInjector
|
3
3
|
def self.extended(base)
|
4
4
|
class << base
|
5
|
-
def initialize_with(*attrs)
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def initialize_with(*attrs, **kwattrs)
|
6
|
+
if kwattrs.empty?
|
7
|
+
define_method :initialize do |*args|
|
8
|
+
unless args.length == attrs.length
|
9
|
+
raise ArgumentError.new("wrong number of arguments (given #{args.length}, expected #{attrs.length})")
|
10
|
+
end
|
11
|
+
|
12
|
+
attrs.zip(args).each do |attr,arg|
|
13
|
+
instance_variable_set("@#{attr}", arg)
|
14
|
+
end
|
9
15
|
end
|
16
|
+
else
|
17
|
+
define_method :initialize do |*args, **kwargs|
|
18
|
+
unless args.length == attrs.length
|
19
|
+
raise ArgumentError.new("wrong number of arguments (given #{args.length}, expected #{attrs.length})")
|
20
|
+
end
|
21
|
+
|
22
|
+
attrs.zip(args).each do |attr,arg|
|
23
|
+
instance_variable_set("@#{attr}", arg)
|
24
|
+
end
|
10
25
|
|
11
|
-
|
12
|
-
|
26
|
+
kwargs.each do |name,value|
|
27
|
+
if kwattrs.keys.include?(name)
|
28
|
+
instance_variable_set("@#{name}", value)
|
29
|
+
else
|
30
|
+
raise ArgumentError.new("unknown keyword: #{name}")
|
31
|
+
end
|
32
|
+
end
|
13
33
|
end
|
14
34
|
end
|
15
35
|
|
@@ -17,10 +37,19 @@ module Mandate
|
|
17
37
|
define_method attr do instance_variable_get("@#{attr}") end
|
18
38
|
private attr
|
19
39
|
end
|
40
|
+
|
41
|
+
kwattrs.each do |attr,default|
|
42
|
+
define_method attr do
|
43
|
+
if instance_variable_defined?("@#{attr}")
|
44
|
+
instance_variable_get("@#{attr}")
|
45
|
+
else
|
46
|
+
default
|
47
|
+
end
|
48
|
+
end
|
49
|
+
private attr
|
50
|
+
end
|
20
51
|
end
|
21
52
|
end
|
22
53
|
end
|
23
54
|
end
|
24
55
|
end
|
25
|
-
|
26
|
-
|
data/lib/mandate/version.rb
CHANGED
data/mandate.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
25
25
|
spec.add_development_dependency "rake", "~> 12.3"
|
26
26
|
spec.add_development_dependency "minitest", "~> 5.0"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,7 @@ homepage: https://github.com/iHiD/mandate
|
|
80
80
|
licenses:
|
81
81
|
- MIT
|
82
82
|
metadata: {}
|
83
|
-
post_install_message:
|
83
|
+
post_install_message:
|
84
84
|
rdoc_options: []
|
85
85
|
require_paths:
|
86
86
|
- lib
|
@@ -91,12 +91,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.3.1
|
97
97
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
98
|
+
rubygems_version: 3.1.2
|
99
|
+
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: A simple command-pattern helper gem for Ruby
|
102
102
|
test_files: []
|