Module: Diffrent
- Defined in:
- lib/diffrent.rb
Instance Method Summary collapse
-
#diff_for(attr, old_version, new_version, options = {:format => :html}) ⇒ String
Get a diff between two arbitrary versions of an ActiveRecord object.
-
#has_versions_after?(v) ⇒ Boolean
Are there later versions?.
-
#has_versions_before?(v) ⇒ Boolean
Are there previous versions?.
Instance Method Details
#diff_for(attr, old_version, new_version, options = {:format => :html}) ⇒ String
Get a diff between two arbitrary versions of an ActiveRecord object.
10 11 12 13 14 15 16 17 |
# File 'lib/diffrent.rb', line 10 def diff_for(attr, old_version, new_version, ={:format => :html}) changes = self.changes_between(new_version, old_version) if changes.key?(attr) Diffy::Diff.new(changes[attr].first, changes[attr].last).to_s([:format]) else self.send(attr) end end |
#has_versions_after?(v) ⇒ Boolean
Are there later versions?
29 30 31 |
# File 'lib/diffrent.rb', line 29 def has_versions_after?(v) self.versions.at(v + 1) end |
#has_versions_before?(v) ⇒ Boolean
Are there previous versions?
22 23 24 |
# File 'lib/diffrent.rb', line 22 def has_versions_before?(v) self.versions.at(v - 1) end |