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 +4 -4
- data/.github/workflows/rspec.yml +28 -0
- data/README.md +28 -0
- data/lib/dekiru/capybara/matchers.rb +1 -1
- data/lib/dekiru/data_migration_operator.rb +45 -6
- data/lib/dekiru/task_with_logger.rb +7 -6
- data/lib/dekiru/validators/existence.rb +1 -1
- data/lib/dekiru/version.rb +1 -1
- metadata +3 -3
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b41d118d14b7e96272667d7a6dfe0d9fc5fb6e77765f9d2add4b47290f5b2b6d
|
4
|
+
data.tar.gz: 88ba004a68df6e0b3b30b99f5f67715f9fbd45743567b53f58d3db27f95eb0fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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) ?
|
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
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
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
|
-
|
7
|
+
TaskWithLogger.echo("[START] #{_task.name} #{_args.to_h} (#{Time.current})")
|
8
8
|
yield(_task, _args)
|
9
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
|
data/lib/dekiru/version.rb
CHANGED
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.
|
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:
|
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
|