Sha256: 58aaeae2e6ee90a34233d4637b130c193f9adb30f14b7d2a8eab31f9211ddfe4

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# -*- encoding : utf-8 -*-
require 'mdwa/generators'

module MDWA
  module DSL

    class EntityAttribute
      
      attr_accessor :entity, :name, :type, :default
      
      ACCEPTED_TYPES = MDWA::Generators::ModelAttribute::STATIC_TYPES
      
      def initialize(entity)
        self.entity = entity
        self.default = false
      end
      
      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
      
      def valid?
        !entity.nil? and !name.blank? and !type.blank? and !type_invalid?
      end
      
      def type_invalid?
        !ACCEPTED_TYPES.include?( self.type.to_sym )
      end
      
      def default?
        self.default
      end
      
      def generate
        "#{name}:#{type}"
      end
      
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mdd-3.0.2 lib/mdwa/dsl/entity_attribute.rb
mdd-3.0.1 lib/mdwa/dsl/entity_attribute.rb