Class: ActsAsContentHighlightable::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ActsAsContentHighlightable::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/acts_as_content_highlightable/install_generator.rb
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
- #copy_migration ⇒ Object
- #detect_database ⇒ Object
- #generate_model ⇒ Object
- #migration_version ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
16 17 18 19 20 21 22 23 |
# File 'lib/generators/acts_as_content_highlightable/install_generator.rb', line 16 def self.next_migration_number(dirname) #:nodoc: next_migration_number = current_migration_number(dirname) + 1 if ::ActiveRecord::Base. [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max else "%.3d" % next_migration_number end end |
Instance Method Details
#copy_migration ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/generators/acts_as_content_highlightable/install_generator.rb', line 25 def copy_migration @database = ["database"] || detect_database unless @database.in?([nil, "postgresql", "postgresql-jsonb", "mysql", "sqlite"]) raise Thor::Error, "Unknown database option" end migration_template "active_record_content_highlights_migration.rb", "db/migrate/create_content_highlights.rb", migration_version: migration_version end |
#detect_database ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/generators/acts_as_content_highlightable/install_generator.rb', line 37 def detect_database postgresql_version = ActiveRecord::Base.connection.send(:postgresql_version) rescue 0 if postgresql_version >= 90400 "postgresql-jsonb" elsif postgresql_version >= 90200 "postgresql" end end |
#generate_model ⇒ Object
33 34 35 |
# File 'lib/generators/acts_as_content_highlightable/install_generator.rb', line 33 def generate_model template "active_record_content_highlight_model.rb", "app/models/content_highlight.rb" end |
#migration_version ⇒ Object
46 47 48 49 50 |
# File 'lib/generators/acts_as_content_highlightable/install_generator.rb', line 46 def migration_version if ActiveRecord::VERSION::MAJOR >= 5 "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end end |