Sha256: 6b3f1fb2dc376d84c68354314a116de330255b689900d8aaca1088760da95f77

Contents?: true

Size: 1.9 KB

Versions: 26

Compression:

Stored size: 1.9 KB

Contents

class Card
  class Action
    # a collection of methods for comparing actions
    module Differ
      # compare action's name value with previous name value
      # @return [rendered diff]
      def name_diff opts={}
        return unless new_name?
        diff_object(:name, opts).complete
      end

      # @return [rendered diff]
      # compare action's cardtype value with previous cardtype value
      def cardtype_diff opts={}
        return unless new_type?
        diff_object(:cardtype, opts).complete
      end

      # @return [rendered diff]
      # compare action's content value with previous content value
      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

      # test whether content was visibly removed
      # @return [true/false]
      def red?
        content_diff_object.red?
      end

      # test whether content was visibly added
      # @return [true/false]
      def green?
        content_diff_object.green?
      end

      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

      def summary_diff_omits_content?
        content_diff_object.summary_omits_content?
      end

      private

      def diff_object field, opts
        Card::Content::Diff.new previous_value(field), value(field), opts
      end

      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
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
card-1.94.1 mod/history/lib/card/action/differ.rb
card-1.94.0 mod/history/lib/card/action/differ.rb
card-1.93.13 mod/history/lib/card/action/differ.rb
card-1.93.12 mod/history/lib/card/action/differ.rb
card-1.93.11 mod/history/lib/card/action/differ.rb
card-1.93.10 mod/history/lib/card/action/differ.rb
card-1.93.9 mod/history/lib/card/action/differ.rb
card-1.93.8 mod/history/lib/card/action/differ.rb
card-1.93.7 mod/history/lib/card/action/differ.rb
card-1.93.6 mod/history/lib/card/action/differ.rb
card-1.93.5 mod/history/lib/card/action/differ.rb
card-1.93.4 mod/history/lib/card/action/differ.rb
card-1.93.3 mod/history/lib/card/action/differ.rb
card-1.93.2 mod/history/lib/card/action/differ.rb
card-1.93.1 mod/history/lib/card/action/differ.rb
card-1.93.0 mod/history/lib/card/action/differ.rb
card-1.92.2 mod/history/lib/card/action/differ.rb
card-1.92.1 mod/history/lib/card/action/differ.rb
card-1.92 mod/history/lib/card/action/differ.rb
card-1.91 mod/history/lib/card/action/differ.rb