Module: Yesterday::Model::ClassMethods

Defined in:
lib/yesterday/model.rb

Instance Method Summary collapse

Instance Method Details

#diff_version(from_version_number, to_version_number) ⇒ Object



62
63
64
65
66
# File 'lib/yesterday/model.rb', line 62

def diff_version(from_version_number, to_version_number)
  if object = first
    Versioning.diff_for from_version_number, to_version_number, object
  end
end

#exclude_tracking_for(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/yesterday/model.rb', line 9

def exclude_tracking_for(options)
  if options[:associations]
    @excluded_tracked_associations ||= []
    @excluded_tracked_associations += Array(options[:associations]).map(&:to_s)
  end

  if options[:attributes]
    @excluded_tracked_attributes ||= []
    @excluded_tracked_attributes += Array(options[:attributes]).map(&:to_s)
  end
end

#excluded_tracked_associationsObject



33
34
35
# File 'lib/yesterday/model.rb', line 33

def excluded_tracked_associations
  @excluded_tracked_associations || []
end

#excluded_tracked_attributesObject



37
38
39
# File 'lib/yesterday/model.rb', line 37

def excluded_tracked_attributes
  @excluded_tracked_attributes || []
end

#include_tracking_for(options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yesterday/model.rb', line 21

def include_tracking_for(options)
  if options[:associations]
    @tracked_associations ||= []
    @tracked_associations += Array(options[:associations]).map(&:to_s)
  end

  if options[:attributes]
    @tracked_attributes ||= []
    @tracked_attributes += Array(options[:attributes]).map(&:to_s)
  end
end

#track_changes(options = {}) ⇒ Object



49
50
51
52
53
54
# File 'lib/yesterday/model.rb', line 49

def track_changes(options = {})
  send :include, InstanceMethods

  after_save :serialize_current_state
  exclude_tracking_for :associations => :changesets
end

#tracked_associationsObject



41
42
43
# File 'lib/yesterday/model.rb', line 41

def tracked_associations
  @tracked_associations || []
end

#tracked_attributesObject



45
46
47
# File 'lib/yesterday/model.rb', line 45

def tracked_attributes
  @tracked_attributes || []
end

#version(version_number) ⇒ Object



56
57
58
59
60
# File 'lib/yesterday/model.rb', line 56

def version(version_number)
  if object = first
    Versioning.versioned_object_for version_number, object
  end
end