dekiru 0.4.1 → 0.4.3
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 +4 -4
- data/README.md +19 -0
- data/dekiru.gemspec +5 -1
- data/lib/dekiru/data_migration_operator.rb +5 -2
- data/lib/dekiru/version.rb +1 -1
- data/lib/dekiru.rb +2 -1
- data/lib/generators/maintenance_script/maintenance_script_generator.rb +2 -1
- data/spec/dekiru/data_migration_operator_spec.rb +1 -1
- metadata +7 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6fac2069f365f91b45b8d73c28d5edc43019c77bc759a67be20587d34ba69cd6
         | 
| 4 | 
            +
              data.tar.gz: 445b58a763dbd2d19615126e369074a83c31129495a444b46ba659147474c5eb
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5415cd694554c1d4f025b8a800ca948ad9ae57dac8ffe7eaa1b49ee2ff6199d2cbc07d1692a9a7c224f92873b2390a0a467de8d5c26e0a40777490c1dcdaf4ce
         | 
| 7 | 
            +
              data.tar.gz: 0d69944fdc7f5f09dc08921be3e92eb05929feb8b319eae20c089c7d4344b584857ce24bded17d7173065eb7fc746188c9abb72af15fbf15e20f0e1ad7147a58
         | 
    
        data/README.md
    CHANGED
    
    | @@ -182,6 +182,25 @@ Deliverd Mailers!! | |
| 182 182 | 
             
            Are you sure to commit? (yes/no) > yes
         | 
| 183 183 | 
             
            ```
         | 
| 184 184 |  | 
| 185 | 
            +
            ジェネレータを使って `Dekiru::DataMigrationOperator` を使ったメンテナンススクリプトを生成することができます。ファイル名にはスクリプトファイルを生成した日付が prefix として付与されます。
         | 
| 186 | 
            +
             | 
| 187 | 
            +
            ```
         | 
| 188 | 
            +
            $ bin/rails g maintenance_script demo_migration
         | 
| 189 | 
            +
            $ cat scripts/20230118_demo_migration.rb
         | 
| 190 | 
            +
            Dekiru::DataMigrationOperator.execute('demo_migration') do
         | 
| 191 | 
            +
              # write here
         | 
| 192 | 
            +
            end
         | 
| 193 | 
            +
            ```
         | 
| 194 | 
            +
             | 
| 195 | 
            +
            ファイルの出力先ディレクトリは、デフォルトではアプリケーションルート直下の `scripts` ディレクトリです。設定で出力先ディレクトリを変更することもできます。
         | 
| 196 | 
            +
             | 
| 197 | 
            +
            ```ruby
         | 
| 198 | 
            +
            # config/initializer/dekiru.rb
         | 
| 199 | 
            +
            Dekiru.configure do |config|
         | 
| 200 | 
            +
              config.maintenance_script_directory = 'scripts/maintenance'
         | 
| 201 | 
            +
            end
         | 
