Module: Canned::ControllerExt::ClassMethods
- Defined in:
- lib/canned/controller_ext.rb
Instance Method Summary collapse
-
#acts_as_restricted(_definition, _method = nil, &_block) ⇒ Object
Setups the controller user profile definitions and profile provider block (or proc).
-
#register_actor(_name, _options = {}, &_block) ⇒ Object
Registers a canned actor.
- #register_default_resources ⇒ Object
-
#register_resource(_name, _options = {}, &_block) ⇒ Object
(also: #load_resource)
Registers a canned resource.
-
#unrestricted(*_excluded) ⇒ Object
Removes protection for the especified controller actions.
-
#unrestricted_all ⇒ Object
Removes protection for all controller actions.
Instance Method Details
#acts_as_restricted(_definition, _method = nil, &_block) ⇒ Object
Setups the controller user profile definitions and profile provider block (or proc)
The passed method or block must return a list of profiles to be validated by the definition.
TODO: default definition (canned config)
91 92 93 94 95 96 97 98 99 |
# File 'lib/canned/controller_ext.rb', line 91 def acts_as_restricted(_definition, _method=nil, &_block) self.before_filter do if is_restricted? profiles = Array(if _method.nil? then instance_eval(&_block) else send(_method) end) raise Canned::AuthError.new 'No profiles avaliable' if profiles.empty? raise Canned::AuthError unless (_definition, profiles) else perform_resource_loading end end end |
#register_actor(_name, _options = {}, &_block) ⇒ Object
Registers a canned actor
122 123 124 |
# File 'lib/canned/controller_ext.rb', line 122 def register_actor(_name, ={}, &_block) self._cn_actors[.fetch(:as, _name)] = _block || _name end |
#register_default_resources ⇒ Object
152 153 154 |
# File 'lib/canned/controller_ext.rb', line 152 def register_default_resources # TODO: Load resources using convention and controller names. end |
#register_resource(_name, _options = {}, &_block) ⇒ Object Also known as: load_resource
Registers a canned resource
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/canned/controller_ext.rb', line 137 def register_resource(_name, ={}, &_block) self._cn_resources ||= [] self._cn_resources << { name: _name, only: unless [:only].nil? then Array([:only]) else nil end, except: Array([:except]), loader: _block || Proc.new do key = .fetch(:using, :id) if params.has_key? key then eval(_name.to_s.camelize).find params[key] else nil end end } end |
#unrestricted(*_excluded) ⇒ Object
Removes protection for the especified controller actions.
110 111 112 113 |
# File 'lib/canned/controller_ext.rb', line 110 def unrestricted(*_excluded) self._cn_excluded ||= [] self._cn_excluded.push(*(_excluded.collect &:to_sym)) end |
#unrestricted_all ⇒ Object
Removes protection for all controller actions.
102 103 104 |
# File 'lib/canned/controller_ext.rb', line 102 def unrestricted_all self._cn_excluded = :all end |