Class: Aldous::ControllerAction

Inherits:
Object
  • Object
show all
Includes:
Aldous
Defined in:
lib/aldous/controller_action.rb

Constant Summary

Constants included from Aldous

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Aldous

configuration

Constructor Details

#initialize(controller) ⇒ ControllerAction

Returns a new instance of ControllerAction.



33
34
35
# File 'lib/aldous/controller_action.rb', line 33

def initialize(controller)
  @controller = controller
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



31
32
33
# File 'lib/aldous/controller_action.rb', line 31

def controller
  @controller
end

Class Method Details

.build(controller) ⇒ Object



11
12
13
# File 'lib/aldous/controller_action.rb', line 11

def build(controller)
  Aldous::Controller::Action::Wrapper.new(new(controller))
end

.inherited(klass) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/aldous/controller_action.rb', line 19

def inherited(klass)
  # expose methods from controller to the service, according to configuration
  ::Aldous.configuration.controller_methods_exposed_to_action.each do |method_name|
    unless klass.method_defined?(method_name)
      define_method method_name do
        controller.send(method_name)
      end
    end
  end
end

.perform(controller) ⇒ Object



15
16
17
# File 'lib/aldous/controller_action.rb', line 15

def perform(controller)
  build(controller).perform
end

Instance Method Details

#build_view(respondable_class, extra_data = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/aldous/controller_action.rb', line 53

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

#default_error_respondableObject



49
50
51
# File 'lib/aldous/controller_action.rb', line 49

def default_error_respondable
  ::Aldous::View::Blank::HtmlView
end

#default_view_dataObject



41
42
43
# File 'lib/aldous/controller_action.rb', line 41

def default_view_data
  {}
end

#performObject

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/aldous/controller_action.rb', line 37

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

#preconditionsObject



45
46
47
# File 'lib/aldous/controller_action.rb', line 45

def preconditions
  []
end