dekiru 0.1.7 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52638cf1b48eda2cccf9bc53435a8c361e17a43a3145457eba5fbfdd68b5f9ac
4
- data.tar.gz: 5ced1fe987c0999fdff91eeef663cd664c3bdafd58a466dd40dd21c6e8b64bda
3
+ metadata.gz: b41d118d14b7e96272667d7a6dfe0d9fc5fb6e77765f9d2add4b47290f5b2b6d
4
+ data.tar.gz: 88ba004a68df6e0b3b30b99f5f67715f9fbd45743567b53f58d3db27f95eb0fd
5
5
  SHA512:
6
- metadata.gz: 2dc00bbe336a2381355d72b5da39a398a36640af30a425696c9f145773b1c7c0fe3844d985d533af8f2336dc2e0591cc1cb2f6980fddbacfa587e1b50c759d94
7
- data.tar.gz: 0f81e7e83a43ac4a335b89e42a5c08cf5f3573792a4afd958aa5744fe3ef3b59546ba82195c36e60f2ec420f52b5bc7dd484c41747e908dc81ff7274f7402027
6
+ metadata.gz: 355332f2520250b85cdd76f71931959dc414aa58b6471e1ce8eb6091c518bf6264592874b63fd656e65ca5d27ebd6d9c375abff39a6792aaad6e99e971246d7b
7
+ data.tar.gz: fc17816184e72d8ce6e22582b741a9142492eb03c15747a2e96b9b600ea65dea1d91c9d58b08110b93bbfac1e0a753e478a5ba6d4191d7020e8aaceb99b9f1c0
@@ -0,0 +1,28 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+
8
+ jobs:
9
+ rspec:
10
+ runs-on: ubuntu-latest
11
+ env:
12
+ BUNDLE_JOBS: 4
13
+ BUNDLE_RETRY: 3
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ ruby: ["2.6", "2.7", "3.0"]
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+
27
+ - name: Run rspec
28
+ run: bundle exec rspec
data/README.md CHANGED
@@ -154,6 +154,34 @@ Finished successfully: Demo migration
154
154
  Total time: 6.35 sec
