screamers 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: dd7ad40377447ccb7e9dd576145a16cd5c623024
4
- data.tar.gz: a023b799d0f13787dfabd217fee6c6511272d84d
3
+ metadata.gz: c758d59eefca8fe53f74f8b767551ab74ca28b22
4
+ data.tar.gz: 4a75e01840b39476caacb21759d49f9ae40ce3a8
5
5
  SHA512:
6
- metadata.gz: e857794a2b2c96c6b5b5928f4339eea66ebc33504eceb7bc6ad2896a3dfa4926f1719a5824198405f9329c0ccf2ca92ab028c42968f3b1c5f70b62d0cbcc4667
7
- data.tar.gz: af14ce768fb031ae627186b3f8b5bcb270283ba1fe80c9733c8f15c829f4cfac2a16b1f7f2158bb9dd7d06925d7a1c2c2bbd376cba349c607894deec255bc20c
6
+ metadata.gz: e355ca06f9e67107698f923f9df8e15d0e104aa0486ecca68f7cee6a0ff2691191ddb9e8defbfaaa71dad336d6e5f2ef41313c5fe1ff11133890ae2330792949
7
+ data.tar.gz: 9f3d9477e34c444e91c2488a688423313384b0f7c3ac4d570e947d7b0f9eb16d90f450367582660fa6be55d3671e13e8f82bb26c96aef88df7aa41fdbb34c23b
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Screamers [![Build Status](https://travis-ci.org/koic/screamers.svg)](https://travis-ci.org/koic/screamers)
1
+ # Screamers [![Build Status](https://travis-ci.org/koic/screamers.svg)](https://travis-ci.org/koic/screamers) [![Gem Version](https://badge.fury.io/rb/screamers.svg)](http://badge.fury.io/rb/screamers)
2
2
 
3
3
  Generate a migration file that converts column types all at once.
4
4
 
@@ -26,7 +26,7 @@ Screamers:
26
26
  ## Synopsis
27
27
 
28
28
  ```console
29
- bin/rails g screamers:migration <old-column-type> <new-column-type>
29
+ bin/rails g screamers:migration OLD_COLUMN_TYPE NEW_COLUMN_TYPE
30
30
  ```
31
31
 
32
32
  ## Usage
@@ -6,25 +6,26 @@ module Screamers
6
6
  module Generators
7
7
  class MigrationGenerator < ::Rails::Generators::Base
8
8
  desc 'Creates a migration file made [Screamers Task]'
9
- argument :old_column_type, type: :string, banner: 'old column type'
10
- argument :new_column_type, type: :string, banner: 'new column type'
9
+ argument :old_column_type, type: :string, banner: 'OLD_COLUMN_TYPE'
10
+ argument :new_column_type, type: :string, banner: 'NEW_COLUMN_TYPE'
11
11
 
12
12
  def self.source_root
13
13
  File.expand_path('../templates', __FILE__)
14
14
  end
15
15
 
16
16
  def create_migration_file
17
- collector = Screamers::SchemaCollector.new(old_column_type, new_column_type)
17
+ collector = Screamers::ColumnCollector.new(old_column_type, new_column_type)
18
18
 
19
- @target_columns = collector.collect_schema
19
+ @target_columns = collector.collect_columns
20
20
 
21
21
  if @target_columns.empty?
22
22
  puts '[Screamers] There is no change in the schema.'; exit!
23
23
  end
24
24
 
25
+ migrations_path = ActiveRecord::Migrator.migrations_paths.first
25
26
  file_name = "#{Time.current.strftime('%Y%m%d%H%M%S')}_change_#{old_column_type}_to_#{new_column_type}_using_screamers"
26
27
 
27
- template 'migration.rb.tt', File.join('db/migrate', "#{file_name}.rb")
28
+ template 'migration.rb.tt', File.join(migrations_path, "#{file_name}.rb")
28
29
  end
29
30
  end
30
31
  end
data/lib/screamers.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  require 'active_record'
4
- require 'screamers/schema_collector'
4
+ require 'screamers/column_collector'
5
5
  require 'screamers/version'
@@ -1,20 +1,22 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  module Screamers
4
- class SchemaCollector
4
+ class ColumnCollector
5
5
  def initialize(old_column_type, new_column_type)
6
6
  @old_column_type = old_column_type.to_sym
7
7
  @new_column_type = new_column_type.to_sym
8
8
  end
9
9
 
10
- migrations_paths = ActiveRecord::Migrator.migrations_paths.first
11
-
12
- def collect_schema
10
+ def collect_columns
13
11
  tables = ActiveRecord::Base.connection.tables
14
- tables.delete('ar_internal_metadata')
15
12
 
16
13
  @target_tables = tables.each_with_object({}) {|table, target|
17
- columns = Module.const_get(table.classify).columns rescue next
14
+ begin
15
+ columns = Module.const_get(table.classify).columns
16
+ rescue
17
+ puts "An ActiveRecord model mapped to `#{table}` foo could not be found. Please check if you need handmade by yourself."
18
+ next
19
+ end
18
20
 
19
21
  target_columns = columns.select {|column|
20
22
  column.type == @old_column_type
@@ -1,3 +1,3 @@
1
1
  module Screamers
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screamers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-28 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -127,8 +127,7 @@ files:
127
127
  - lib/rails/generators/screamers/migration/migration_generator.rb
128
128
  - lib/rails/generators/screamers/migration/templates/migration.rb.tt
129
129
  - lib/screamers.rb
130
- - lib/screamers/railtie.rb
131
- - lib/screamers/schema_collector.rb
130
+ - lib/screamers/column_collector.rb
132
131
  - lib/screamers/version.rb
133
132
  - screamers.gemspec
134
133
  homepage: https://github.com/koic/screamers
@@ -1,5 +0,0 @@
1
- class Railtie < Rails::Railtie
2
- rake_tasks do
3
- Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |f| load f }
4
- end
5
- end