dekiru 0.1.4 → 0.1.9

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: fa88f3d2cf47df7ed8a071acc0dbb0b86fa20e42c5ad3e72b3f23fb8c6f593b5
4
- data.tar.gz: ddabf00fc5c3dfcfb8a22f9103f7a8d90ea5e92b6c158bd2b4ea1936d48ebc81
3
+ metadata.gz: 1a97b022b934401c9a7bb4ada03bda713299e5ee8a59acc93e8e8397a6c2b529
4
+ data.tar.gz: 2adfa51b5b92c008f2a7099d863f385093a41a18f64c4123c15130c4dd29ad7f
5
5
  SHA512:
6
- metadata.gz: 02ed8451df03137d882758e3adb2fb06f7d8aa3b9e240ec84cd0e59a3bf460945f18919717010c44f58f13abbd6f468d39a33d37a29c9ad809334385ecbd6adc
7
- data.tar.gz: be1798f99193883c7bb7978f52b9e52e40bcd2e01e1b041159f110c1be6517922b7a6067978a423e3c9315bf9a870bceb465fae1234b2929a318d191d486066c
6
+ metadata.gz: 2329153068a4faa166d61d7c08ee43cec421bf93b9205c7ceed4104bd0b8cd5f1a81998a62623106e0f093c689adfa6ecce7a935b4e456d0d438080993dcf3ed
7
+ data.tar.gz: 63012279c77d3896c1e9b5a9e35587c95eeb5c0ae07a72645786bf223cd028093c938e67d75bf253ee6c1de64679e1e175bb924305adaa2dc5da272d75f70f00
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.7.1
@@ -1,7 +1,8 @@
1
1
  rvm:
2
- - 2.3.3
3
- - 2.4.4
4
- - 2.5.1
2
+ - 2.4.6
3
+ - 2.5.5
4
+ - 2.6.3
5
+ - 2.7.1
5
6
 
6
7
  # NOTE: https://github.com/travis-ci/travis-ci/issues/8978
7
8
  before_install:
data/README.md CHANGED
@@ -113,7 +113,7 @@ Rake::Task['db:migrate'].enhance(['db:migrate:check_conflict']) if Rails.env.dev
113
113
 
114
114
  以下の設定をすると、宛先を指定しないメールを配信しようとした時に`Dekiru::MailSecurityInterceptor::NoToAdreessError`例外を発生させる。
115
115
 
116
- ※ toに空文字や空配列を指定してメールを配信しようとすると、bcc内のアドレスがtoに転記されるといった問題がある。これを未然に防ぐことができる。
116
+ ※ to に空文字や空配列を指定してメールを配信しようとすると、bcc 内のアドレスが to に転記されるといった問題がある。これを未然に防ぐことができる。
117
117
 
