Class: Pliable::Generators::ModelGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/pliable/model_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



8
9
10
# File 'lib/generators/pliable/model_generator.rb', line 8

def self.next_migration_number(path)
  @migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i.to_s
end

Instance Method Details

#add_initializerObject



14
15
16
17
18
19
20
21
# File 'lib/generators/pliable/model_generator.rb', line 14

def add_initializer
  create_file "config/initializers/pliable.rb", "Pliable.configure do |config|
  # define extra scrubbing for ply_name here.  This is for the purpose of making scopes.
  # For instance, if your models ply name is something like 'Invoice__c'
  # you will need to gsub '__c' off the end:
  # config.added_scrubber {|name| name.gsub('__c', '') }
end"
end

#generate_migrationObject



27
28
29
30
# File 'lib/generators/pliable/model_generator.rb', line 27

def generate_migration
  # TODO only run if migration dosn't exist
  migration_template "migration.rb", "db/migrate/create_plies_and_ply_relations"
end

#generate_ply_and_relation_modelObject



23
24
25
# File 'lib/generators/pliable/model_generator.rb', line 23

def generate_ply_and_relation_model
  Rails::Generators.invoke("active_record:model", ["Ply", "--parent", "pliable/ply",  "--no-migration" ])
end

#run_migrationsObject



32
33
34
35
36
# File 'lib/generators/pliable/model_generator.rb', line 32

def run_migrations
  unless (ActiveRecord::Base.connection.table_exists?('plies') && (ActiveRecord::Base.connection.table_exists? 'ply_relations'))
    rake("db:migrate db:test:prepare")
  end
end