2015-09-28 04:11:33 -04:00
|
|
|
require 'rails/generators/named_base'
|
|
|
|
require 'generators/aasm/orm_helpers'
|
|
|
|
|
|
|
|
module Mongoid
|
|
|
|
module Generators
|
|
|
|
class AASMGenerator < Rails::Generators::NamedBase
|
|
|
|
include AASM::Generators::OrmHelpers
|
2016-02-21 06:30:37 -05:00
|
|
|
namespace "mongoid:aasm"
|
2015-09-28 04:11:33 -04:00
|
|
|
argument :column_name, type: :string, default: 'aasm_state'
|
|
|
|
|
|
|
|
def generate_model
|
|
|
|
invoke "mongoid:model", [name] unless model_exists?
|
2016-02-21 06:30:37 -05:00
|
|
|
end
|
2015-09-28 04:11:33 -04:00
|
|
|
|
|
|
|
def inject_aasm_content
|
|
|
|
inject_into_file model_path, model_contents, after: "include Mongoid::Document\n" if model_exists?
|
2016-02-21 06:30:37 -05:00
|
|
|
end
|
2015-09-28 04:11:33 -04:00
|
|
|
|
|
|
|
def inject_field_types
|
|
|
|
inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists?
|
2016-02-21 06:30:37 -05:00
|
|
|
end
|
2015-09-28 04:11:33 -04:00
|
|
|
|
|
|
|
def migration_data
|
|
|
|
" field :#{column_name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|