Sha256: 4b44f1bd5d56f9ce10e1d23ba9aee57a35b08840654239ce14ba0f588bfdbb6c
Contents?: true
Size: 1.04 KB
Versions: 3
Compression:
Stored size: 1.04 KB
Contents
require "rails/generators" module Statesman class ActiveRecordTransitionGenerator < Rails::Generators::Base desc "Create an ActiveRecord-based transition model"\ "with the required attributes" argument :parent, type: :string, desc: "Your parent model name" argument :klass, type: :string, desc: "Your transition model name" source_root File.expand_path('../templates', __FILE__) def create_model_file template("create_migration.rb.erb", migration_file_name) template("active_record_transition_model.rb.erb", model_file_name) end private def next_migration_number Time.now.utc.strftime("%Y%m%d%H%M%S") end def migration_file_name "db/migrate/#{next_migration_number}_create_#{table_name}.rb" end def model_file_name "app/models/#{klass.underscore}.rb" end def table_name klass.underscore.pluralize end def parent_id parent.underscore + "_id" end def rails_4? Rails.version.split(".").map(&:to_i).first >= 4 end end end
Version data entries
3 entries across 3 versions & 1 rubygems