Sha256: 19656b28ca2b81b8a2ebf007fd150a75803025746b9a748853bafe0c43e4c5b3

Contents?: true

Size: 677 Bytes

Versions: 3

Compression:

Stored size: 677 Bytes

Contents

module CouchPillow

  module Attributive

    # Declares a new Attribute
    #
    def attribute attr, &block
      attr = attr.to_s.to_sym
      new_attr = Attribute.new(attr)
      attributes[attr] = new_attr

      # Define accessor methods
      define_method(attr) do
        @data[attr]
      end
      define_method("#{attr}=") do |val|
        @data[attr] = val
      end

      new_attr.instance_eval &block if block

      new_attr
    end


    def attributes
      @attributes ||= {}
    end


    def inherited(subclass)
      # Copy existing attributes to subclasses
      attributes.each do |k, v|
        subclass.attributes[k] = v
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
couchpillow-0.4.5 lib/couchpillow/attributive.rb
couchpillow-0.4.4 lib/couchpillow/attributive.rb
couchpillow-0.4.3 lib/couchpillow/attributive.rb