Sha256: 7cca462524e3b903afa39b5d9a51f3b0a35caa5f712c51318cbfb3bf0e8d6eed

Contents?: true

Size: 905 Bytes

Versions: 2

Compression:

Stored size: 905 Bytes

Contents

module Firebrew
  module Entity
    def self.included(base)
      base.class_eval do
        extend ClassMethod
      end
    end
    
    module ClassMethod
      attr_accessor :attributes
      
      def self.extended(base)
        base.attributes = []
      end
      
      def inherited(base)
        base.attributes = self.attributes.clone
      end
      
      def entity_attr(*attrs)
        attrs.uniq!
        common = self.attributes & attrs
        adding = attrs - common
        self.attributes.push(*adding)
        attr_accessor *adding
        adding
      end
    end
    
    def initialize(attributes={})
      attributes.each do |(k,v)|
        self.send("#{k}=", v)
      end
    end
    
    def ==(rop)
      self.class.attributes.each do |attr|
        return false unless self.send(attr) == rop.send(attr)
      end
      return true
    end
    
    alias :eql? :==
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
firebrew-0.3.0 lib/firebrew/entity.rb
firebrew-0.2.0 lib/firebrew/entity.rb