Sha256: ae6f4badc66b49567c8945d3c07b3ca5d46a2640f0030212a392693118b8e17d

Contents?: true

Size: 1.37 KB

Versions: 74

Compression:

Stored size: 1.37 KB

Contents

module GovukContentModels
  module ActionProcessors
    class BaseProcessor
      attr_accessor :actor, :edition, :action_attributes, :event_attributes

      def initialize(actor, edition, action_attributes={}, event_attributes={})
        @actor = actor
        @edition = edition
        @action_attributes = action_attributes
        @event_attributes = event_attributes
      end

      def processed_edition
        if process? && process
          record_action if record_action?
          edition
        end
      end

      protected

      def process?
        true
      end

      def process
        edition.send(action_name)
      end

      def record_action?
        true
      end

      def action_name
        REQUEST_TYPE_TO_PROCESSOR.invert[self.class.name.slice(/.*::(.*)/, 1)]
      end

      def record_action
        new_action = edition.new_action(actor, action_name, action_attributes || {})
        edition.denormalise_users!
        new_action
      end

      def record_action_without_validation
        new_action = edition.new_action_without_validation(actor, action_name, action_attributes || {})
        edition.denormalise_users!
        new_action
      end

      def requester_different?
        if edition.latest_status_action
          edition.latest_status_action.requester_id != actor.id
        else
          true
        end
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
govuk_content_models-47.0.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-46.0.1 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-46.0.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-45.0.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-44.4.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-44.3.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-44.2.1 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-44.2.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-44.1.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-44.0.1 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-44.0.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-43.2.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-43.1.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-43.0.1 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-43.0.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-42.1.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-42.0.1 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-42.0.0 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-41.1.1 lib/govuk_content_models/action_processors/base_processor.rb
govuk_content_models-41.1.0 lib/govuk_content_models/action_processors/base_processor.rb