Sha256: e2d52940cbd0e548fe54c8d967c29bbb47a29eecd339cbbda2ed54c6956f3cac

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

require 'aldous/controller/action/precondition/wrapper'
require 'aldous/build_respondable_service'

module Aldous
  module Controller
    module Action
      class Precondition
        include Aldous

        class << self
          def build(action)
            Aldous::Controller::Action::Precondition::Wrapper.new(new(action))
          end

          def perform(action)
            build(action).perform
          end

          def inherited(klass)
            ::Aldous.configuration.controller_methods_exposed_to_action.each do |method_name|
              unless klass.method_defined?(method_name)
                define_method method_name do
                  action.controller.send(method_name)
                end
              end
            end
          end
        end

        attr_reader :action

        def initialize(action)
          @action = action
        end

        def perform
          raise NotImplementedError.new("#{self.class.name} must implement method #perform")
        end

        def controller
          action.controller
        end

        def build_view(respondable_class, extra_data = {})
          ::Aldous::BuildRespondableService.new(
            view_context: action.controller.view_context,
            default_view_data: action.default_view_data,
            respondable_class: respondable_class,
            status: extra_data[:status],
            extra_data: extra_data
          ).perform
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aldous-1.0.1 lib/aldous/controller/action/precondition.rb