Class: CartGenerator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CartGenerator

Returns a new instance of CartGenerator.



7
8
9
10
11
# File 'lib/generators/cart_generator.rb', line 7

def initialize *args
  @user_cname = args[0][0]
  @product_cname = args[0][1]
  super
end

Instance Attribute Details

#product_cnameObject

Returns the value of attribute product_cname.



4
5
6
# File 'lib/generators/cart_generator.rb', line 4

def product_cname
  @product_cname
end

#user_cnameObject

Returns the value of attribute user_cname.



4
5
6
# File 'lib/generators/cart_generator.rb', line 4

def user_cname
  @user_cname
end

Instance Method Details

#copy_cart_migrationObject



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

def copy_cart_migration
  migration_template "migration.rb", "db/migrate/create_carts.rb"
end

#ensure_definedObject



13
14
15
# File 'lib/generators/cart_generator.rb', line 13

def ensure_defined
  ensure_classes_defined [:user, :product]
end

#generate_modelObject



17
18
19
20
21
# File 'lib/generators/cart_generator.rb', line 17

def generate_model
  invoke "active_record:model", [ "cart" ], :migration => false
  
  inject_into_class model_path, Cart, model_content 
end