edrive 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/README.md +18 -24
- data/lib/edrive/processor_dispatcher.rb +49 -47
- data/lib/edrive/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e47a7b77728080f4f992e78d32b84fdb2f60af0e994c1fe0439abb04649e5d7e
|
4
|
+
data.tar.gz: 9e8d01b77f338210e9ecbda9b7b17938016dd1af1da0470a69d82b253193a2f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aece7fc70c84065b5ac8d59da7b5f3e488d8ed5d2a4cd8ae98ff81db17c7c4cda27deac99607c96d49296b91186bcbc91c0656902f43823fed6dddddb39e0ceb
|
7
|
+
data.tar.gz: 2b1a6657d6ed38a580a27e19ea0e0f1c11a58746da9f154ef734d2bd0b051d8682a1d1b842cec9bb7bc8835c4aaf75d9cee5b00bac9e3af41c7b246290269067
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# edrive
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/edrive)
|
4
|
-
[](https://circleci.com/gh/MichinaoShimizu/edrive)
|
5
|
-
[](https://codeclimate.com/github/MichinaoShimizu/edrive/maintainability)
|
6
4
|
|
7
5
|
Provide simple event dispatcher mechanism for all of ruby products.
|
8
6
|
|
@@ -26,6 +24,8 @@ Or install it yourself as:
|
|
26
24
|
|
27
25
|
### Edrive::Dispatcher
|
28
26
|
|
27
|
+
main class
|
28
|
+
|
29
29
|
#### lambda & dispatch
|
30
30
|
|
31
31
|
```ruby
|
@@ -79,9 +79,21 @@ dispatcher.dispatch_with_data(:event, 100)
|
|
79
79
|
106
|
80
80
|
```
|
81
81
|
|
82
|
+
### clear target event
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
dispatcher.clear!(:event)
|
86
|
+
```
|
87
|
+
|
88
|
+
### clear all event
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
dispatcher.clear_all!
|
92
|
+
```
|
93
|
+
|
82
94
|
### Edrive::ProcessorDispatcher
|
83
95
|
|
84
|
-
Event dispatcher for processor class inherited `Edrive::Dispatcher
|
96
|
+
Event dispatcher for processor class inherited `Edrive::Dispatcher`.
|
85
97
|
|
86
98
|
Use `:before_process`, `:after_process` events only in this class.
|
87
99
|
|
@@ -101,7 +113,7 @@ This class has `dispatch_all` method.
|
|
101
113
|
|
102
114
|
### Edrive::Handler
|
103
115
|
|
104
|
-
sample event handlers.
|
116
|
+
sample event handlers class.
|
105
117
|
|
106
118
|
```ruuby
|
107
119
|
require 'edrive'
|
@@ -112,27 +124,9 @@ dispatcher.subscribe(:before, Edrive::Handler.json2hash)
|
|
112
124
|
puts dispatcher.dispatch_with_data(:before, hoge: 2, fuga: 3)
|
113
125
|
```
|
114
126
|
|
115
|
-
### clear target event
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
dispatcher.clear!(:event)
|
119
|
-
```
|
120
|
-
|
121
|
-
### clear all event
|
122
|
-
|
123
|
-
```ruby
|
124
|
-
dispatcher.clear_all!
|
125
|
-
```
|
126
|
-
|
127
|
-
## Development
|
128
|
-
|
129
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
130
|
-
|
131
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
132
|
-
|
133
127
|
## Contributing
|
134
128
|
|
135
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
129
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/MichinaoShimizu/edrive. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
136
130
|
|
137
131
|
## License
|
138
132
|
|
@@ -140,4 +134,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
140
134
|
|
141
135
|
## Code of Conduct
|
142
136
|
|
143
|
-
Everyone interacting in the Edrive project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
137
|
+
Everyone interacting in the Edrive project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/MichinaoShimizu/edrive/blob/master/CODE_OF_CONDUCT.md).
|
@@ -6,61 +6,63 @@ require 'edrive/dispatcher'
|
|
6
6
|
# @attr [Processor] processor processor object
|
7
7
|
# @attr [Symbol] processor_process processor main method symbol
|
8
8
|
# @author shimimi
|
9
|
-
|
10
|
-
|
9
|
+
module Edrive
|
10
|
+
class ProcessorDispatcher < Edrive::Dispatcher
|
11
|
+
attr_accessor :processor, :processor_process
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
# @return [Array] defined event symbols
|
14
|
+
DEFINED_EVENT = %i[before_process after_process].freeze
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
# @return [Symbol] default processor process symbol
|
17
|
+
DEFAULT_PROCESSOR_PROCESS = :process
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
# Initialize
|
20
|
+
# @param [Processor] processor processor object
|
21
|
+
# @param [Symbol] processor_process processor main method
|
22
|
+
def initialize(processor, processor_process = DEFAULT_PROCESSOR_PROCESS)
|
23
|
+
super()
|
24
|
+
@processor = processor
|
25
|
+
@processor_process = processor_process
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
# subscribe handler (proc, lambda, block)
|
29
|
+
# @param [Symbol] event event name symbol
|
30
|
+
# @param [Proc] handler handler (lambda, proc)
|
31
|
+
# @param [Block] block handler (block)
|
32
|
+
# @raise ArgumentError
|
33
|
+
# @return [Array] registered handler list
|
34
|
+
def subscribe(event, handler = nil, &block)
|
35
|
+
undefined_event_protect(event)
|
36
|
+
super
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
# Dispatch all events
|
40
|
+
# @param [Boolean] use_result use processor process result in after_process event
|
41
|
+
# @return [Mixed] last subscriber return value
|
42
|
+
def dispatch_all(use_result = true)
|
43
|
+
dispatch(DEFINED_EVENT[0])
|
44
|
+
if use_result
|
45
|
+
result = dispatch_processor_process
|
46
|
+
return dispatch_with_data(DEFINED_EVENT[1], result)
|
47
|
+
end
|
48
|
+
dispatch_processor_process
|
49
|
+
dispatch(DEFINED_EVENT[1])
|
46
50
|
end
|
47
|
-
dispatch_processor_process
|
48
|
-
dispatch(DEFINED_EVENT[1])
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
# Dispach processor process
|
53
|
+
# @param [Mixed] args
|
54
|
+
# @return [Mixed] processor process return value
|
55
|
+
def dispatch_processor_process(*args)
|
56
|
+
processor.send(processor_process, *args)
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
+
private
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
# Check event is defined or not
|
62
|
+
# @param [Symbol] event event name symbol
|
63
|
+
# @raise ArgumentError
|
64
|
+
def undefined_event_protect(event)
|
65
|
+
raise ArgumentError, "event #{event} is not defined." unless DEFINED_EVENT.include?(event)
|
66
|
+
end
|
65
67
|
end
|
66
68
|
end
|
data/lib/edrive/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edrive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MichinaoShimizu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- ".gitignore"
|
93
93
|
- CODE_OF_CONDUCT.md
|
94
94
|
- Gemfile
|
95
|
-
- Gemfile.lock
|
96
95
|
- LICENSE.txt
|
97
96
|
- README.md
|
98
97
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
edrive (1.0.4)
|
5
|
-
oj (~> 3.6)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
diff-lcs (1.3)
|
11
|
-
oj (3.6.2)
|
12
|
-
rake (10.5.0)
|
13
|
-
rspec (3.7.0)
|
14
|
-
rspec-core (~> 3.7.0)
|
15
|
-
rspec-expectations (~> 3.7.0)
|
16
|
-
rspec-mocks (~> 3.7.0)
|
17
|
-
rspec-core (3.7.1)
|
18
|
-
rspec-support (~> 3.7.0)
|
19
|
-
rspec-expectations (3.7.0)
|
20
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
-
rspec-support (~> 3.7.0)
|
22
|
-
rspec-mocks (3.7.0)
|
23
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.7.0)
|
25
|
-
rspec-support (3.7.1)
|
26
|
-
rspec_junit_formatter (0.4.1)
|
27
|
-
rspec-core (>= 2, < 4, != 2.12.0)
|
28
|
-
|
29
|
-
PLATFORMS
|
30
|
-
ruby
|
31
|
-
|
32
|
-
DEPENDENCIES
|
33
|
-
bundler (~> 1.16)
|
34
|
-
edrive!
|
35
|
-
rake (~> 10.0)
|
36
|
-
rspec (~> 3.0)
|
37
|
-
rspec_junit_formatter (~> 0.4)
|
38
|
-
|
39
|
-
BUNDLED WITH
|
40
|
-
1.16.2
|