155
155
  ```
156
156
 
157
+ また`warning_side_effects: true`オプションを付けて実行することで、データ移行作業で発生した副作用が表示されるようになります。
158
+
159
+ ```ruby
160
+ Dekiru::DataMigrationOperator.execute('Demo migration', warning_side_effects: true) do
161
+ # ...
162
+ end
163
+ ```
164
+
165
+ ```
166
+ $ bin/rails r scripts/demo.rb
167
+ Start: Demo migration at 2019-05-24 18:29:57 +0900
168
+
169
+ all targets count: 30
170
+ Time: 00:00:00 |=================>>| 100% Progress
171
+ updated user count: 30
172
+
173
+ Write Queries!!
174
+ 30 call: Update "users" SET ...
175
+
176
+ Enqueued Jobs!!
177
+ 10 call: NotifyJob
178
+
179
+ Deliverd Mailers!!
180
+ 10 call: UserMailer
181
+
182
+ Are you sure to commit? (yes/no) > yes
183
+ ```
184
+
157
185
  ## Refinements
158
186
 
159
187
  ### Dekiru::CamelizeHash
@@ -3,7 +3,7 @@ module Dekiru
3
3
  module Matchers
4
4
  class JsNoErrorMatcher
5
5
  def matches?(page_or_logs)
6
- logs = page_or_logs.respond_to?(:driver) ? page.driver.browser.manage.logs.get(:browser) : page_or_logs
6
+ logs = page_or_logs.respond_to?(:driver) ? page_or_logs.driver.browser.manage.logs.get(:browser) : page_or_logs
7
7
  logs.find_all { |log| log.level == 'WARNING' }.each do |log|
8
8
  STDERR.puts 'WARN: javascript warning'
9
9
  STDERR.puts log.message
@@ -10,18 +10,22 @@ module Dekiru
10
10
 
11
11
  def initialize(title, options = {})
12
12
  @title = title
13
- @stream = options[:output] || $stdout
14
- end
15
-
16
- def log(message)
17
- stream.puts(message)
13
+ @options = options
14
+ @stream = @options[:output] || $stdout
15
+ @side_effects = Hash.new do |hash, key|
16
+ hash[key] = Hash.new(0)
17
+ end
18
18
  end
19
19
 
20
20
  def execute(&block)
21
21
  @started_at = Time.current
22
22
  log "Start: #{title} at #{started_at}\n\n"
23
23
  @result = ActiveRecord::Base.transaction(requires_new: true, joinable: false) do
24
- instance_eval(&block)
24
+ if @options[:warning_side_effects]
25
+ warning_side_effects(&block)
26
+ else
27
+ instance_eval(&block)
28
+ end
25
29
  confirm?("\nAre you sure to commit?")
26
30
  end
27
31
  log "Finished successfully: #{title}" if @result == true
@@ -56,6 +60,12 @@ module Dekiru
56
60
  pb.finish
57
61
  end
58
62
 
63
+ private
64
+
65
+ def log(message)
66
+ stream.puts(message)
67
+ end
68
+
59
69
  def confirm?(message = 'Are you sure?')
60
70
  loop do
61
71
  stream.print "#{message} (yes/no) > "
@@ -78,5 +88,34 @@ module Dekiru
78
88
  log "Canceled: #{title}"
79
89
  raise ActiveRecord::Rollback
80
90
  end
91
+
92
+ def handle_notification(*args)
93
+ event = ActiveSupport::Notifications::Event.new(*args)
94
+
95
+ increment_side_effects(:enqueued_jobs, event.payload[:job].class.name) if event.payload[:job]
96
+ increment_side_effects(:deliverd_mailers, event.payload[:mailer]) if event.payload[:mailer]
97
+
98
+ if event.payload[:sql] && /\A\s*(insert|update|delete)/i.match?(event.payload[:sql])
99
+ increment_side_effects(:write_queries, event.payload[:sql])
100
+ end
101
+ end
102
+
103
+ def increment_side_effects(type, value)
104
+ @side_effects[type][value] += 1
105
+ end
106
+
107
+ def warning_side_effects(&block)
108
+ ActiveSupport::Notifications.subscribed(method(:handle_notification), /^(sql|enqueue|deliver)/) do
109
+ instance_eval(&block)
110
+ end
111
+
112
+ @side_effects.each do |name, items|
113
+ newline
114
+ log "#{name.to_s.titlecase}!!"
115
+ items.sort_by { |v, c| c }.reverse.slice(0, 20).each do |value, count|
116
+ log "#{count} call: #{value}"
117
+ end
118
+ end
119
+ end
81
120
  end
82
121
  end
@@ -4,16 +4,17 @@ module TaskWithLogger
4
4
 
5
5
  def task(*args, &block)
6
6
  new_block = proc do |_task, _args|
7
- __echo__ "[START] #{_task.name} #{_args.to_h} (#{Time.current})"
7
+ TaskWithLogger.echo("[START] #{_task.name} #{_args.to_h} (#{Time.current})")
8
8
  yield(_task, _args)
9
- __echo__ "[END] #{_task.name} #{_args.to_h} (#{Time.current})"
9
+ TaskWithLogger.echo("[END] #{_task.name} #{_args.to_h} (#{Time.current})")
10
10
  end
11
11
  super(*args, &new_block)
12
12
  end
13
+ end
13
14
 
14
- def __echo__(str)
15
- Rails.logger.info(str)
16
- puts(str)
17
- end
15
+ def echo(str)
16
+ Rails.logger.info(str)
17
+ puts(str)
18
18
  end
19
+ module_function :echo
19
20
  end
@@ -9,7 +9,7 @@ module ActiveModel
9
9
  class ExistenceValidator < EachValidator
10
10
  def validate_each(record, attribute, value)
11
11
  unless exists?(record, value)
12
- record.errors.add(attribute, :existence, options.except(:in).merge!(value: value))
12
+ record.errors.add(attribute, :existence, **options.except(:in).merge!(value: value))
13
13
  end
14
14
  end
15
15
 
@@ -1,3 +1,3 @@
1
1
  module Dekiru
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dekiru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Matsumura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-05 00:00:00.000000000 Z
11
+ date: 2021-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http_accept_language
@@ -115,9 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/rspec.yml"
118
119
  - ".gitignore"
119
120
  - ".ruby-version"
120
- - ".travis.yml"
121
121
  - Gemfile
122
122
  - LICENSE
123
123
  - README.md
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- rvm:
2
- - 2.4.6
3
- - 2.5.5
4
- - 2.6.3
5
- - 2.7.1
6
-
7
- # NOTE: https://github.com/travis-ci/travis-ci/issues/8978
8
- before_install:
9
- - gem update --system --no-document
10
-
11
- sudo: false
12
- cache: bundler