Module: ContextExposer::BaseController
- Extended by:
- ActiveSupport::Concern
- Includes:
- Integrations::Base
- Included in:
- ResourceController
- Defined in:
- lib/context_exposer/base_controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#build_page_obj ⇒ Object
TODO: cleanup!.
- #calc_resource_type ⇒ Object
-
#configure_exposed_context ⇒ Object
must be called after Controller is instantiated.
- #configured_exposed_context? ⇒ Boolean
- #page_obj ⇒ Object
- #save_exposed_context ⇒ Object
- #view_ctx ⇒ Object (also: #ctx)
Instance Method Details
#build_page_obj ⇒ Object
TODO: cleanup!
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/context_exposer/base_controller.rb', line 125 def build_page_obj return @page if @page @page = ContextExposer::Page.instance @page.clear! clazz = self.class # single or list resource ? @page.resource.type = calc_resource_type if calc_resource_type # also attempts to auto-caluclate resource.type if not set @page.resource.name = if clazz.respond_to?(:normalized_resource_name, true) clazz.normalized_resource_name else clazz.resource_name if clazz.respond_to?(:resource_name, true) end @page.controller = self @page.name = if respond_to?(:page_name, true) page_name else @page_name if @page_name end @page end |
#calc_resource_type ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/context_exposer/base_controller.rb', line 152 def calc_resource_type return @resource_type if @resource_type clazz = self.class if clazz.respond_to?(:list_actions, true) && !clazz.list_actions.blank? resource_type = :list if clazz.list_actions[action_name.to_sym] end if !resource_type && clazz.respond_to?(:item_actions, true) && !clazz.item_actions.blank? resource_type = :item if clazz.item_actions[action_name.to_sym] end @resource_type = resource_type end |
#configure_exposed_context ⇒ Object
must be called after Controller is instantiated
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/context_exposer/base_controller.rb', line 105 def configure_exposed_context return if configured_exposed_context? clazz = self.class exposed_methods = clazz.send(:_exposure_hash)[clazz.to_s] || [] exposed_methods.each do |name, obj| = obj[:options] || {} [:cached] ? _add_cached_ctx_method(obj, name) : _add_ctx_method(obj, name) end @configured_exposed_context = true end |
#configured_exposed_context? ⇒ Boolean
166 167 168 |
# File 'lib/context_exposer/base_controller.rb', line 166 def configured_exposed_context? @configured_exposed_context == true end |
#page_obj ⇒ Object
120 121 122 |
# File 'lib/context_exposer/base_controller.rb', line 120 def page_obj @page ||= build_page_obj end |
#save_exposed_context ⇒ Object
116 117 118 |
# File 'lib/context_exposer/base_controller.rb', line 116 def save_exposed_context ContextExposer::PageContext.instance.configure ctx, page_obj end |
#view_ctx ⇒ Object Also known as: ctx
16 17 18 |
# File 'lib/context_exposer/base_controller.rb', line 16 def view_ctx @view_ctx ||= build_view_ctx end |