neo-dci 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4a0fd6e30874980cc150a48995e912165343d425fc24254e0f3f9b97e49fdf13
4
+ data.tar.gz: bfa3c369b56c93a5e4ecfc7c915e26f6c52655245e4d5ea979280e70279e4f71
5
+ SHA512:
6
+ metadata.gz: f53b2c7652fa22003c46c002d2ebd2b717d4290294017c3c73cd85b6accf1a2abcb122c6c68b8c29508f1178209d1432f2b95a2b4c509ffcb5e93fa42bd3d1b2
7
+ data.tar.gz: 2aca570d841b0898e41e7138048abf5e9fc3a36c961d11ff3213db1db7dd580c147426967330f10e8faa88395132fa6b0b5fb38968f304657419127bbb38c2e7
@@ -1,5 +1,30 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  rvm:
3
- - 1.9.3
4
- - jruby-19mode
5
- - rbx-19mode
5
+ - ruby-head
6
+ - 2.7.0
7
+ - 2.6
8
+ - 2.5
9
+ - jruby
10
+ - jruby-head
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: jruby
14
+ - rvm: jruby-head
15
+ - rvm: ruby-head
16
+ env:
17
+ global:
18
+ - CODECLIMATE_REPO_TOKEN=70820b2c9137bc6411ae1a2e0c6861028c70ce373eec87ad46d9b7c14dce3401
19
+ - JRUBY_OPTS='--dev -J-Xmx1024M'
20
+ matrix:
21
+ allow_failures:
22
+ - rvm: ruby-head
23
+ - rvm: jruby-head
24
+ notifications:
25
+ webhooks:
26
+ urls:
27
+ - https://webhooks.gitter.im/e/556fa7e78f49c2f0016e
28
+ on_success: change # options: [always|never|change] default: always
29
+ on_failure: always # options: [always|never|change] default: always
30
+ on_start: false # default: false
data/README.md CHANGED
@@ -1,11 +1,24 @@
1
- # Neo::DCI [![Build Status](https://secure.travis-ci.org/neopoly/neo-dci.png?branch=master)](http://travis-ci.org/neopoly/neo-dci)
1
+ [github]: https://github.com/neopoly/neo-dci
2
+ [doc]: http://rubydoc.info/github/neopoly/neo-dci/master/file/README.md
3
+ [gem]: https://rubygems.org/gems/neo-dci
4
+ [travis]: https://travis-ci.org/neopoly/neo-dci
5
+ [codeclimate]: https://codeclimate.com/github/neopoly/neo-dci
6
+ [inchpages]: https://inch-ci.org/github/neopoly/neo-dci
7
+
8
+ # Neo::DCI
2
9
 
3
10
  Simple DCI (Data Context Interaction).
4
11
  Includes Data, Roles and Context.
5
12
 
