Class: Assets::Generators::ModelGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/assets/model_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_migrationObject



16
17
18
# File 'lib/generators/assets/model_generator.rb', line 16

def copy_migration
  migration_template "migration.rb", "db/migrate/create_#{table_name}"
end

#generate_modelObject



12
13
14
# File 'lib/generators/assets/model_generator.rb', line 12

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

#inject_contentObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/assets/model_generator.rb', line 20

def inject_content
  inject_into_class model_path, class_name, %q{
  # Setup accessible (or protected) attributes for your model
  attr_accessible :name, :description, :owner_type, :owner_id

  belongs_to :owner, :polymorphic => true

  validates_presence_of :owner

  has_attached_file :attachment

  %w(image doc pdf xls).each do |file_type|
    define_method "is_#{file_type}?" do
attachment_content_type.present? && attachment_content_type.include?("#{file_type}")
    end
  end

}
end