neo-dci 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -5
- data/Gemfile +0 -4
- data/lib/neo/dci/context.rb +21 -19
- data/lib/neo/dci/version.rb +1 -1
- data/lib/ruby2_keywords.rb +24 -0
- data/neo-dci.gemspec +2 -1
- data/test/context_test.rb +87 -5
- data/test/helper.rb +2 -6
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a0fd6e30874980cc150a48995e912165343d425fc24254e0f3f9b97e49fdf13
|
4
|
+
data.tar.gz: bfa3c369b56c93a5e4ecfc7c915e26f6c52655245e4d5ea979280e70279e4f71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f53b2c7652fa22003c46c002d2ebd2b717d4290294017c3c73cd85b6accf1a2abcb122c6c68b8c29508f1178209d1432f2b95a2b4c509ffcb5e93fa42bd3d1b2
|
7
|
+
data.tar.gz: 2aca570d841b0898e41e7138048abf5e9fc3a36c961d11ff3213db1db7dd580c147426967330f10e8faa88395132fa6b0b5fb38968f304657419127bbb38c2e7
|
data/.travis.yml
CHANGED
@@ -3,15 +3,13 @@ sudo: false
|
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
5
|
- ruby-head
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
6
|
+
- 2.7.0
|
7
|
+
- 2.6
|
8
|
+
- 2.5
|
9
9
|
- jruby
|
10
10
|
- jruby-head
|
11
|
-
- rbx-2
|
12
11
|
matrix:
|
13
12
|
allow_failures:
|
14
|
-
- rvm: rbx-2
|
15
13
|
- rvm: jruby
|
16
14
|
- rvm: jruby-head
|
17
15
|
- rvm: ruby-head
|
data/Gemfile
CHANGED
data/lib/neo/dci/context.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
+
require "ruby2_keywords"
|
2
|
+
|
1
3
|
module Neo
|
2
4
|
module DCI
|
3
5
|
class Context
|
4
6
|
class << self
|
5
7
|
private :new
|
6
|
-
end
|
7
8
|
|
8
|
-
|
9
|
+
def callbacks(*args)
|
10
|
+
@callbacks ||= []
|
11
|
+
@callbacks = args unless args.empty?
|
12
|
+
@callbacks
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
ruby2_keywords def call(*args, &block)
|
16
|
+
context = new(*args)
|
17
|
+
context.callback = result_class.new(*callbacks, &block)
|
18
|
+
context.call
|
19
|
+
raise NoCallbackCalled, callbacks unless context.callback.called?
|
20
|
+
rescue NotImplementedError
|
21
|
+
raise
|
22
|
+
end
|
15
23
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
raise NoCallbackCalled, callbacks unless context.callback.called?
|
21
|
-
rescue NotImplementedError
|
22
|
-
raise
|
24
|
+
def result_class(klass = :reader)
|
25
|
+
@result_class = klass unless klass == :reader
|
26
|
+
defined?(@result_class) ? @result_class : ContextResult
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
|
-
|
26
|
-
@result_class = klass unless klass == :reader
|
27
|
-
defined?(@result_class) ? @result_class : ContextResult
|
28
|
-
end
|
30
|
+
attr_accessor :callback
|
29
31
|
|
30
32
|
def call
|
31
33
|
raise NotImplementedError
|
@@ -33,7 +35,7 @@ module Neo
|
|
33
35
|
|
34
36
|
class NoCallbackCalled < StandardError
|
35
37
|
def initialize(callbacks)
|
36
|
-
super("No callback called. Available callbacks: #{callbacks.join(
|
38
|
+
super("No callback called. Available callbacks: #{callbacks.join(", ")}")
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/neo/dci/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A compatible delegation that works on Ruby 2.6, 2.7 and Ruby 3:
|
2
|
+
#
|
3
|
+
# ruby2_keywords def foo(*args, &block)
|
4
|
+
# target(*args, &block)
|
5
|
+
# end
|
6
|
+
#
|
7
|
+
# Ruby <= 2.6 does not handle the new delegation style correctly, so the old-style delegation
|
8
|
+
# must be used.
|
9
|
+
#
|
10
|
+
# `ruby2_keywords` allows you to run the old style even in Ruby 2.7 and 3.0.
|
11
|
+
#
|
12
|
+
# More informations:
|
13
|
+
# https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
|
14
|
+
#
|
15
|
+
# Discussion about adding `ruby2_keywords` semantics by default in 2.7.1:
|
16
|
+
# https://bugs.ruby-lang.org/issues/16463
|
17
|
+
#
|
18
|
+
#
|
19
|
+
# We need to remove this method if we no longer support Ruby versions < 2.7.
|
20
|
+
#
|
21
|
+
module Kernel
|
22
|
+
def ruby2_keywords(*)
|
23
|
+
end if RUBY_VERSION < "2.7"
|
24
|
+
end
|
data/neo-dci.gemspec
CHANGED
@@ -15,11 +15,12 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Neo::DCI::VERSION
|
17
17
|
|
18
|
-
gem.add_runtime_dependency 'on', '~> 0.
|
18
|
+
gem.add_runtime_dependency 'on', '~> 1.0.0'
|
19
19
|
|
20
20
|
gem.add_development_dependency 'rake'
|
21
21
|
gem.add_development_dependency 'rdoc'
|
22
22
|
gem.add_development_dependency 'minitest'
|
23
23
|
gem.add_development_dependency 'testem'
|
24
24
|
gem.add_development_dependency 'simplecov'
|
25
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
|
25
26
|
end
|
data/test/context_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
class ContextTest < NeoDCICase
|
4
4
|
class TestContext < Neo::DCI::Context
|
@@ -17,7 +17,7 @@ class ContextTest < NeoDCICase
|
|
17
17
|
assert_raises NotImplementedError do
|
18
18
|
Class.new(Neo::DCI::Context) do
|
19
19
|
callbacks :foo
|
20
|
-
end.call {}
|
20
|
+
end.call { }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -41,7 +41,7 @@ class ContextTest < NeoDCICase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
assert_equal true, block_called
|
44
|
-
assert_equal [
|
44
|
+
assert_equal [:foo, :bar], result
|
45
45
|
end
|
46
46
|
|
47
47
|
test "ensure callback called" do
|
@@ -63,8 +63,8 @@ class ContextTest < NeoDCICase
|
|
63
63
|
context1 = Class.new(TestContext) { callbacks :foo }
|
64
64
|
context2 = Class.new(TestContext) { callbacks :bar }
|
65
65
|
|
66
|
-
assert_equal [
|
67
|
-
assert_equal [
|
66
|
+
assert_equal [:foo], context1.callbacks
|
67
|
+
assert_equal [:bar], context2.callbacks
|
68
68
|
end
|
69
69
|
|
70
70
|
test "define own context result class" do
|
@@ -99,4 +99,86 @@ class ContextTest < NeoDCICase
|
|
99
99
|
|
100
100
|
assert_equal :ok, $success_callback_arg
|
101
101
|
end
|
102
|
+
|
103
|
+
test "pass attributes and kwargs do context" do
|
104
|
+
context = Class.new(TestContext) do
|
105
|
+
callbacks :success
|
106
|
+
|
107
|
+
def initialize(attribute, kwarg:)
|
108
|
+
@attribute = attribute
|
109
|
+
@kwarg = kwarg
|
110
|
+
end
|
111
|
+
|
112
|
+
def call
|
113
|
+
callback.call :success, @attribute, @kwarg
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context.call("attribute", kwarg: "kwarg") do |result|
|
118
|
+
result.on :success do |attr, kwarg|
|
119
|
+
assert_equal "attribute", attr
|
120
|
+
assert_equal "kwarg", kwarg
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
test "pass only attributes do context" do
|
126
|
+
context = Class.new(TestContext) do
|
127
|
+
callbacks :success
|
128
|
+
|
129
|
+
def initialize(attribute)
|
130
|
+
@attribute = attribute
|
131
|
+
end
|
132
|
+
|
133
|
+
def call
|
134
|
+
callback.call :success, @attribute
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context.call("attribute") do |result|
|
139
|
+
result.on :success do |attr|
|
140
|
+
assert_equal "attribute", attr
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
test "pass hash as attribute do context" do
|
146
|
+
context = Class.new(TestContext) do
|
147
|
+
callbacks :success
|
148
|
+
|
149
|
+
def initialize(uid, attribute)
|
150
|
+
@attribute = attribute
|
151
|
+
end
|
152
|
+
|
153
|
+
def call
|
154
|
+
callback.call :success, @attribute
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context.call("1", {}) do |result|
|
159
|
+
result.on :success do |attr|
|
160
|
+
assert_equal ({}), attr
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
test "pass only kwargs do context" do
|
166
|
+
context = Class.new(TestContext) do
|
167
|
+
callbacks :success
|
168
|
+
|
169
|
+
def initialize(kwarg:)
|
170
|
+
@kwarg = kwarg
|
171
|
+
end
|
172
|
+
|
173
|
+
def call
|
174
|
+
callback.call :success, @kwarg
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context.call(kwarg: "kwarg") do |result|
|
179
|
+
result.on :success do |kwarg|
|
180
|
+
assert_equal "kwarg", kwarg
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
102
184
|
end
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo-dci
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Suschlik
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-06-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: 'on'
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.
|
28
|
+
version: 1.0.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rake
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,6 +96,20 @@ dependencies:
|
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: codeclimate-test-reporter
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 1.0.0
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 1.0.0
|
99
113
|
description: Simple DCI
|
100
114
|
email:
|
101
115
|
- ps@neopoly.de
|
@@ -120,6 +134,7 @@ files:
|
|
120
134
|
- lib/neo/dci/role.rb
|
121
135
|
- lib/neo/dci/task_loader.rb
|
122
136
|
- lib/neo/dci/version.rb
|
137
|
+
- lib/ruby2_keywords.rb
|
123
138
|
- lib/tasks/neo-dci_tasks.rake
|
124
139
|
- lib/tasks/share/app/contexts/context.rb
|
125
140
|
- lib/tasks/share/app/roles/role.rb
|
@@ -145,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
160
|
- !ruby/object:Gem::Version
|
146
161
|
version: '0'
|
147
162
|
requirements: []
|
148
|
-
|
149
|
-
rubygems_version: 2.5.1
|
163
|
+
rubygems_version: 3.1.2
|
150
164
|
signing_key:
|
151
165
|
specification_version: 4
|
152
166
|
summary: Includes Data, Roles and Context.
|