Skip to content

Commit

Permalink
Merge pull request #329 from anilmaurya/master
Browse files Browse the repository at this point in the history
Add namespace to aasm generator
  • Loading branch information
alto committed Feb 22, 2016
2 parents 82f592a + 24f757b commit 497a903
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions lib/generators/aasm/aasm_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
module AASM
module Generators
class AASMGenerator < Rails::Generators::NamedBase

source_root File.expand_path("../templates", __FILE__)
namespace "aasm"
argument :column_name, type: :string, default: 'aasm_state'

desc "Generates a model with the given NAME (if one does not exist) with aasm " <<
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/active_record/aasm_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module ActiveRecord
module Generators
class AASMGenerator < ActiveRecord::Generators::Base
include AASM::Generators::OrmHelpers

namespace "active_record:aasm"
argument :column_name, type: :string, default: 'aasm_state'

source_root File.expand_path("../templates", __FILE__)
Expand All @@ -16,11 +16,11 @@ def copy_aasm_migration
else
migration_template "migration.rb", "db/migrate/aasm_create_#{table_name}.rb"
end
end
end

def generate_model
invoke "active_record:model", [name], migration: false unless model_exists?
end
end

def inject_aasm_content
content = model_contents
Expand Down
8 changes: 4 additions & 4 deletions lib/generators/mongoid/aasm_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ module Mongoid
module Generators
class AASMGenerator < Rails::Generators::NamedBase
include AASM::Generators::OrmHelpers

namespace "mongoid:aasm"
argument :column_name, type: :string, default: 'aasm_state'

def generate_model
invoke "mongoid:model", [name] unless model_exists?
end
end

def inject_aasm_content
inject_into_file model_path, model_contents, after: "include Mongoid::Document\n" if model_exists?
end
end

def inject_field_types
inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists?
end
end

def migration_data
" field :#{column_name}"
Expand Down

0 comments on commit 497a903

Please sign in to comment.