forked from mbulat/plutus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addressing some duplication across generators
- Moves identical methods to a base class - Changes all generators to inherit from base class - Cleans up some excess whitespace in templates - Fixes namespacing in plutus_generator.rb
- Loading branch information
Showing
6 changed files
with
38 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Plutus | ||
class BaseGenerator < Rails::Generators::Base | ||
include Rails::Generators::Migration | ||
|
||
def self.source_root | ||
@source_root ||= File.join(File.dirname(__FILE__), 'templates') | ||
end | ||
|
||
# Implement the required interface for Rails::Generators::Migration. | ||
# See http://apidock.com/rails/ActiveRecord/Generators/Base/next_migration_number/class | ||
def self.next_migration_number(dirname) | ||
if ActiveRecord::Base.timestamped_migrations | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
else | ||
"%.3d" % (current_migration_number(dirname) + 1) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
# lib/generators/plutus/plutus_generator.rb | ||
require 'rails/generators' | ||
require 'rails/generators/migration' | ||
|
||
class PlutusGenerator < Rails::Generators::Base | ||
include Rails::Generators::Migration | ||
|
||
def self.source_root | ||
@source_root ||= File.join(File.dirname(__FILE__), 'templates') | ||
end | ||
|
||
# Implement the required interface for Rails::Generators::Migration. | ||
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb | ||
def self.next_migration_number(dirname) | ||
if ActiveRecord::Base.timestamped_migrations | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
else | ||
"%.3d" % (current_migration_number(dirname) + 1) | ||
end | ||
end | ||
|
||
def create_migration_file | ||
migration_template 'migration.rb', 'db/migrate/create_plutus_tables.rb' | ||
end | ||
|
||
require_relative 'base_generator' | ||
|
||
module Plutus | ||
class PlutusGenerator < BaseGenerator | ||
def create_migration_file | ||
migration_template 'migration.rb', 'db/migrate/create_plutus_tables.rb' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,12 @@ | ||
# lib/generators/plutus/plutus_generator.rb | ||
require 'rails/generators' | ||
require 'rails/generators/migration' | ||
require_relative 'base_generator' | ||
|
||
module Plutus | ||
class UpgradePlutusGenerator < Rails::Generators::Base | ||
include Rails::Generators::Migration | ||
|
||
def self.source_root | ||
@source_root ||= File.join(File.dirname(__FILE__), 'templates') | ||
end | ||
|
||
# Implement the required interface for Rails::Generators::Migration. | ||
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb | ||
def self.next_migration_number(dirname) | ||
if ActiveRecord::Base.timestamped_migrations | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
else | ||
"%.3d" % (current_migration_number(dirname) + 1) | ||
end | ||
end | ||
|
||
def create_migration_file | ||
migration_template 'update_migration.rb', 'db/migrate/update_plutus_tables.rb' | ||
end | ||
|
||
end | ||
class UpgradePlutusGenerator < BaseGenerator | ||
def create_migration_file | ||
migration_template 'update_migration.rb', 'db/migrate/update_plutus_tables.rb' | ||
end | ||
end | ||
end |