| 202 | 
            +
            ```
         | 
| 203 | 
            +
             | 
| 185 204 | 
             
            ## Refinements
         | 
| 186 205 |  | 
| 187 206 | 
             
            ### Dekiru::CamelizeHash
         | 
    
        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) }
         | 
| @@ -4,7 +4,7 @@ module Dekiru | |
| 4 4 | 
             
              class DataMigrationOperator
         | 
| 5 5 | 
             
                class NestedTransactionError < StandardError ; end
         | 
| 6 6 |  | 
| 7 | 
            -
                attr_reader :title, :stream, :result, :canceled, :started_at, :ended_at, :error
         | 
| 7 | 
            +
                attr_reader :title, :stream, :logger, :result, :canceled, :started_at, :ended_at, :error
         | 
| 8 8 |  | 
| 9 9 | 
             
                def self.execute(title, options = {}, &block)
         | 
| 10 10 | 
             
                  self.new(title, options).execute(&block)
         | 
| @@ -13,6 +13,7 @@ module Dekiru | |
| 13 13 | 
             
                def initialize(title, options = {})
         | 
| 14 14 | 
             
                  @title = title
         | 
| 15 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")) }
         | 
| 16 17 | 
             
                  @stream = @options.fetch(:output, $stdout)
         | 
| 17 18 | 
             
                  @without_transaction = @options.fetch(:without_transaction, false)
         | 
| 18 19 | 
             
                  @side_effects = Hash.new do |hash, key|
         | 
| @@ -31,6 +32,7 @@ module Dekiru | |
| 31 32 |  | 
| 32 33 | 
             
                    @result = ActiveRecord::Base.transaction do
         | 
| 33 34 | 
             
                      run(&block)
         | 
| 35 | 
            +
                      log "Finished execution: #{title}"
         | 
| 34 36 | 
             
                      confirm?("\nAre you sure to commit?")
         | 
| 35 37 | 
             
                    end
         | 
| 36 38 | 
             
                  end
         | 
| @@ -75,6 +77,7 @@ module Dekiru | |
| 75 77 |  | 
| 76 78 | 
             
                def log(message)
         | 
| 77 79 | 
             
                  stream.puts(message)
         | 
| 80 | 
            +
                  logger&.info(message.squish)
         | 
| 78 81 | 
             
                end
         | 
| 79 82 |  | 
| 80 83 | 
             
                def confirm?(message = 'Are you sure?')
         | 
| @@ -92,7 +95,7 @@ module Dekiru | |
| 92 95 | 
             
                end
         | 
| 93 96 |  | 
| 94 97 | 
             
                def newline
         | 
| 95 | 
            -
                   | 
| 98 | 
            +
                  stream.puts('')
         | 
| 96 99 | 
             
                end
         | 
| 97 100 |  | 
| 98 101 | 
             
                def cancel!
         | 
    
        data/lib/dekiru/version.rb
    CHANGED
    
    
    
        data/lib/dekiru.rb
    CHANGED
    
    | @@ -21,10 +21,11 @@ module Dekiru | |
| 21 21 | 
             
              end
         | 
| 22 22 |  | 
| 23 23 | 
             
              class Configuration
         | 
| 24 | 
            -
                attr_accessor :mail_security_hook
         | 
| 24 | 
            +
                attr_accessor :mail_security_hook, :maintenance_script_directory
         | 
| 25 25 |  | 
| 26 26 | 
             
                def initialize
         | 
| 27 27 | 
             
                  @mail_security_hook = false # default
         | 
| 28 | 
            +
                  @maintenance_script_directory = 'scripts'
         | 
| 28 29 | 
             
                end
         | 
| 29 30 | 
             
              end
         | 
| 30 31 | 
             
            end
         | 
| @@ -4,7 +4,8 @@ class MaintenanceScriptGenerator < Rails::Generators::NamedBase | |
| 4 4 | 
             
              source_root File.expand_path('templates', __dir__)
         | 
| 5 5 |  | 
| 6 6 | 
             
              def copy_maintenance_script_file
         | 
| 7 | 
            -
                template 'maintenance_script.rb.erb', | 
| 7 | 
            +
                template 'maintenance_script.rb.erb',
         | 
| 8 | 
            +
                         "#{Dekiru.configuration.maintenance_script_directory}/#{filename_date}_#{file_name}.rb"
         | 
| 8 9 | 
             
              end
         | 
| 9 10 |  | 
| 10 11 | 
             
              private
         | 
| @@ -28,7 +28,7 @@ describe Dekiru::DataMigrationOperator do | |
| 28 28 | 
             
              end
         | 
| 29 29 | 
             
              let(:without_transaction) { false }
         | 
| 30 30 | 
             
              let(:operator) do
         | 
| 31 | 
            -
                op = Dekiru::DataMigrationOperator.new('dummy', output: dummy_stream, without_transaction: without_transaction)
         | 
| 31 | 
            +
                op = Dekiru::DataMigrationOperator.new('dummy', output: dummy_stream, logger: nil, without_transaction: without_transaction)
         | 
| 32 32 | 
             
                allow(op).to receive(:current_transaction_open?) { false }
         | 
| 33 33 | 
             
                op
         | 
| 34 34 | 
             
              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.4. | 
| 4 | 
            +
              version: 0.4.3
         | 
| 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: 2023-01-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: http_accept_language
         | 
| @@ -164,9 +164,12 @@ files: | |
| 164 164 | 
             
            - spec/spec_helper.rb
         | 
| 165 165 | 
             
            - spec/supports/action_mailer.rb
         | 
| 166 166 | 
             
            - spec/supports/mock_active_record.rb
         | 
| 167 | 
            -
            homepage:  | 
| 167 | 
            +
            homepage: https://github.com/SonicGarden/dekiru
         | 
| 168 168 | 
             
            licenses: []
         | 
| 169 | 
            -
            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
         | 
| 170 173 | 
             
            post_install_message: 
         | 
| 171 174 | 
             
            rdoc_options: []
         | 
| 172 175 | 
             
            require_paths:
         |