Class: MDWA::DSL::EntityAttribute
- Inherits:
-
Object
- Object
- MDWA::DSL::EntityAttribute
- Defined in:
- lib/mdwa/dsl/entity_attribute.rb
Constant Summary collapse
- ACCEPTED_TYPES =
MDWA::Generators::ModelAttribute::STATIC_TYPES
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#entity ⇒ Object
Returns the value of attribute entity.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #default? ⇒ Boolean
- #generate ⇒ Object
-
#initialize(entity) ⇒ EntityAttribute
constructor
A new instance of EntityAttribute.
- #raise_errors_if_invalid! ⇒ Object
-
#to_model_attribute ⇒ Object
Return the model attribute generator.
- #type_invalid? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(entity) ⇒ EntityAttribute
Returns a new instance of EntityAttribute.
13 14 15 16 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 13 def initialize(entity) self.entity = entity self.default = false end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
9 10 11 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9 def default @default end |
#entity ⇒ Object
Returns the value of attribute entity.
9 10 11 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9 def entity @entity end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9 def @options end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9 def type @type end |
Instance Method Details
#default? ⇒ Boolean
35 36 37 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 35 def default? self.default end |
#generate ⇒ Object
39 40 41 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 39 def generate "#{name}:#{type}" end |
#raise_errors_if_invalid! ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 18 def raise_errors_if_invalid! if !valid? raise "Invalid entity attribute: name is blank" if self.name.blank? raise "Invalid entity attribute: '#{name}' - type is blank" if self.type.blank? raise "Invalid entity attribute: '#{name}' - type '#{type}' is invalid" if self.type_invalid? raise "Invalid entity attribute: '#{name}' - entity is nil" if self.entity.blank? end end |
#to_model_attribute ⇒ Object
Return the model attribute generator.
46 47 48 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 46 def to_model_attribute self.entity.generator_model.attributes.select{ |m_attr| m_attr.name == self.name }.first end |
#type_invalid? ⇒ Boolean
31 32 33 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 31 def type_invalid? !ACCEPTED_TYPES.include?( self.type.to_sym ) end |
#valid? ⇒ Boolean
27 28 29 |
# File 'lib/mdwa/dsl/entity_attribute.rb', line 27 def valid? !entity.nil? and !name.blank? and !type.blank? and !type_invalid? end |