Class: Reactive::Controller::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/controller/base.rb

Constant Summary collapse

@@exempt_from_layout =

Templates that are exempt from layouts

Set.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#action_nameObject (readonly)

Returns the name of the action this controller is processing.



30
31
32
# File 'lib/controller/base.rb', line 30

def action_name
  @action_name
end

Class Method Details

.append_view_path(path) ⇒ Object

Adds a view_path to the end of the view_paths array. If the current class has no view paths, copy them from the superclass. This change will be visible for all future requests.

ArticleController.append_view_path("views/default")
ArticleController.append_view_path(["views/default", "views/custom"])


112
113
114
115
# File 'lib/controller/base.rb', line 112

def append_view_path(path)
  @view_paths = superclass.view_paths.dup if @view_paths.nil?
  view_paths.push(*path)
end

.controller_class_nameObject

Converts the class name from something like “OneModule::TwoModule::NeatController” to “NeatController”.



52
53
54
# File 'lib/controller/base.rb', line 52

def controller_class_name
  @controller_class_name ||= name.demodulize
end

.controller_nameObject

Converts the class name from something like “OneModule::TwoModule::NeatController” to “neat”.



57
58
59
# File 'lib/controller/base.rb', line 57

def controller_name
  @controller_name ||= controller_class_name.sub(/Controller$/, '').underscore
end

.controller_pathObject

Converts the class name from something like “OneModule::TwoModule::NeatController” to “one_module/two_module/neat”.



62
63
64
# File 'lib/controller/base.rb', line 62

def controller_path
  @controller_path ||= name.gsub(/Controller$/, '').underscore
end

.hidden_actionsObject

Return an array containing the names of public methods that have been marked hidden from the action processor. By default, all methods defined in ActionController::Base and included modules are hidden. More methods can be hidden using hide_actions.



69
70
71
72
73
74
75
# File 'lib/controller/base.rb', line 69

def hidden_actions
  unless read_inheritable_attribute(:hidden_actions)
    write_inheritable_attribute(:hidden_actions, Controller::Base.public_instance_methods.map(&:to_s))
  end

  read_inheritable_attribute(:hidden_actions)
end

.hide_action(*names) ⇒ Object

Hide each of the given methods from being callable as actions.



78
79
80
# File 'lib/controller/base.rb', line 78

def hide_action(*names)
  write_inheritable_attribute(:hidden_actions, hidden_actions | names.map(&:to_s))
end

.prepend_view_path(path) ⇒ Object

Adds a view_path to the front of the view_paths array. If the current class has no view paths, copy them from the superclass. This change will be visible for all future requests.

ArticleController.prepend_view_path("views/default")
ArticleController.prepend_view_path(["views/default", "views/custom"])


100
101
102
103
# File 'lib/controller/base.rb', line 100

def prepend_view_path(path)
  @view_paths = superclass.view_paths.dup if @view_paths.nil?
  view_paths.unshift(*path)
end

.process(request, response, method = :perform_action, *arguments) ⇒ Object



47
48
49
# File 'lib/controller/base.rb', line 47

def process(request, response, method = :perform_action, *arguments)
  new.process(request, response, method, *arguments)
end

.view_pathsObject

View load paths determine the bases from which template references can be made. So a call to render(“test/template”) will be looked up in the view load paths array and the closest match will be returned.



85
86
87
# File 'lib/controller/base.rb', line 85

def view_paths
  @view_paths || superclass.view_paths
end

.view_paths=(value) ⇒ Object



89
90
91
# File 'lib/controller/base.rb', line 89

def view_paths=(value)
  @view_paths = value
end

Instance Method Details

#append_view_path(path) ⇒ Object

Adds a view_path to the end of the view_paths array. This change affects the current request only.

self.append_view_path("views/default")
self.append_view_path(["views/default", "views/custom"])


176
177
178
# File 'lib/controller/base.rb', line 176

def append_view_path(path)
  (@template || self.class).append_view_path(path)
end

#controller_class_nameObject

Converts the class name from something like “OneModule::TwoModule::NeatController” to “NeatController”.



135
136
137
# File 'lib/controller/base.rb', line 135

def controller_class_name
  self.class.controller_class_name
end

#controller_nameObject

Converts the class name from something like “OneModule::TwoModule::NeatController” to “neat”.



140
141
142
# File 'lib/controller/base.rb', line 140

def controller_name
  self.class.controller_name
end

#controller_pathObject

Converts the class name from something like “OneModule::TwoModule::NeatController” to “one_module/two_module/neat”.



145
146
147
# File 'lib/controller/base.rb', line 145

def controller_path
  self.class.controller_path
end

#prepend_view_path(path) ⇒ Object

Adds a view_path to the front of the view_paths array. This change affects the current request only.

self.prepend_view_path("views/default")
self.prepend_view_path(["views/default", "views/custom"])


166
167
168
# File 'lib/controller/base.rb', line 166

def prepend_view_path(path)
  (@template || self.class).prepend_view_path(path)
end

#process(request, response, method = :perform_action, *arguments) ⇒ Object

Extracts the action_name from the request parameters and performs that action.



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/controller/base.rb', line 120

def process(request, response, method = :perform_action, *arguments) #:nodoc:
  initialize_template_class(response)
  assign_params(request.params)
  assign_shortcuts(request, response)
  forget_variables_added_to_assigns

  log_processing
  send(method, *arguments)

  response
ensure
  process_cleanup
end

#view_pathsObject

View load paths for controller.



152
153
154
# File 'lib/controller/base.rb', line 152

def view_paths
  (@template || self.class).view_paths
end

#view_paths=(value) ⇒ Object



156
157
158
# File 'lib/controller/base.rb', line 156

def view_paths=(value)
  (@template || self.class).view_paths = value
end