Sha256: 434fc03cfa61c35bc6c747dc9666164c8c2823addc1a9b736822b4da6d9d6e50

Contents?: true

Size: 1.29 KB

Versions: 20

Compression:

Stored size: 1.29 KB

Contents

require 'friendly/document/mixin'

module Friendly
  module Document
    module Storage
      extend Mixin

      module ClassMethods
        attr_writer :storage_proxy, :query_klass
        
        def create_tables!
          storage_proxy.create_tables!
        end

        def storage_proxy
          @storage_proxy ||= StorageProxy.new(self)
        end

        def indexes(*args)
          storage_proxy.add(args)
        end

        def caches_by(*fields)
          options = fields.last.is_a?(Hash) ? fields.pop : {}
          storage_proxy.cache(fields, options)
        end

        def first(query)
          storage_proxy.first(query(query))
        end

        def all(query)
          storage_proxy.all(query(query))
        end

        def count(conditions)
          storage_proxy.count(query(conditions))
        end

        def query_klass
          @query_klass ||= Query
        end

        protected
          def query(conditions)
            conditions.is_a?(Query) ? conditions : query_klass.new(conditions)
          end
      end
      
      def save
        new_record? ? storage_proxy.create(self) : storage_proxy.update(self)
      end

      def destroy
        storage_proxy.destroy(self)
      end

      def storage_proxy
        self.class.storage_proxy
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 7 rubygems

Version Path
ihoka-friendly-0.8.0.pre lib/friendly/document/storage.rb
ihoka-friendly-0.7.1.2 lib/friendly/document/storage.rb
ihoka-friendly-0.7.1.1 lib/friendly/document/storage.rb
ihoka-friendly-0.7.1 lib/friendly/document/storage.rb
ihoka-friendly-0.7.0 lib/friendly/document/storage.rb
ihoka-friendly-0.6.3 lib/friendly/document/storage.rb
ihoka-friendly-0.6.2 lib/friendly/document/storage.rb
friendly-0.6.0 lib/friendly/document/storage.rb
honkster-friendly-0.5.3 lib/friendly/document/storage.rb
honkster-friendly-0.5.2 lib/friendly/document/storage.rb
honkster-friendly-0.5.1 lib/friendly/document/storage.rb
wayne-friendly-0.5.1 lib/friendly/document/storage.rb
wego-friendly-0.5.1 lib/friendly/document/storage.rb
arunthampi-friendly-0.5.1 lib/friendly/document/storage.rb
friendly_postgres-0.5.1 lib/friendly/document/storage.rb
friendly-0.5.1 lib/friendly/document/storage.rb
friendly-0.5.0 lib/friendly/document/storage.rb
friendly_postgres-0.4.5 lib/friendly/document/storage.rb
friendly-0.4.5 lib/friendly/document/storage.rb
friendly-0.4.4 lib/friendly/document/storage.rb