Class: Roomer::Generators::ModelGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Extended by:
ActiveRecord::Generators::Migration
Includes:
Rails::Generators::Migration, Helpers::GeneratorHelper
Defined in:
lib/generators/roomer/model/model_generator.rb

Instance Method Summary collapse

Methods included from Helpers::GeneratorHelper

#migration_dir, #model_exists?, #model_path, #shared?

Instance Method Details

#copy_roomer_migrationObject

Generates migration file of the model



39
40
41
# File 'lib/generators/roomer/model/model_generator.rb', line 39

def copy_roomer_migration
  migration_template "migration.rb", "#{migration_dir}/roomer_create_#{table_name}"
end

#generate_modelObject

Generates the active record model without the migration



19
20
21
# File 'lib/generators/roomer/model/model_generator.rb', line 19

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

#inject_roomer_contentObject

Injects the roomer method to the class Example:

rails generate roomer:model person --shared # will Generate
class Person < ActiveRecord::Base
  roomer :shared
end


29
30
31
32
33
34
35
36
# File 'lib/generators/roomer/model/model_generator.rb', line 29

def inject_roomer_content
  inject_into_class model_path, class_name do
<<-CONTENT
  # tell roomer if this is a shared or tenanted model
  roomer :#{shared? ? "shared" : "tenanted"}
CONTENT
  end
end