118
118
  ```ruby
119
119
  # config/initializer/dekiru.rb
@@ -154,6 +154,48 @@ 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
+
185
+ ## Refinements
186
+
187
+ ### Dekiru::CamelizeHash
188
+
189
+ ```ruby
190
+ using Dekiru::CamelizeHash
191
+
192
+ { dekiru_rails: true }.camelize_keys(:lower)
193
+ # => { dekiruRails: true }
194
+
195
+ { dekiru_rails: { dekiru_rails: true } }.deep_camelize_keys(:lower)
196
+ # => { dekiruRails: { dekiruRails: true } }
197
+ ```
198
+
157
199
  ## Contributing
158
200
 
159
201
  1. Fork it
@@ -15,6 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Dekiru::VERSION
17
17
 
18
+ gem.required_ruby_version = '>= 2.4.0'
19
+
18
20
  gem.add_dependency 'http_accept_language', [">= 2.0.0"]
19
21
  gem.add_dependency 'rails'
20
22
  gem.add_dependency 'ruby-progressbar'
@@ -5,6 +5,7 @@ require 'dekiru/controller_additions'
5
5
  require 'dekiru/validators/existence'
6
6
  require 'dekiru/data_migration_operator'
7
7
  require 'dekiru/mail_security_interceptor'
8
+ require 'dekiru/camelize_hash'
8
9
 
9
10
  require 'active_support'
10
11
  require 'active_support/all'
@@ -0,0 +1,25 @@
1
+ module Dekiru
2
+ module CamelizeHash
3
+ refine ::Hash do
4
+ def camelize_keys(first_letter = :upper)
5
+ transform_keys do |k|
6
+ if k.is_a?(Symbol)
7
+ k.to_s.camelize(first_letter).to_sym
8
+ else
9
+ k.camelize(first_letter)
10
+ end
11
+ end
12
+ end
13
+
14
+ def deep_camelize_keys(first_letter = :upper)
15
+ deep_transform_keys do |k|
16
+ if k.is_a?(Symbol)
17
+ k.to_s.camelize(first_letter).to_sym
18
+ else
19
+ k.camelize(first_letter)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,14 +2,14 @@ module Dekiru
2
2
  module Capybara
3
3
  module Matchers
4
4
  class JsNoErrorMatcher
5
- def matches?(page)
6
- errors = page.driver.browser.manage.logs.get(:browser)
7
- errors.find_all { |error| error.level == 'WARNING' }.each do |error|
5
+ def matches?(page_or_logs)
6
+ logs = page_or_logs.respond_to?(:driver) ? page_or_logs.driver.browser.manage.logs.get(:browser) : page_or_logs
7
+ logs.find_all { |log| log.level == 'WARNING' }.each do |log|
8
8
  STDERR.puts 'WARN: javascript warning'
9
- STDERR.puts error.message
9
+ STDERR.puts log.message
10
10
  end
11
11
 
12
- @severe_errors = errors.find_all { |error| error.level == 'SEVERE' }
12
+ @severe_errors = logs.find_all { |log| log.level == 'SEVERE' }
13
13
  @severe_errors.empty?
14
14
  end
15
15
 
@@ -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
- @result = ActiveRecord::Base.transaction(requires_new: true) do
24
- instance_eval(&block)
23
+ @result = ActiveRecord::Base.transaction(requires_new: true, joinable: false) do
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
@@ -19,8 +19,8 @@ module Dekiru
19
19
  end
20
20
  end
21
21
 
22
- def null_check_localization(*args)
23
- localize(*args) if args.try(:first).present?
22
+ def null_check_localization(object, **options)
23
+ localize(object, **options) if object.present?
24
24
  end
25
25
  alias nl null_check_localization
26
26
 
@@ -1,3 +1,3 @@
1
1
  module Dekiru
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.9'
3
3
  end
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+
3
+ describe Dekiru::CamelizeHash do
4
+ using Dekiru::CamelizeHash
5
+
6
+ let(:hash) do
7
+ hash = {
8
+ dekiru_rails: {
9
+ dekiru_rails: 'dekiru'
10
+ },
11
+ 'dekiru_ruby' => {
12
+ 'dekiru_ruby' => 'dekiru'
13
+ }
14
+ }
15
+ end
16
+
17
+ describe '#camelize_keys' do
18
+ it '一階層目のキーがキャメルケースに変換される' do
19
+ expect(hash.camelize_keys(:lower)).to match({
20
+ dekiruRails: {
21
+ dekiru_rails: 'dekiru'
22
+ },
23
+ 'dekiruRuby' => {
24
+ 'dekiru_ruby' => 'dekiru'
25
+ }
26
+ })
27
+ end
28
+
29
+ it '一階層目のキーがアッパーキャメルケースに変換される' do
30
+ expect(hash.camelize_keys).to match({
31
+ DekiruRails: {
32
+ dekiru_rails: 'dekiru'
33
+ },
34
+ 'DekiruRuby' => {
35
+ 'dekiru_ruby' => 'dekiru'
36
+ }
37
+ })
38
+ end
39
+ end
40
+
41
+ describe '#deep_camelize_keys' do
42
+ it '2階層目以降のキーもキャメルケースに変換される' do
43
+ expect(hash.deep_camelize_keys(:lower)).to match({
44
+ dekiruRails: {
45
+ dekiruRails: 'dekiru'
46
+ },
47
+ 'dekiruRuby' => {
48
+ 'dekiruRuby' => 'dekiru'
49
+ }
50
+ })
51
+ end
52
+
53
+ it '2階層目以降のキーもアッパーキャメルケースに変換される' do
54
+ expect(hash.deep_camelize_keys).to match({
55
+ DekiruRails: {
56
+ DekiruRails: 'dekiru'
57
+ },
58
+ 'DekiruRuby' => {
59
+ 'DekiruRuby' => 'dekiru'
60
+ }
61
+ })
62
+ end
63
+ end
64
+ 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.4
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Matsumura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-01 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http_accept_language
@@ -124,6 +124,7 @@ files:
124
124
  - Rakefile
125
125
  - dekiru.gemspec
126
126
  - lib/dekiru.rb
127
+ - lib/dekiru/camelize_hash.rb
127
128
  - lib/dekiru/capybara/helpers.rb
128
129
  - lib/dekiru/capybara/matchers.rb
129
130
  - lib/dekiru/controller_additions.rb
@@ -137,6 +138,7 @@ files:
137
138
  - lib/dekiru/tasks/smtp_check.rake
138
139
  - lib/dekiru/validators/existence.rb
139
140
  - lib/dekiru/version.rb
141
+ - spec/dekiru/camelize_hash_spec.rb
140
142
  - spec/dekiru/data_migration_operator_spec.rb
141
143
  - spec/dekiru/helper_spec.rb
142
144
  - spec/dekiru/mail_security_interceptor_spec.rb
@@ -155,19 +157,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
157
  requirements:
156
158
  - - ">="
157
159
  - !ruby/object:Gem::Version
158
- version: '0'
160
+ version: 2.4.0
159
161
  required_rubygems_version: !ruby/object:Gem::Requirement
160
162
  requirements:
161
163
  - - ">="
162
164
  - !ruby/object:Gem::Version
163
165
  version: '0'
164
166
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.7.6
167
+ rubygems_version: 3.1.2
167
168
  signing_key:
168
169
  specification_version: 4
169
170
  summary: Usefull helper methods for Ruby on Rails
170
171
  test_files:
172
+ - spec/dekiru/camelize_hash_spec.rb
171
173
  - spec/dekiru/data_migration_operator_spec.rb
172
174
  - spec/dekiru/helper_spec.rb
173
175
  - spec/dekiru/mail_security_interceptor_spec.rb