Class: Reactive::Mvc::Controller::Base

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

Constant Summary collapse

@@protected_instance_variables =
%w(@assigns @performed_redirect @performed_render @parent_controller
@action_name @before_filter_chain_aborted @_params @_flash @_response)
@@template_classes =
{}

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.



58
59
60
# File 'lib/reactive-mvc/controller/base.rb', line 58

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"])


139
140
141
142
# File 'lib/reactive-mvc/controller/base.rb', line 139

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”.



83
84
85
# File 'lib/reactive-mvc/controller/base.rb', line 83

def controller_class_name
  @controller_class_name ||= name.demodulize
end

.controller_nameObject

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



88
89
90
# File 'lib/reactive-mvc/controller/base.rb', line 88

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”.



93
94
95
# File 'lib/reactive-mvc/controller/base.rb', line 93

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.



100
101
102
# File 'lib/reactive-mvc/controller/base.rb', line 100

def hidden_actions
  read_inheritable_attribute(:hidden_actions) || write_inheritable_attribute(:hidden_actions, [])
end

.hide_action(*names) ⇒ Object

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



105
106
107
# File 'lib/reactive-mvc/controller/base.rb', line 105

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"])


127
128
129
130
# File 'lib/reactive-mvc/controller/base.rb', line 127

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

.process(request, response) ⇒ Object

, method = :perform_action, *arguments)



74
75
76
# File 'lib/reactive-mvc/controller/base.rb', line 74

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

.register_template_class(format, klass) ⇒ Object



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

def register_template_class(format, klass)
  @@template_classes[format.to_sym] = klass
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.



112
113
114
# File 'lib/reactive-mvc/controller/base.rb', line 112

def view_paths
  @view_paths || superclass.view_paths
end

.view_paths=(value) ⇒ Object



116
117
118
# File 'lib/reactive-mvc/controller/base.rb', line 116

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"])


202
203
204
# File 'lib/reactive-mvc/controller/base.rb', line 202

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”.



161
162
163
# File 'lib/reactive-mvc/controller/base.rb', line 161

def controller_class_name
  self.class.controller_class_name
end

#controller_nameObject

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



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

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”.



171
172
173
# File 'lib/reactive-mvc/controller/base.rb', line 171

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"])


192
193
194
# File 'lib/reactive-mvc/controller/base.rb', line 192

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.



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/reactive-mvc/controller/base.rb', line 147

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

  log_processing
  send(method, *arguments)

  response
ensure
  process_cleanup
end

#view_pathsObject

View load paths for controller.



178
179
180
# File 'lib/reactive-mvc/controller/base.rb', line 178

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

#view_paths=(value) ⇒ Object



182
183
184
# File 'lib/reactive-mvc/controller/base.rb', line 182

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