jace 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +25 -1
- data/.rubocop.yml +1 -0
- data/README.md +1 -1
- data/config/check_specs.yml +1 -0
- data/config/yardstick.yml +1 -1
- data/lib/jace.rb +3 -2
- data/lib/jace/dispatcher.rb +38 -0
- data/lib/jace/version.rb +1 -1
- data/scripts/build.sh +47 -0
- data/spec/lib/jace/dispatcher_spec.rb +157 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a538f92589b4feb4a08d1f8521f93c34979c1e5e80b14edb7aaeeec6c05e66a0
|
4
|
+
data.tar.gz: 1de3fa76bdbf09d5488cec3e09ec4a6074377c2134ccd3311591057bd45e1903
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b6d12aa27caa2ee4db4ef93404b40aea0b1d5cf5a581ab309f588b79a5390aaa1baa1ea399bd9fe8b771ee2bc354f7dc5b53456e5bdf2f1a06092a4c881e913
|
7
|
+
data.tar.gz: a6a260fefb1cae9ed26d8643961456dd1a7d90186bfddf92aaaa0af86b71c0b21a1edbd8e717fd947f55037f32a1abbd413af9814c1a716eb81afea526ab5f25
|
data/.circleci/config.yml
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
version: 2
|
2
|
+
workflows:
|
3
|
+
version: 2
|
4
|
+
test:
|
5
|
+
jobs:
|
6
|
+
- build-and-release
|
2
7
|
jobs:
|
3
|
-
|
8
|
+
test:
|
4
9
|
docker:
|
5
10
|
- image: darthjee/circleci_ruby_gems:0.5.2
|
6
11
|
environment:
|
@@ -34,3 +39,22 @@ jobs:
|
|
34
39
|
- run:
|
35
40
|
name: Check unit tests
|
36
41
|
command: check_specs
|
42
|
+
build-and-release:
|
43
|
+
docker:
|
44
|
+
- image: darthjee/circleci_ruby_gems:0.5.2
|
45
|
+
environment:
|
46
|
+
PROJECT: jace
|
47
|
+
steps:
|
48
|
+
- checkout
|
49
|
+
- run:
|
50
|
+
name: Signin
|
51
|
+
command: scripts/build.sh signin
|
52
|
+
- run:
|
53
|
+
name: Degub
|
54
|
+
command: cat ~/.gem/credentials
|
55
|
+
- run:
|
56
|
+
name: Build Gem
|
57
|
+
command: scripts/build.sh build
|
58
|
+
- run:
|
59
|
+
name: Push Gem
|
60
|
+
command: scripts/build.sh push
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Sinclair
|
|
11
11
|
|
12
12
|
Yard Documentation
|
13
13
|
-------------------
|
14
|
-
[https://www.rubydoc.info/gems/jace/0.0.
|
14
|
+
[https://www.rubydoc.info/gems/jace/0.0.3](https://www.rubydoc.info/gems/jace/0.0.3)
|
15
15
|
|
16
16
|
Installation
|
17
17
|
---------------
|
data/config/check_specs.yml
CHANGED
data/config/yardstick.yml
CHANGED
data/lib/jace.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jace
|
4
|
+
# @api public
|
5
|
+
# @author Darthjee
|
6
|
+
#
|
7
|
+
# Class responsible for dispatching the call of events
|
8
|
+
class Dispatcher
|
9
|
+
# @param before [Symbol,Proc,Array] all the methods / proc
|
10
|
+
# to be executed before block call
|
11
|
+
# @param after [Symbol,Proc,Array] all the methods / proc
|
12
|
+
# to be executed after block call
|
13
|
+
def initialize(before: [], after: [])
|
14
|
+
@before = [before].flatten.compact
|
15
|
+
@after = [after].flatten.compact
|
16
|
+
end
|
17
|
+
|
18
|
+
# Dispatch the event call on a context
|
19
|
+
#
|
20
|
+
# @param context [Object] Object where the procs / methods
|
21
|
+
# will be called on
|
22
|
+
# @block [Proc] bloc to be performed between befores and afters
|
23
|
+
#
|
24
|
+
# @return [Object] result of block call
|
25
|
+
def dispatch(context, &block)
|
26
|
+
Executer.call(
|
27
|
+
before: before,
|
28
|
+
after: after,
|
29
|
+
context: context,
|
30
|
+
&block
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :before, :after
|
37
|
+
end
|
38
|
+
end
|
data/lib/jace/version.rb
CHANGED
data/scripts/build.sh
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
function version() {
|
4
|
+
echo $(cat lib/$PROJECT/version.rb | grep VERSION | sed -e "s/.*'\\(.*\\)'.*/\\1/g")
|
5
|
+
}
|
6
|
+
|
7
|
+
function isTagged() {
|
8
|
+
VERSION=$(version)
|
9
|
+
TAG=$(git tag | tail -n 1)
|
10
|
+
|
11
|
+
if [ $VERSION = $TAG ]; then
|
12
|
+
return 0
|
13
|
+
else
|
14
|
+
return 1
|
15
|
+
fi
|
16
|
+
}
|
17
|
+
|
18
|
+
ACTION=$1
|
19
|
+
|
20
|
+
case $ACTION in
|
21
|
+
"signin")
|
22
|
+
mkdir ~/.gem
|
23
|
+
echo "---" > ~/.gem/credentials
|
24
|
+
echo ":rubygems_api_key: $RUBY_GEMS_API_KEY" >> ~/.gem/credentials
|
25
|
+
chmod 600 ~/.gem/credentials
|
26
|
+
;;
|
27
|
+
"build")
|
28
|
+
if $(isTagged); then
|
29
|
+
rake build
|
30
|
+
else
|
31
|
+
echo version did not change
|
32
|
+
fi
|
33
|
+
;;
|
34
|
+
"push")
|
35
|
+
if $(isTagged); then
|
36
|
+
VERSION=$(version)
|
37
|
+
gem push "pkg/$PROJECT-$VERSION.gem"
|
38
|
+
else
|
39
|
+
echo version did not change
|
40
|
+
fi
|
41
|
+
;;
|
42
|
+
*)
|
43
|
+
echo Usage:
|
44
|
+
echo "$0 build # builds gem"
|
45
|
+
echo "$0 push # pushes gem"
|
46
|
+
;;
|
47
|
+
esac
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Jace::Dispatcher do
|
6
|
+
subject(:dispatcher) do
|
7
|
+
described_class.new(
|
8
|
+
before: before,
|
9
|
+
after: after
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:before) { nil }
|
14
|
+
let(:after) { nil }
|
15
|
+
let(:person) { Person.new }
|
16
|
+
|
17
|
+
describe '#dispatch' do
|
18
|
+
context 'without before or after' do
|
19
|
+
let(:result) do
|
20
|
+
described_class.new.dispatch(person) { 10 }
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns re result of block call' do
|
24
|
+
expect(result).to eq(10)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'executes in current context ignoring given context' do
|
28
|
+
expect(described_class.new.dispatch(person) { self })
|
29
|
+
.to eq(self)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with before option' do
|
34
|
+
context 'with symbol' do
|
35
|
+
let(:before) { :init_age }
|
36
|
+
|
37
|
+
let(:result) do
|
38
|
+
dispatcher.dispatch(person) { person.age }
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns result after running before code' do
|
42
|
+
expect(result).to eq(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'changes state of context object' do
|
46
|
+
expect { result }.to change(person, :age)
|
47
|
+
.from(nil).to(1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with block' do
|
52
|
+
let(:block) { proc { @age = 10 } }
|
53
|
+
let(:before) { block }
|
54
|
+
|
55
|
+
let(:result) do
|
56
|
+
dispatcher.dispatch(person) { person.age }
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns result after running before code' do
|
60
|
+
expect(result).to eq(10)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'changes state of context object' do
|
64
|
+
expect { result }.to change(person, :age)
|
65
|
+
.from(nil).to(10)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with array' do
|
70
|
+
let(:block) { proc { @brothers = @age ? 2 : 10 } }
|
71
|
+
let(:before) { [:init_age, block] }
|
72
|
+
|
73
|
+
let(:result) do
|
74
|
+
dispatcher.dispatch(person) do
|
75
|
+
person.age + person.brothers
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns result after running all before code' do
|
80
|
+
expect(result).to eq(3)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'changes state of context object by block call' do
|
84
|
+
expect { result }.to change(person, :brothers)
|
85
|
+
.from(0).to(2)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'changes state of context object by method call' do
|
89
|
+
expect { result }.to change(person, :age)
|
90
|
+
.from(nil).to(1)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'with after option' do
|
96
|
+
context 'with symbol' do
|
97
|
+
let(:after) { :init_age }
|
98
|
+
|
99
|
+
let(:result) do
|
100
|
+
dispatcher.dispatch(person) { person.age }
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns result before running after code' do
|
104
|
+
expect(result).to be_nil
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'changes state of context object' do
|
108
|
+
expect { result }.to change(person, :age)
|
109
|
+
.from(nil).to(1)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'with block' do
|
114
|
+
let(:block) { proc { @age = 10 } }
|
115
|
+
let(:after) { block }
|
116
|
+
|
117
|
+
let(:result) do
|
118
|
+
dispatcher.dispatch(person) { person.age }
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'returns result before running after code' do
|
122
|
+
expect(result).to be_nil
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'changes state of context object' do
|
126
|
+
expect { result }.to change(person, :age)
|
127
|
+
.from(nil).to(10)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'with array' do
|
132
|
+
let(:block) { proc { @brothers = @age ? 2 : 10 } }
|
133
|
+
let(:after) { [:init_age, block] }
|
134
|
+
|
135
|
+
let(:result) do
|
136
|
+
dispatcher.dispatch(person) do
|
137
|
+
person.age.to_i + person.brothers
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'returns result before running all after code' do
|
142
|
+
expect(result).to eq(0)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'changes state of context object by block call' do
|
146
|
+
expect { result }.to change(person, :brothers)
|
147
|
+
.from(0).to(2)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'changes state of context object by method call' do
|
151
|
+
expect { result }.to change(person, :age)
|
152
|
+
.from(nil).to(1)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarthJee
|
@@ -259,10 +259,13 @@ files:
|
|
259
259
|
- jace.gemspec
|
260
260
|
- jace.jpg
|
261
261
|
- lib/jace.rb
|
262
|
+
- lib/jace/dispatcher.rb
|
262
263
|
- lib/jace/executer.rb
|
263
264
|
- lib/jace/version.rb
|
265
|
+
- scripts/build.sh
|
264
266
|
- spec/integration/readme/.keep
|
265
267
|
- spec/integration/yard/.keep
|
268
|
+
- spec/lib/jace/dispatcher_spec.rb
|
266
269
|
- spec/lib/jace/executer_spec.rb
|
267
270
|
- spec/spec_helper.rb
|
268
271
|
- spec/support/models/.keep
|