Sha256: 05bd824cec56be13c5568cec4997752304f0e514183162abe3cc96b423befc0b

Contents?: true

Size: 746 Bytes

Versions: 2

Compression:

Stored size: 746 Bytes

Contents

# encoding: utf-8
module Dynamoid #:nodoc:

  module Attributes
    extend ActiveSupport::Concern
    
    attr_accessor :attributes
    alias :raw_attributes :attributes
      
    def write_attribute(name, value)
      attributes[name.to_sym] = value
    end
    alias :[]= :write_attribute
    
    def read_attribute(name)
      attributes[name.to_sym]
    end
    alias :[] :read_attribute
    
    def update_attributes(attributes)
      self.attributes = self.attributes.merge(attributes)
      save
    end
    
    def update_attribute(attribute, value)
      self.attributes[attribute] = value
      save
    end
    
    module ClassMethods
      def attributes
        [self.fields + [:id]].flatten.uniq
      end
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dynamoid-0.1.1 lib/dynamoid/attributes.rb
dynamoid-0.1.0 lib/dynamoid/attributes.rb