dekiru 0.4.0 → 0.4.2

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: dbfeff250b0e1ec21cc8ed1f4ccf284ac5430ad41be129f0f04a6fa73b6f36b7
4
- data.tar.gz: dc7557d4f6a91491fad5cd70d938a0050e8b98405ded870825564ee037401156
3
+ metadata.gz: c890a48f2abca1d753301d1d95b568306896da734616e4ecf18b1f65fef89126
4
+ data.tar.gz: fdddce1a0ff1db098175aa86abf02c0e1327ee2ede909364e08c14919151b0d2
5
5
  SHA512:
6
- metadata.gz: 447ab174db16c187dab03db7ecef25d217036ea688442c5594dd0d82382cde3bf2ce10e6e7fb27382b6f9702d4c7292fe01c583f7055cd365921f1bf97d4f1ed
7
- data.tar.gz: 723725e05e52c1beef024d39787c2dd5c834b14e1c5c7d18374c0dea57c4bf6441c1e618d8287c5bb44210865ea9b7d63eb554486f5293fa19c78f9a7e280d92
6
+ metadata.gz: 76a86a4250d2633f379078535034596067d3331c23e4c4c3f55aaf38dfcb3fcabdc82c695c0829bf3b5990c86fab6095318dde10c4be86a9b2d4677ed868d52e
7
+ data.tar.gz: f7e3a2065a7c58537e070d066b40d3ef9805caa0712b53372bff8db5806a2e07c8e375ba680f9f0ca622c7fe16c4ee2c3480f5795b80e8c290ccab8232ccb3dc
@@ -0,0 +1,18 @@
1
+ - name: add
2
+ description: Add new features.
3
+ color: "0e8a16"
4
+ - name: change
5
+ description: Change existing functionality.
6
+ color: "fbca04"
7
+ - name: deprecate
8
+ description: Mark as soon-to-be removed features.
9
+ color: "d93f0b"
10
+ - name: remove
11
+ description: Remove features.
12
+ color: "b60205"
13
+ - name: fix
14
+ description: Fix bug.
15
+ color: "5319e7"
16
+ - name: security
17
+ description: In case of vulnerabilities.
18
+ color: "0052cc"
@@ -0,0 +1,23 @@
1
+ changelog:
2
+ categories:
3
+ - title: Added
4
+ labels:
5
+ - add
6
+ - title: Changed
7
+ labels:
8
+ - change
9
+ - title: Deprecated
10
+ labels:
11
+ - deprecate
12
+ - title: Fixed
13
+ labels:
14
+ - fix
15
+ - title: Removed
16
+ labels:
17
+ - remove
18
+ - title: Security
19
+ labels:
20
+ - security
21
+ - title: Others
22
+ labels:
23
+ - "*"
@@ -0,0 +1,16 @@
1
+ name: github-label-sync
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ paths:
8
+ - .github/labels.yml
9
+ - .github/workflows/github-label-sync.yml
10
+ workflow_dispatch:
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: r7kamura/github-label-sync-action@v0
data/dekiru.gemspec CHANGED
@@ -6,7 +6,11 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["matsumura.aki@gmail.com"]
7
7
  gem.description = %q{Usefull helper methods for Ruby on Rails}
8
8
  gem.summary = %q{Usefull helper methods for Ruby on Rails}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/SonicGarden/dekiru"
10
+
11
+ gem.metadata["homepage_uri"] = gem.homepage
12
+ gem.metadata["source_code_uri"] = "https://github.com/SonicGarden/dekiru"
13
+ gem.metadata["changelog_uri"] = "https://github.com/SonicGarden/dekiru/releases"
10
14
 
11
15
  gem.files = `git ls-files`.split($\)
12
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -2,7 +2,9 @@ require 'ruby-progressbar'
2
2
 
3
3
  module Dekiru
4
4
  class DataMigrationOperator
5
- attr_reader :title, :stream, :result, :canceled, :started_at, :ended_at, :error
5
+ class NestedTransactionError < StandardError ; end
6
+
7
+ attr_reader :title, :stream, :logger, :result, :canceled, :started_at, :ended_at, :error
6
8
 
7
9
  def self.execute(title, options = {}, &block)
8
10
  self.new(title, options).execute(&block)
