module Card::Action::Differ

a collection of methods for comparing actions

Public Instance Methods

cardtype_diff(opts={}) click to toggle source

@return [rendered diff] compare action's cardtype value with previous cardtype value

# File lib/card/action/differ.rb, line 21
def cardtype_diff opts={}
  return unless new_type?

  diff_object(:cardtype, opts).complete
end
content_diff(diff_type=:expanded, opts=nil) click to toggle source

@return [rendered diff] compare action's content value with previous content value

# File lib/card/action/differ.rb, line 35
def content_diff diff_type=:expanded, opts=nil
  return unless new_content?

  dobj = content_diff_object(opts)
  diff_type == :summary ? dobj.summary : dobj.complete
end
green?() click to toggle source

test whether content was visibly added @return [true/false]

# File lib/card/action/differ.rb, line 56
def green?
  content_diff_object.green?
end
name_diff(opts={}) click to toggle source

compare action's name value with previous name value @return [rendered diff]

# File lib/card/action/differ.rb, line 7
def name_diff opts={}
  return unless new_name?

  diff_object(:name, opts).complete
end
new_content?() click to toggle source

does action change card's content? @return [true/false]

# File lib/card/action/differ.rb, line 44
def new_content?
  !value(:db_content).nil?
end
new_name?() click to toggle source

does action change card's name? @return [true/false]

# File lib/card/action/differ.rb, line 15
def new_name?
  !value(:name).nil?
end
new_type?() click to toggle source

does action change card's type? @return [true/false]

# File lib/card/action/differ.rb, line 29
def new_type?
  !value(:type_id).nil?
end
raw_view(content=nil) click to toggle source
# File lib/card/action/differ.rb, line 60
def raw_view content=nil
  original_content = card.db_content
  card.db_content = content || value(:db_content)
  card.format.render_raw
ensure
  card.db_content = original_content
end
red?() click to toggle source

test whether content was visibly removed @return [true/false]

# File lib/card/action/differ.rb, line 50
def red?
  content_diff_object.red?
end
summary_diff_omits_content?() click to toggle source
# File lib/card/action/differ.rb, line 68
def summary_diff_omits_content?
  content_diff_object.summary_omits_content?
end

Private Instance Methods

content_diff_object(opts=nil) click to toggle source
# File lib/card/action/differ.rb, line 78
def content_diff_object opts=nil
  @diff ||= begin
    diff_args = opts || card.include_set_modules.diff_args
    previous_value = previous_value(:content)
    previous = previous_value ? raw_view(previous_value) : ""
    current = raw_view
    Card::Content::Diff.new previous, current, diff_args
  end
end
diff_object(field, opts) click to toggle source
# File lib/card/action/differ.rb, line 74
def diff_object field, opts
  Card::Content::Diff.new previous_value(field), value(field), opts
end