Sha256: 6be3fb6f1eb19dc5fd8b6bc9b359db63727490f8f1d059c11c488c96ce2d44d4

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 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 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.0 lib/aldous/controller/action/precondition.rb