Sha256: cebea3832db3d53412fbaf6f56f839247cbaaa4e0f471e3fdb25ff322f98d815

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module ActionTracker
  module Templates
    class BaseTemplate
      attr_reader :target, :options

      def initialize(target, options = {})
        @target = target
        @options = options
      end

      def form
        @form ||= ActionTracker::Models::TransitionRecord.new(
          payload: payload,
          reference: reference
        ).with_target(target)
      end

      protected

      def payload
        @payload ||= build_payload
      end

      def build_payload
        payload_instance = ActionTracker::Models::Payload.new

        payload_instance
          .with_user(user)
          .with_content(content)
          .for_event(event_title)
      end

      def user
        @user ||= options[:user] || ActionTracker::Models::User.default_user
      end

      # Override
      #
      def content
        options[:content] || target.try(:id)
      end

      def event_title
        [title_prepend, event_name, title_append].compact.join(' ').humanize
      end

      def event_name
        # Override
      end

      def title_prepend
        options[:title_prepend]
      end

      def title_append
        options[:title_append]
      end

      def reference
        options[:reference]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
action_tracker_client-0.1.4 lib/action_tracker/templates/base_template.rb
action_tracker_client-0.1.3 lib/action_tracker/templates/base_template.rb
action_tracker_client-0.1.2 lib/action_tracker/templates/base_template.rb
action_tracker_client-0.1.1 lib/action_tracker/templates/base_template.rb