Module: Diffing

Defined in:
lib/drafter/diffing.rb

Instance Method Summary collapse

Instance Method Details

#differences(attr, options = {:format => :html}) ⇒ String

Get a diff between the current and draft status of an ActiveRecord object field.

Parameters:

  • attr (Symbol)

    the attribute you want to diff.

  • options (Hash) (defaults to: {:format => :html})

    an options hash allowing you to pass a :format.

Returns:

  • (String)

    a diff string. If :format was nil, this could be a [Diffy::Diff].



10
11
12
13
14
# File 'lib/drafter/diffing.rb', line 10

def differences(attr, options={:format => :html})
  if self.draft
    Diffy::Diff.new(self.send(attr), self.draft.send(attr)).to_s(options[:format])
  end
end