Class: MDWA::DSL::EntityAssociation
- Inherits:
-
Object
- Object
- MDWA::DSL::EntityAssociation
- Defined in:
- lib/mdwa/dsl/entity_association.rb
Constant Summary collapse
- ACCEPTED_TYPES =
[:one_to_many, :many_to_one, :one_to_one, :one_to_one_not_navigable, :many_to_many]
Instance Attribute Summary collapse
-
#composition ⇒ Object
Returns the value of attribute composition.
-
#description ⇒ Object
Returns the value of attribute description.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#destination_view ⇒ Object
Returns the value of attribute destination_view.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#skip_views ⇒ Object
Returns the value of attribute skip_views.
-
#source ⇒ Object
Returns the value of attribute source.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #generate ⇒ Object
-
#generator_type ⇒ Object
Return the mapped type for the code generation.
-
#initialize(source) ⇒ EntityAssociation
constructor
A new instance of EntityAssociation.
- #many_to_many? ⇒ Boolean
- #many_to_one? ⇒ Boolean
- #one_to_many? ⇒ Boolean
- #one_to_one? ⇒ Boolean
- #one_to_one_not_navigable? ⇒ Boolean
- #skip_views! ⇒ Object
- #skip_views? ⇒ Boolean
-
#to_model_association ⇒ Object
Return the model association generator.
Constructor Details
#initialize(source) ⇒ EntityAssociation
Returns a new instance of EntityAssociation.
12 13 14 15 16 17 |
# File 'lib/mdwa/dsl/entity_association.rb', line 12 def initialize(source) self.source = source self.composition = false self.skip_views = false self. = {} end |
Instance Attribute Details
#composition ⇒ Object
Returns the value of attribute composition.
8 9 10 |
# File 'lib/mdwa/dsl/entity_association.rb', line 8 def composition @composition end |
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/mdwa/dsl/entity_association.rb', line 8 def description @description end |
#destination ⇒ Object
Returns the value of attribute destination.
7 8 9 |
# File 'lib/mdwa/dsl/entity_association.rb', line 7 def destination @destination end |
#destination_view ⇒ Object
Returns the value of attribute destination_view.
7 8 9 |
# File 'lib/mdwa/dsl/entity_association.rb', line 7 def destination_view @destination_view end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/mdwa/dsl/entity_association.rb', line 8 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/mdwa/dsl/entity_association.rb', line 8 def @options end |
#skip_views ⇒ Object
Returns the value of attribute skip_views.
8 9 10 |
# File 'lib/mdwa/dsl/entity_association.rb', line 8 def skip_views @skip_views end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/mdwa/dsl/entity_association.rb', line 7 def source @source end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/mdwa/dsl/entity_association.rb', line 8 def type @type end |
Instance Method Details
#generate ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mdwa/dsl/entity_association.rb', line 61 def generate destination = DSL.entity(self.destination.camelize) gen = [] gen << self.name gen << destination.scaffold_name + (destination.model_name != destination.scaffold_name ? ",#{destination.model_name}" : '') gen << (self.destination_view || destination.default_attribute.name) gen << generator_type gen.join(':') end |
#generator_type ⇒ Object
Return the mapped type for the code generation.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mdwa/dsl/entity_association.rb', line 46 def generator_type case self.type.to_sym when :one_to_many return (self.composition ? 'nested_many' : 'has_many' ) when :one_to_one return (self.composition ? 'nested_one' : 'belongs_to' ) when :one_to_one_not_navigable 'has_one' when :many_to_one 'belongs_to' when :many_to_many 'has_and_belongs_to_many' end end |
#many_to_many? ⇒ Boolean
85 86 87 |
# File 'lib/mdwa/dsl/entity_association.rb', line 85 def many_to_many? self.type.to_sym == :many_to_many end |
#many_to_one? ⇒ Boolean
77 78 79 |
# File 'lib/mdwa/dsl/entity_association.rb', line 77 def many_to_one? self.type.to_sym == :many_to_one end |
#one_to_many? ⇒ Boolean
73 74 75 |
# File 'lib/mdwa/dsl/entity_association.rb', line 73 def one_to_many? self.type.to_sym == :one_to_many end |
#one_to_one? ⇒ Boolean
81 82 83 |
# File 'lib/mdwa/dsl/entity_association.rb', line 81 def one_to_one? self.type.to_sym == :one_to_one end |
#one_to_one_not_navigable? ⇒ Boolean
89 90 91 |
# File 'lib/mdwa/dsl/entity_association.rb', line 89 def one_to_one_not_navigable? self.type.to_sym == :one_to_one_not_navigable end |
#skip_views! ⇒ Object
32 33 34 |
# File 'lib/mdwa/dsl/entity_association.rb', line 32 def skip_views! self.skip_views = true end |
#skip_views? ⇒ Boolean
28 29 30 |
# File 'lib/mdwa/dsl/entity_association.rb', line 28 def skip_views? skip_views end |
#to_model_association ⇒ Object
Return the model association generator.
39 40 41 |
# File 'lib/mdwa/dsl/entity_association.rb', line 39 def to_model_association self.source.generator_model.associations.select{ |m_assoc| m_assoc.model2.name.underscore == self.name.underscore }.first end |