6
- [Gem](https://rubygems.org/gems/neo-dci) |
7
- [Source](https://github.com/neopoly/neo-dci) |
8
- [Documentation](http://rubydoc.info/github/neopoly/neo-dci/master/file/README.md)
13
+ [![Travis](https://img.shields.io/travis/neopoly/neo-dci.svg?branch=master)][travis]
14
+ [![Gem Version](https://img.shields.io/gem/v/neo-dci.svg)][gem]
15
+ [![Code Climate](https://img.shields.io/codeclimate/github/neopoly/neo-dci.svg)][codeclimate]
16
+ [![Test Coverage](https://codeclimate.com/github/neopoly/neo-dci/badges/coverage.svg)][codeclimate]
17
+ [![Inline docs](https://inch-ci.org/github/neopoly/neo-dci.svg?branch=master&style=flat)][inchpages]
18
+
19
+ [Gem][gem] |
20
+ [Source][github] |
21
+ [Documentation][doc]
9
22
 
10
23
  ## Installation
11
24
 
@@ -95,8 +108,8 @@ end
95
108
 
96
109
  ## Contributing
97
110
 
98
- 1. Fork it
111
+ 1. Fork it ( https://github.com/neopoly/neo-dci/fork )
99
112
  2. Create your feature branch (`git checkout -b my-new-feature`)
100
- 3. Commit your changes (`git commit -am 'Added some feature'`)
113
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
101
114
  4. Push to the branch (`git push origin my-new-feature`)
102
- 5. Create new Pull Request
115
+ 5. Create a new Pull Request
@@ -1,7 +1,12 @@
1
+ module Neo
2
+ module DCI
3
+ end
4
+ end
5
+
1
6
  require 'neo/dci/version'
2
-
3
7
  require 'neo/dci/data'
4
8
  require 'neo/dci/role'
5
9
  require 'neo/dci/context'
10
+ require 'neo/dci/context_result'
6
11
 
7
12
  require 'neo/dci/task_loader' if defined?(::Rails::Railtie)
@@ -1,36 +1,41 @@
1
- require 'on'
1
+ require "ruby2_keywords"
2
2
 
3
3
  module Neo
4
4
  module DCI
5
5
  class Context
6
6
  class << self
7
7
  private :new
8
- end
9
8
 
10
- attr_accessor :callback
9
+ def callbacks(*args)
10
+ @callbacks ||= []
11
+ @callbacks = args unless args.empty?
12
+ @callbacks
13
+ end
11
14
 
12
- def self.callbacks(*args)
13
- @callbacks ||= []
14
- @callbacks = args unless args.empty?
15
- @callbacks
16
- end
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
17
23
 
18
- def self.call(*args, &block)
19
- context = new(*args)
20
- context.callback = On.new(*callbacks, &block)
21
- context.call
22
- raise NoCallbackCalled, callbacks unless context.callback.callback
23
- rescue NotImplementedError
24
- raise
24
+ def result_class(klass = :reader)
25
+ @result_class = klass unless klass == :reader
26
+ defined?(@result_class) ? @result_class : ContextResult
27
+ end
25
28
  end
26
29
 
30
+ attr_accessor :callback
31
+
27
32
  def call
28
33
  raise NotImplementedError
29
34
  end
30
35
 
31
36
  class NoCallbackCalled < StandardError
32
37
  def initialize(callbacks)
33
- super("No callback called. Available callbacks: #{callbacks.join(', ')}")
38
+ super("No callback called. Available callbacks: #{callbacks.join(", ")}")
34
39
  end
35
40
  end
36
41
  end
@@ -0,0 +1,12 @@
1
+ require 'on'
2
+
3
+ module Neo
4
+ module DCI
5
+ # Result emitted by the Context.
6
+ class ContextResult < On
7
+ def called?
8
+ !!callback
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Neo
2
2
  module DCI
3
- VERSION = "0.3.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -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
@@ -15,10 +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', '~> 1.0.0'
19
+
18
20
  gem.add_development_dependency 'rake'
19
21
  gem.add_development_dependency 'rdoc'
20
22
  gem.add_development_dependency 'minitest'
21
23
  gem.add_development_dependency 'testem'
22
24
  gem.add_development_dependency 'simplecov'
23
- gem.add_development_dependency 'on', '~> 0.2.0'
25
+ gem.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
24
26
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
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 [ :foo, :bar ], result
44
+ assert_equal [:foo, :bar], result
45
45
  end
46
46
 
47
47
  test "ensure callback called" do
@@ -63,7 +63,122 @@ class ContextTest < NeoDCICase
63
63
  context1 = Class.new(TestContext) { callbacks :foo }
64
64
  context2 = Class.new(TestContext) { callbacks :bar }
65
65
 
66
- assert_equal [ :foo ], context1.callbacks
67
- assert_equal [ :bar ], context2.callbacks
66
+ assert_equal [:foo], context1.callbacks
67
+ assert_equal [:bar], context2.callbacks
68
+ end
69
+
70
+ test "define own context result class" do
71
+ $success_callback_arg = nil
72
+
73
+ listener = Class.new do
74
+ def register_callbacks(result)
75
+ result.on :success do |arg|
76
+ $success_callback_arg = arg
77
+ end
78
+ end
79
+ end
80
+
81
+ context_result = Class.new(Neo::DCI::ContextResult) do
82
+ def register(listener)
83
+ listener.register_callbacks(self)
84
+ end
85
+ end
86
+
87
+ context = Class.new(TestContext) do
88
+ callbacks :success
89
+ result_class context_result
90
+
91
+ def call
92
+ callback.call :success, :ok
93
+ end
94
+ end
95
+
96
+ context.call do |my_result|
97
+ my_result.register listener.new
98
+ end
99
+
100
+ assert_equal :ok, $success_callback_arg
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
68
183
  end
69
184
  end
@@ -1,4 +1,5 @@
1
- require 'simplecov' if ENV['COVERAGE']
1
+ require "simplecov"
2
+ SimpleCov.start
2
3
 
3
4
  require 'minitest/autorun'
4
5
  require 'testem'
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo-dci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Suschlik
@@ -11,104 +10,106 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2012-11-29 00:00:00.000000000 Z
13
+ date: 2020-06-26 00:00:00.000000000 Z
15
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: 'on'
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 1.0.0
16
29
  - !ruby/object:Gem::Dependency
17
30
  name: rake
18
31
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
32
  requirements:
21
- - - ! '>='
33
+ - - ">="
22
34
  - !ruby/object:Gem::Version
23
35
  version: '0'
24
36
  type: :development
25
37
  prerelease: false
26
38
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
39
  requirements:
29
- - - ! '>='
40
+ - - ">="
30
41
  - !ruby/object:Gem::Version
31
42
  version: '0'
32
43
  - !ruby/object:Gem::Dependency
33
44
  name: rdoc
34
45
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
46
  requirements:
37
- - - ! '>='
47
+ - - ">="
38
48
  - !ruby/object:Gem::Version
39
49
  version: '0'
40
50
  type: :development
41
51
  prerelease: false
42
52
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
53
  requirements:
45
- - - ! '>='
54
+ - - ">="
46
55
  - !ruby/object:Gem::Version
47
56
  version: '0'
48
57
  - !ruby/object:Gem::Dependency
49
58
  name: minitest
50
59
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
60
  requirements:
53
- - - ! '>='
61
+ - - ">="
54
62
  - !ruby/object:Gem::Version
55
63
  version: '0'
56
64
  type: :development
57
65
  prerelease: false
58
66
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
67
  requirements:
61
- - - ! '>='
68
+ - - ">="
62
69
  - !ruby/object:Gem::Version
63
70
  version: '0'
64
71
  - !ruby/object:Gem::Dependency
65
72
  name: testem
66
73
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
74
  requirements:
69
- - - ! '>='
75
+ - - ">="
70
76
  - !ruby/object:Gem::Version
71
77
  version: '0'
72
78
  type: :development
73
79
  prerelease: false
74
80
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
81
  requirements:
77
- - - ! '>='
82
+ - - ">="
78
83
  - !ruby/object:Gem::Version
79
84
  version: '0'
80
85
  - !ruby/object:Gem::Dependency
81
86
  name: simplecov
82
87
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
88
  requirements:
85
- - - ! '>='
89
+ - - ">="
86
90
  - !ruby/object:Gem::Version
87
91
  version: '0'
88
92
  type: :development
89
93
  prerelease: false
90
94
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
95
  requirements:
93
- - - ! '>='
96
+ - - ">="
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0'
96
99
  - !ruby/object:Gem::Dependency
97
- name: 'on'
100
+ name: codeclimate-test-reporter
98
101
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
102
  requirements:
101
- - - ~>
103
+ - - "~>"
102
104
  - !ruby/object:Gem::Version
103
- version: 0.2.0
105
+ version: 1.0.0
104
106
  type: :development
105
107
  prerelease: false
106
108
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
109
  requirements:
109
- - - ~>
110
+ - - "~>"
110
111
  - !ruby/object:Gem::Version
111
- version: 0.2.0
112
+ version: 1.0.0
112
113
  description: Simple DCI
113
114
  email:
114
115
  - ps@neopoly.de
@@ -118,9 +119,9 @@ executables: []
118
119
  extensions: []
119
120
  extra_rdoc_files: []
120
121
  files:
121
- - .gitignore
122
- - .simplecov
123
- - .travis.yml
122
+ - ".gitignore"
123
+ - ".simplecov"
124
+ - ".travis.yml"
124
125
  - Gemfile
125
126
  - LICENSE
126
127
  - README.md
@@ -128,10 +129,12 @@ files:
128
129
  - lib/neo-dci.rb
129
130
  - lib/neo/dci.rb
130
131
  - lib/neo/dci/context.rb
132
+ - lib/neo/dci/context_result.rb
131
133
  - lib/neo/dci/data.rb
132
134
  - lib/neo/dci/role.rb
133
135
  - lib/neo/dci/task_loader.rb
134
136
  - lib/neo/dci/version.rb
137
+ - lib/ruby2_keywords.rb
135
138
  - lib/tasks/neo-dci_tasks.rake
136
139
  - lib/tasks/share/app/contexts/context.rb
137
140
  - lib/tasks/share/app/roles/role.rb
@@ -141,33 +144,25 @@ files:
141
144
  - test/role_test.rb
142
145
  homepage: https://github.com/neopoly/neo-dci
143
146
  licenses: []
147
+ metadata: {}
144
148
  post_install_message:
145
149
  rdoc_options: []
146
150
  require_paths:
147
151
  - lib
148
152
  required_ruby_version: !ruby/object:Gem::Requirement
149
- none: false
150
153
  requirements:
151
- - - ! '>='
154
+ - - ">="
152
155
  - !ruby/object:Gem::Version
153
156
  version: '0'
154
- segments:
155
- - 0
156
- hash: -3362418473646590166
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
- none: false
159
158
  requirements:
160
- - - ! '>='
159
+ - - ">="
161
160
  - !ruby/object:Gem::Version
162
161
  version: '0'
163
- segments:
164
- - 0
165
- hash: -3362418473646590166
166
162
  requirements: []
167
- rubyforge_project:
168
- rubygems_version: 1.8.24
163
+ rubygems_version: 3.1.2
169
164
  signing_key:
170
- specification_version: 3
165
+ specification_version: 4
171
166
  summary: Includes Data, Roles and Context.
172
167
  test_files:
173
168
  - test/context_test.rb