Class: Grn::Generators::P1Generator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Grn::Generators::P1Generator
- Defined in:
- lib/generators/grn/p1_generator.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#resource_attributes ⇒ Object
Returns the value of attribute resource_attributes.
-
#resource_name ⇒ Object
Returns the value of attribute resource_name.
-
#resource_type ⇒ Object
Returns the value of attribute resource_type.
-
#resource_type_attributes ⇒ Object
Returns the value of attribute resource_type_attributes.
-
#resource_type_name ⇒ Object
Returns the value of attribute resource_type_name.
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ P1Generator
constructor
A new instance of P1Generator.
- #insert_into_classes ⇒ Object
- #mdd_associations ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ P1Generator
Returns a new instance of P1Generator.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/grn/p1_generator.rb', line 20 def initialize(*args, &block) super # resource type @resource_type_name = .type_name || ask("\nChoose the resource type name.\nExample: Category, ProductCategory, etc.\nResource type name:") @resource_type = Mdd::Generators::Model.new( @resource_type_name ) print_usage unless @resource_type.valid? #resource type attributes @resource_type_attributes = .type_attributes || ask("\n=============================\nChoose the resource type attributes.\nSyntax: similar to MDD gem. Description is already included.\nResource type attributes:") @resource_type_attributes.split(' ').each do |attribute| @resource_type.add_attribute Mdd::Generators::ModelAttribute.new( attribute ) end # resource @resource_name = .resource_name || ask("\n=============================\nChoose the resource name.\nExample: Product, Movie, Equipment, etc.\nResource name:") @resource = Mdd::Generators::Model.new( @resource_name ) print_usage unless @resource.valid? # resource attributes @resource_attributes = .resource_attributes || ask("\n=============================\nChoose the resource attributes.\nSyntax: similar to MDD gem. Description is already included.\nResource attributes:") @resource_attributes.split(' ').each do |attribute| @resource.add_attribute Mdd::Generators::ModelAttribute.new( attribute ) end end |
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
12 13 14 |
# File 'lib/generators/grn/p1_generator.rb', line 12 def resource @resource end |
#resource_attributes ⇒ Object
Returns the value of attribute resource_attributes.
12 13 14 |
# File 'lib/generators/grn/p1_generator.rb', line 12 def resource_attributes @resource_attributes end |
#resource_name ⇒ Object
Returns the value of attribute resource_name.
12 13 14 |
# File 'lib/generators/grn/p1_generator.rb', line 12 def resource_name @resource_name end |
#resource_type ⇒ Object
Returns the value of attribute resource_type.
12 13 14 |
# File 'lib/generators/grn/p1_generator.rb', line 12 def resource_type @resource_type end |
#resource_type_attributes ⇒ Object
Returns the value of attribute resource_type_attributes.
12 13 14 |
# File 'lib/generators/grn/p1_generator.rb', line 12 def resource_type_attributes @resource_type_attributes end |
#resource_type_name ⇒ Object
Returns the value of attribute resource_type_name.
12 13 14 |
# File 'lib/generators/grn/p1_generator.rb', line 12 def resource_type_name @resource_type_name end |
Instance Method Details
#insert_into_classes ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/generators/grn/p1_generator.rb', line 62 def insert_into_classes # resource type inject_into_class "app/models/#{@resource_type.space}/#{@resource_type.singular_name}.rb", @resource_type.klass.classify.constantize do "include Grn::ResourceType" end # resource inject_into_class "app/models/#{@resource.space}/#{@resource.singular_name}.rb", @resource.klass.classify.constantize do "include Grn::Resource" end end |
#mdd_associations ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/grn/p1_generator.rb', line 49 def mdd_associations # resouce type # generate the scaffold with the attributes generate "mdd:scaffold #{@resource_type.raw} description:string #{@resource_type.attributes.map{ |attr| attr.raw }.join(' ')}" # resouce # generate the scaffold with the attributes and belongs_to resource type generate "mdd:scaffold #{@resource.raw} description:string #{@resource.attributes.map{ |attr| attr.raw }.join(' ')} #{@resource_type.singular_name}:#{@resource_type.raw}:description:belongs_to" end |