Module: Perspectives::ControllerAdditions::ClassMethods
- Defined in:
- lib/perspectives/controller_additions.rb
Instance Method Summary collapse
- #perspectives_actions(options = {}) ⇒ Object
- #resolve_perspective_class_name(name) ⇒ Object
- #wrapped_with(perspective, options = {}) ⇒ Object
Instance Method Details
#perspectives_actions(options = {}) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/perspectives/controller_additions.rb', line 111 def perspectives_actions( = {}) self.perspectives_enabled_actions = .slice(:only, :except).each_with_object({}) do |(k, v), h| h[k] = Array(v).map(&:to_s) end respond_to :html, :json, self.responder = Perspectives::Responder end |
#resolve_perspective_class_name(name) ⇒ Object
137 138 139 |
# File 'lib/perspectives/controller_additions.rb', line 137 def resolve_perspective_class_name(name) Perspectives.resolve_partial_class_name(controller_name.camelize, name) end |
#wrapped_with(perspective, options = {}) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/perspectives/controller_additions.rb', line 120 def wrapped_with(perspective, = {}) perspective_klass = resolve_perspective_class_name(perspective) [:only] = Array([:only]).map(&:to_s) if [:only] [:except] = Array([:except]).map(&:to_s) if [:except] [:if] ||= lambda { |c| c.params[perspective_klass.id_param].present? } [:args] ||= lambda do |controller, perspective| { perspective_klass.active_record_klass.name.underscore => perspective_klass.active_record_klass.find(controller.params[perspective_klass.id_param]), .fetch(:as, controller_name.underscore.singularize) => perspective } end self.perspectives_wrapping += [[perspective_klass, ]] end |