Sha256: fa901b6402ea4ec3da255b6cef26c98ce2772aff161b80f8eeee373873120a6b

Contents?: true

Size: 1.29 KB

Versions: 16

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    class EnhanceInstructionInteractor < BaseInteractor
      TAB_INDEX = %i(instructions videos generic).freeze

      attr_reader :props

      def run
        @props = pagination.serialize(data, serializer)
        @props.merge!(filterbar.props)
        @props.merge!(tab: active_tab)
      end

      private

      def filterbar
        @filterbar ||= Filterbar.new(params)
      end

      def pagination
        @pagination ||= Pagination.new(params)
      end

      def active_tab
        @active_tab ||= (params[:tab] || 0).to_i
      end

      def tab(name)
        TAB_INDEX.index(name)
      end

      def data
        case active_tab
        when tab(:videos) then resources(:media)
        else resources(:generic_resources)
        end
      end

      def serializer
        ResourceInstructionSerializer
      end

      def resources(type)
        scope = Resource
                  .send(type)
                  .where_subject(filterbar.subjects)
                  .where_grade(filterbar.grades)

        scope = if type == :media
                  scope.order(created_at: :desc)
                else
                  scope.ordered
                end

        scope.paginate(pagination.params(strict: true))
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.5.4 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.5.3 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.5.2 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.5.1 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.5.0 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.4.2 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.4.1 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.4.0 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.3.1 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.1.4 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.3.0 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.1.3 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.2.0 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.1.2 app/interactors/lcms/engine/enhance_instruction_interactor.rb
lcms-engine-0.1.0 app/interactors/lcms/engine/enhance_instruction_interactor.rb