Class: MDWA::DSL::EntityAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/mdwa/dsl/entity_attribute.rb

Constant Summary collapse

ACCEPTED_TYPES =
MDWA::Generators::ModelAttribute::STATIC_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#defaultObject

Returns the value of attribute default.



9
10
11
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9

def default
  @default
end

#entityObject

Returns the value of attribute entity.



9
10
11
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9

def entity
  @entity
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9

def name
  @name
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/mdwa/dsl/entity_attribute.rb', line 9

def options
  @options
end

#typeObject

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

Returns:

  • (Boolean)


35
36
37
# File 'lib/mdwa/dsl/entity_attribute.rb', line 35

def default?
  self.default
end

#generateObject



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_attributeObject

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

Returns:

  • (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

Returns:

  • (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