@@ -11,6 +13,7 @@ module Dekiru
11
13
  def initialize(title, options = {})
12
14
  @title = title
13
15
  @options = options
16
+ @logger = @options.fetch(:logger) { Logger.new(Rails.root.join("log/data_migration_#{Time.current.strftime("%Y%m%d%H%M")}.log")) }
14
17
  @stream = @options.fetch(:output, $stdout)
15
18
  @without_transaction = @options.fetch(:without_transaction, false)
16
19
  @side_effects = Hash.new do |hash, key|
@@ -25,8 +28,11 @@ module Dekiru
25
28
  run(&block)
26
29
  @result = true
27
30
  else
28
- @result = ActiveRecord::Base.transaction(requires_new: true, joinable: false) do
31
+ raise NestedTransactionError if current_transaction_open?
32
+
33
+ @result = ActiveRecord::Base.transaction do
29
34
  run(&block)
35
+ log "Finished execution: #{title}"
30
36
  confirm?("\nAre you sure to commit?")
31
37
  end
32
38
  end
@@ -65,8 +71,13 @@ module Dekiru
65
71
 
66
72
  private
67
73
 
74
+ def current_transaction_open?
75
+ ActiveRecord::Base.connection.current_transaction.open?
76
+ end
77
+
68
78
  def log(message)
69
79
  stream.puts(message)
80
+ logger&.info(message.squish)
70
81
  end
71
82
 
72
83
  def confirm?(message = 'Are you sure?')
@@ -84,7 +95,7 @@ module Dekiru
84
95
  end
85
96
 
86
97
  def newline
87
- log ''
98
+ stream.puts('')
88
99
  end
89
100
 
90
101
  def cancel!
@@ -1,3 +1,3 @@
1
1
  module Dekiru
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -27,7 +27,11 @@ describe Dekiru::DataMigrationOperator do
27
27
  Dekiru::DummyStream.new
28
28
  end
29
29
  let(:without_transaction) { false }
30
- let(:operator) { Dekiru::DataMigrationOperator.new('dummy', output: dummy_stream, without_transaction: without_transaction) }
30
+ let(:operator) do
31
+ op = Dekiru::DataMigrationOperator.new('dummy', output: dummy_stream, logger: nil, without_transaction: without_transaction)
32
+ allow(op).to receive(:current_transaction_open?) { false }
33
+ op
34
+ end
31
35
 
32
36
  describe '#execute' do
33
37
  it 'confirm で yes' do
@@ -76,6 +80,14 @@ describe Dekiru::DataMigrationOperator do
76
80
  expect(operator.stream.out).to include('Total time:')
77
81
  end
78
82
 
83
+ context 'トランザクション内で呼び出された場合' do
84
+ before { allow(operator).to receive(:current_transaction_open?) { true } }
85
+
86
+ it '例外が発生すること' do
87
+ expect { operator.execute { log 'processing'; sleep 1.0 } }.to raise_error(Dekiru::DataMigrationOperator::NestedTransactionError)
88
+ end
89
+ end
90
+
79
91
  context 'without_transaction: true のとき' do
80
92
  let(:without_transaction) { true }
81
93
 
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.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Matsumura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-14 00:00:00.000000000 Z
11
+ date: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http_accept_language
@@ -129,6 +129,9 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".github/labels.yml"
133
+ - ".github/release.yml"
134
+ - ".github/workflows/github-label-sync.yml"
132
135
  - ".github/workflows/rspec.yml"
133
136
  - ".gitignore"
134
137
  - ".ruby-version"
@@ -161,9 +164,12 @@ files:
161
164
  - spec/spec_helper.rb
162
165
  - spec/supports/action_mailer.rb
163
166
  - spec/supports/mock_active_record.rb
164
- homepage: ''
167
+ homepage: https://github.com/SonicGarden/dekiru
165
168
  licenses: []
166
- metadata: {}
169
+ metadata:
170
+ homepage_uri: https://github.com/SonicGarden/dekiru
171
+ source_code_uri: https://github.com/SonicGarden/dekiru
172
+ changelog_uri: https://github.com/SonicGarden/dekiru/releases
167
173
  post_install_message:
168
174
  rdoc_options: []
169
175
  require_paths: