edrive 1.0.3 → 1.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87b602aac5580212cdda2ac42171483d375e5483cf2a3951a355258054ea68c6
4
- data.tar.gz: 8276bd2eba5c98ad4db391c872655922496994625b40d341c1ce98babdab11d8
3
+ metadata.gz: 7d15d921aedb78d60f0761a60b775f6c4b46d250501c198d17693fe83ddad71a
4
+ data.tar.gz: 8dd7c8c5b6ad755f598c624ca033e05d322648c837ab1334a20e714a874f28c1
5
5
  SHA512:
6
- metadata.gz: bf4d32b81ce17027337f76b618ad56617dba5c0b0eb4c484f0a2a1d3f8ca33f3b6cfd8f3d9cb97255862f0e661063045e3b8748fdb413f077849741c80bf2145
7
- data.tar.gz: 4faed2572abec5e1335462092541b1ce8ed316f2f9dc90196c1c85d9f8970d32a6bedbf318bb15d397d2a02ccac21e24550cc051873a9f4d1616b0e2d6209dd2
6
+ metadata.gz: 32304c9cf830abd4053f576fe3e2dea981512790f65fc028f4c3ef7cf6371136299122147c7f2c55b1ce2b61b6c48dc5b4bd7e8304c2e1e4c8711323903f2b44
7
+ data.tar.gz: e1443d02b252514f2957c6ece035ff0f4a2fb93f88fe1716ec136a8b20d1bb444bfd733757a5af9b6dc5de0003da342cdae5f8555944cc87306ef9b0a638032d
@@ -0,0 +1,61 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ # # Database setup
40
+ # - run: bundle exec rake db:create
41
+ # - run: bundle exec rake db:schema:load
42
+
43
+ # run tests!
44
+ - run:
45
+ name: run tests
46
+ command: |
47
+ mkdir /tmp/test-results
48
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
49
+
50
+ bundle exec rspec --format progress \
51
+ --format RspecJunitFormatter \
52
+ --out /tmp/test-results/rspec.xml \
53
+ --format progress \
54
+ $TEST_FILES
55
+
56
+ # collect reports
57
+ - store_test_results:
58
+ path: /tmp/test-results
59
+ - store_artifacts:
60
+ path: /tmp/test-results
61
+ destination: test-results
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- edrive (1.0.3)
4
+ edrive (1.0.4)
5
+ oj (~> 3.6)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  diff-lcs (1.3)
11
+ oj (3.6.2)
10
12
  rake (10.5.0)
11
13
  rspec (3.7.0)
12
14
  rspec-core (~> 3.7.0)
@@ -21,6 +23,8 @@ GEM
21
23
  diff-lcs (>= 1.2.0, < 2.0)
22
24
  rspec-support (~> 3.7.0)
23
25
  rspec-support (3.7.1)
26
+ rspec_junit_formatter (0.4.1)
27
+ rspec-core (>= 2, < 4, != 2.12.0)
24
28
 
25
29
  PLATFORMS
26
30
  ruby
@@ -30,6 +34,7 @@ DEPENDENCIES
30
34
  edrive!
31
35
  rake (~> 10.0)
32
36
  rspec (~> 3.0)
37
+ rspec_junit_formatter (~> 0.4)
33
38
 
34
39
  BUNDLED WITH
