Sha256: 6dd0544704ba1d184e71cac3b72f4f6fb3d7a4929bcc8df33c03d9ae3d1013b1

Contents?: true

Size: 840 Bytes

Versions: 8

Compression:

Stored size: 840 Bytes

Contents

require 'securerandom'

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

  # This module saves things!
  module Persistence
    extend ActiveSupport::Concern
    
    included do
      self.create_table(self.table_name) unless self.table_exists?(self.table_name)
    end
    
    def save
      self.id = SecureRandom.uuid if self.id.nil? || self.id.blank?
      Dynamoid::Adapter.put_item(self.class.table_name, self.attributes)
      save_indexes
    end
    
    module ClassMethods
      def table_name
        "#{Dynamoid::Config.namespace}_#{self.to_s.downcase.pluralize}"
      end
      
      def create_table(table_name, id = :id)
        Dynamoid::Adapter.create_table(table_name, id.to_sym)
      end
      
      def table_exists?(table_name)
        Dynamoid::Adapter.list_tables.include?(table_name)
      end
    end
  end
  
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
dynamoid-0.1.0 lib/dynamoid/persistence.rb
dynamoid-0.0.7 lib/dynamoid/persistence.rb
dynamoid-0.0.6 lib/dynamoid/persistence.rb
dynamoid-0.0.5 lib/dynamoid/persistence.rb
dynamoid-0.0.4 lib/dynamoid/persistence.rb
dynamoid-0.0.3 lib/dynamoid/persistence.rb
dynamoid-0.0.2 lib/dynamoid/persistence.rb
Dynamoid-0.0.1 lib/dynamoid/persistence.rb