Sha256: d3ebb70e7ee137740d750b0a447a4b529f48ec5af53f300731dcaf26ce3472a8

Contents?: true

Size: 1.41 KB

Versions: 20

Compression:

Stored size: 1.41 KB

Contents

require 'active_support/inflector'
require 'friendly/document/associations'
require 'friendly/document/attributes'
require 'friendly/document/convenience'
require 'friendly/document/scoping'
require 'friendly/document/storage'

module Friendly
  module Document
    class << self
      attr_writer :documents

      def included(klass)
        documents << klass
        klass.class_eval do
          extend ClassMethods
          attribute :id,         UUID
          attribute :created_at, Time
          attribute :updated_at, Time
        end
      end

      def documents
        @documents ||= []
      end

      def create_tables!
        documents.each { |d| d.create_tables! }
      end
    end

    module ClassMethods
      attr_writer :table_name

      def table_name
        @table_name ||= name.pluralize.underscore
      end
    end

    include Associations
    include Convenience
    include Scoping
    include Storage
    include Attributes

    def table_name
      self.class.table_name
    end

    def new_record?
      new_record
    end

    def new_record
      @new_record = true if @new_record.nil?
      @new_record
    end

    def new_record=(value)
      @new_record = value
    end

    def ==(comparison_object)
      comparison_object.equal?(self) ||
        (comparison_object.is_a?(self.class) &&
          !comparison_object.new_record? && 
            comparison_object.id == id)
    end
  end
end

Version data entries

20 entries across 20 versions & 7 rubygems

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