Class: Journal

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Comparable, JournalDeprecated, JournalFormatter
Defined in:
app/models/journal.rb

Overview

The ActiveRecord model representing journals.

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block)

This is here to allow people to disregard the difference between working with a Journal and the object it is attached to. The lookup is as follows:

> Call super if the method corresponds to one of our attributes (will end up in AR::Base)

> Try the journaled object with the same method and arguments

> On error, call super



110
111
112
113
114
115
# File 'app/models/journal.rb', line 110

def method_missing(method, *args, &block)
  return super if respond_to?(method) || attributes[method.to_s]
  journaled.send(method, *args, &block)
rescue NoMethodError => e
  e.name == method ? super : raise(e)
end

Instance Method Details

- (Object) <=>(other)

In conjunction with the included Comparable module, allows comparison of journal records based on their corresponding version numbers, creation timestamps and IDs.



51
52
53
# File 'app/models/journal.rb', line 51

def <=>(other)
  [version, created_at, id].map(&:to_i) <=> [other.version, other.created_at, other.id].map(&:to_i)
end

- (Object) anchor

The anchor number for html output



63
64
65
# File 'app/models/journal.rb', line 63

def anchor
  version - 1
end

- (Object) css_classes

Returns a string of css classes



97
98
99
100
101
102
# File 'app/models/journal.rb', line 97

def css_classes
  s = 'journal'
  s << ' has-notes' unless notes.blank?
  s << ' has-details' unless details.empty?
  s
end

- (Object) details Also known as: changes



82
83
84
# File 'app/models/journal.rb', line 82

def details
  attributes["changes"] || {}
end

- (Boolean) editable_by?(user)



78
79
80
# File 'app/models/journal.rb', line 78

def editable_by?(user)
  journaled.journal_editable_by?(self, user)
end

- (Boolean) initial?

Returns whether the version has a version number of 1. Useful when deciding whether to ignore the version during reversion, as initial versions have no serialized changes attached. Helps maintain backwards compatibility.



58
59
60
# File 'app/models/journal.rb', line 58

def initial?
  version < 2
end

- (Object) new_value_for(prop)



88
89
90
# File 'app/models/journal.rb', line 88

def new_value_for(prop)
  details[prop.to_s].last if details.keys.include? prop.to_s
end

- (Object) old_value_for(prop)



92
93
94
# File 'app/models/journal.rb', line 92

def old_value_for(prop)
  details[prop.to_s].first if details.keys.include? prop.to_s
end

- (Object) project

Possible shortcut to the associated project



68
69
70
71
72
73
74
75
76
# File 'app/models/journal.rb', line 68

def project
  if journaled.respond_to?(:project)
    journaled.project
  elsif journaled.is_a? Project
    journaled
  else
    nil
  end
end

- (Object) touch_journaled_after_creation



45
46
47
# File 'app/models/journal.rb', line 45

def touch_journaled_after_creation
  journaled.touch
end