Module: Friendly::Document

Includes:
Associations, Attributes, Convenience, Scoping, Storage
Defined in:
lib/friendly/document.rb,
lib/friendly/document/mixin.rb,
lib/friendly/document/scoping.rb,
lib/friendly/document/storage.rb,
lib/friendly/document/attributes.rb,
lib/friendly/document/convenience.rb,
lib/friendly/document/associations.rb

Defined Under Namespace

Modules: Associations, Attributes, ClassMethods, Convenience, Mixin, Scoping, Storage

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

#assign, #assign_default_values, #attribute_changed?, #attribute_was, #attributes=, #changed, #changed?, #initialize, #not_changed, #reset_changes, #save, #to_hash, #will_change

Methods included from Mixin

#included

Methods included from Storage

#destroy, #save, #storage_proxy

Methods included from Convenience

#update_attributes

Class Attribute Details

.documentsObject



23
24
25
# File 'lib/friendly/document.rb', line 23

def documents
  @documents ||= []
end

Class Method Details

.create_tables!Object



27
28
29
# File 'lib/friendly/document.rb', line 27

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

.included(klass) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/friendly/document.rb', line 13

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

Instance Method Details

#==(comparison_object) ⇒ Object



63
64
65
66
67
68
# File 'lib/friendly/document.rb', line 63

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

#new_recordObject



54
55
56
57
# File 'lib/friendly/document.rb', line 54

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

#new_record=(value) ⇒ Object



59
60
61
# File 'lib/friendly/document.rb', line 59

def new_record=(value)
  @new_record = value
end

#new_record?Boolean

Returns:



50
51
52
# File 'lib/friendly/document.rb', line 50

def new_record?
  new_record
end

#table_nameObject



46
47
48
# File 'lib/friendly/document.rb', line 46

def table_name
  self.class.table_name
end