35
40
  1.16.2
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Edrive
1
+ # edrive
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/edrive.svg)](https://badge.fury.io/rb/edrive)
4
+ [![CircleCI](https://circleci.com/gh/MichinaoShimizu/edrive.svg?style=svg)](https://circleci.com/gh/MichinaoShimizu/edrive)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/5ad04170d3d57b928dc6/maintainability)](https://codeclimate.com/github/MichinaoShimizu/edrive/maintainability)
4
6
 
5
7
  Provide simple event dispatcher mechanism for all of ruby products.
6
8
 
@@ -22,7 +24,9 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- ### lambda & dispatch
27
+ ### Edrive::Dispatcher
28
+
29
+ #### lambda & dispatch
26
30
 
27
31
  ```ruby
28
32
  dispatcher = Edrive::Dispatcher.new
@@ -36,7 +40,7 @@ dispatcher.dispatch(:event)
36
40
  3
37
41
  ```
38
42
 
39
- ### lambda & dispatch with data
43
+ #### lambda & dispatch with data
40
44
 
41
45
  ```ruby
42
46
  dispatcher = Edrive::Dispatcher.new
@@ -49,7 +53,7 @@ dispatcher.dispatch_with_data(:event, 100)
49
53
  106
50
54
  ```
51
55
 
52
- ### block
56
+ #### block
53
57
 
54
58
  ```ruby
55
59
  dispatcher = Edrive::Dispatcher.new
@@ -63,7 +67,7 @@ dispatcher.dispatch(:event)
63
67
  3
64
68
  ```
65
69
 
66
- ### block & dispatch with data
70
+ #### block & dispatch with data
67
71
 
68
72
  ```ruby
69
73
  dispatcher = Edrive::Dispatcher.new
@@ -75,28 +79,37 @@ dispatcher.dispatch_with_data(:event, 100)
75
79
  106
76
80
  ```
77
81
 
78
- ### multi dispatch
82
+ ### Edrive::ProcessorDispatcher
79
83
 
80
- ```ruby
81
- dispatcher = Edrive::Dispatcher.new
82
- dispatcher.subscribe(:event) { puts 1 }
83
- dispatcher.multi_dispatch(3, :event)
84
+ Event dispatcher for processor class inherited `Edrive::Dispatcher` class.
84
85
 
85
- 1
86
- 1
87
- 1
88
- ```
86
+ Use `:before_process`, `:after_process` events only in this class.
89
87
 
90
- ### multi dispatch with data
88
+ This class has `dispatch_all` method.
91
89
 
92
90
  ```ruby
93
- dispatcher = Edrive::Dispatcher.new
94
- dispatcher.subscribe(:event) { |data| data + 1 }
95
- dispatcher.multi_dispatch_with_data(3, :event, 0)
91
+ def dispatch_all(use_result = true)
92
+ dispatch(DEFINED_EVENT[0])
93
+ if use_result
94
+ result = dispatch_processor_process
95
+ return dispatch_with_data(DEFINED_EVENT[1], result)
96
+ end
97
+ dispatch_processor_process
98
+ dispatch(DEFINED_EVENT[1])
99
+ end
100
+ ```
96
101
 
97
- 1
98
- 2
99
- 3
102
+ ### Edrive::Handler
103
+
104
+ sample event handlers.
105
+
106
+ ```ruuby
107
+ require 'edrive'
108
+
109
+ dispatcher = Edrive::Dispatcher.new
110
+ dispatcher.subscribe(:before, Edrive::Handler.hash2json)
111
+ dispatcher.subscribe(:before, Edrive::Handler.json2hash)
112
+ puts dispatcher.dispatch_with_data(:before, hoge: 2, fuga: 3)
100
113
  ```
101
114
 
102
115
  ### clear target event
@@ -105,7 +118,7 @@ dispatcher.multi_dispatch_with_data(3, :event, 0)
105
118
  dispatcher.clear!(:event)
106
119
  ```
107
120
 
108
- ### clean all event
121
+ ### clear all event
109
122
 
110
123
  ```ruby
111
124
  dispatcher.clear_all!
@@ -28,10 +28,12 @@ Gem::Specification.new do |spec|
28
28
  f.match(%r{^(test|spec|features)/})
29
29
  end
30
30
  end
31
- spec.bindir = 'exe'
31
+ spec.bindir = 'bin'
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ['lib']
34
+ spec.add_runtime_dependency 'oj', '~> 3.6'
34
35
  spec.add_development_dependency 'bundler', '~> 1.16'
35
36
  spec.add_development_dependency 'rake', '~> 10.0'
36
37
  spec.add_development_dependency 'rspec', '~> 3.0'
38
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
37
39
  end
@@ -1,6 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'edrive/version'
2
4
  require 'edrive/dispatcher'
5
+ require 'edrive/processor_dispatcher'
6
+ require 'edrive/handler'
3
7
 
8
+ # main module
4
9
  module Edrive
5
10
  # Your code goes here...
6
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edrive
2
4
  # Simple Event Dispatcher
3
5
  # @author Michinao Shimizu <shimizu.michinao@gmail.com>
@@ -29,18 +31,6 @@ module Edrive
29
31
  result
30
32
  end
31
33
 
32
- # multiple dispatch
33
- # @param [Integer] loop_num loop num
34
- # @param [Symbol] event event name
35
- # @param [Mixed] *args
36
- # @return [Mixed] last handler return value
37
- def multi_dispatch(loop_num, event, *args)
38
- raise ArgumentError, 'loop_num must be integer.' unless loop_num.is_a?(Integer)
39
- result = nil
40
- loop_num.times { result = dispatch(event, *args) }
41
- result
42
- end
43
-
44
34
  # dispatch specific event handlers with data
45
35
  # @param [Symbol] event event name
46
36
  # @param [Mixed] data initial value
@@ -52,19 +42,6 @@ module Edrive
52
42
  result
53
43
  end
54
44
 
55
- # multiple dispatch with data
56
- # @param [integer] loop_num loop_num
57
- # @param [Symbol] event event name
58
- # @param [Mixed] data initial value
59
- # @param [Mixed] *args
60
- # @return [Mixed] last handler return value
61
- def multi_dispatch_with_data(loop_num, event, data, *args)
62
- raise ArgumentError, 'loop_num must be integer.' unless loop_num.is_a?(Integer)
63
- result = data.dup
64
- loop_num.times { result = dispatch_with_data(event, result, *args) }
65
- result
66
- end
67
-
68
45
  # get event handlers
69
46
  # @param [Symbol] event event name symbol
70
47
  # @return [Array] registered handler list
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oj'
4
+
5
+ module Edrive
6
+ # event handlers sample
7
+ class Handler
8
+ class << self
9
+ # hash to json
10
+ # @return [Proc] proc hash to json
11
+ def hash2json
12
+ ->(hash) { Oj.dump(hash, :compat) }
13
+ end
14
+
15
+ # json to hash
16
+ # @return [JSON] proc json to hash
17
+ def json2hash
18
+ ->(json) { Oj.load(json) }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'edrive/dispatcher'
4
+
5
+ # Event Dispatcher For Processors
6
+ # @attr [Processor] processor processor object
7
+ # @attr [Symbol] processor_process processor main method symbol
8
+ # @author shimimi
9
+ class ProcessorDispatcher < Edrive::Dispatcher
10
+ attr_accessor :processor, :processor_process
11
+
12
+ # @return [Array] defined event symbols
13
+ DEFINED_EVENT = %i[before after].freeze
14
+
15
+ # @return [Symbol] default processor process symbol
16
+ DEFAULT_PROCESSOR_PROCESS = :process
17
+
18
+ # Initialize
19
+ # @param [Processor] processor processor object
20
+ # @param [Symbol] processor_process processor main method
21
+ def initialize(processor, processor_process = DEFAULT_PROCESSOR_PROCESS)
22
+ super()
23
+ @processor = processor
24
+ @processor_process = processor_process
25
+ end
26
+
27
+ # subscribe handler (proc, lambda, block)
28
+ # @param [Symbol] event event name symbol
29
+ # @param [Proc] handler handler (lambda, proc)
30
+ # @param [Block] block handler (block)
31
+ # @raise ArgumentError
32
+ # @return [Array] registered handler list
33
+ def subscribe(event, handler = nil, &block)
34
+ undefined_event_protect(event)
35
+ super
36
+ end
37
+
38
+ # Dispatch all events
39
+ # @param [Boolean] use_result use processor process result in after_process event
40
+ # @return [Mixed] last subscriber return value
41
+ def dispatch_all(use_result = true)
42
+ dispatch(DEFINED_EVENT[0])
43
+ if use_result
44
+ result = dispatch_processor_process
45
+ return dispatch_with_data(DEFINED_EVENT[1], result)
46
+ end
47
+ dispatch_processor_process
48
+ dispatch(DEFINED_EVENT[1])
49
+ end
50
+
51
+ # Dispach processor process
52
+ # @param [Mixed] args
53
+ # @return [Mixed] processor process return value
54
+ def dispatch_processor_process(*args)
55
+ processor.send(processor_process, *args)
56
+ end
57
+
58
+ private
59
+
60
+ # Check event is defined or not
61
+ # @param [Symbol] event event name symbol
62
+ # @raise ArgumentError
63
+ def undefined_event_protect(event)
64
+ raise ArgumentError, "event #{event} is not defined." unless DEFINED_EVENT.include?(event)
65
+ end
66
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edrive
2
- VERSION = '1.0.3'.freeze
4
+ VERSION = '1.0.4'.freeze
3
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edrive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - MichinaoShimizu
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.6'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.4'
55
83
  description: "Generic Event Dispatcher.\n Provide simple event dispatcher mechanism
56
84
  for all of ruby products.\n\n "
57
85
  email:
@@ -60,6 +88,7 @@ executables: []
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
91
+ - ".circleci/config.yml"
63
92
  - ".gitignore"
64
93
  - CODE_OF_CONDUCT.md
65
94
  - Gemfile
@@ -72,6 +101,8 @@ files:
72
101
  - edrive.gemspec
73
102
  - lib/edrive.rb
74
103
  - lib/edrive/dispatcher.rb
104
+ - lib/edrive/handler.rb
105
+ - lib/edrive/processor_dispatcher.rb
75
106
  - lib/edrive/version.rb
76
107
  homepage: https://github.com/MichinaoShimizu/edrive
77
108
  licenses: