Class: ActionPermission::Base
- Inherits:
-
Object
- Object
- ActionPermission::Base
- Defined in:
- lib/action_permission/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#allowed_actions ⇒ Object
readonly
Returns the value of attribute allowed_actions.
-
#allowed_params ⇒ Object
readonly
Returns the value of attribute allowed_params.
-
#membership ⇒ Object
Returns the value of attribute membership.
Class Method Summary collapse
Instance Method Summary collapse
- #allow(actions, &block) ⇒ Object
- #allow?(action, resource = nil) ⇒ Boolean
- #allow_params(options = nil) ⇒ Object
- #allow_rest_actions(&block) ⇒ Object
-
#initialize(membership) ⇒ Base
constructor
A new instance of Base.
- #load(membership) ⇒ Object
- #params ⇒ Object
Constructor Details
#initialize(membership) ⇒ Base
Returns a new instance of Base.
18 19 20 |
# File 'lib/action_permission/base.rb', line 18 def initialize(membership) load membership end |
Instance Attribute Details
#allowed_actions ⇒ Object (readonly)
Returns the value of attribute allowed_actions.
16 17 18 |
# File 'lib/action_permission/base.rb', line 16 def allowed_actions @allowed_actions end |
#allowed_params ⇒ Object (readonly)
Returns the value of attribute allowed_params.
16 17 18 |
# File 'lib/action_permission/base.rb', line 16 def allowed_params @allowed_params end |
#membership ⇒ Object
Returns the value of attribute membership.
15 16 17 |
# File 'lib/action_permission/base.rb', line 15 def membership @membership end |
Class Method Details
.match_with(source, to) ⇒ Object
7 8 9 10 11 |
# File 'lib/action_permission/base.rb', line 7 def match_with source,to Array(to).each do |role| alias_method role, source end end |
Instance Method Details
#allow(actions, &block) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/action_permission/base.rb', line 35 def allow(actions, &block) @allowed_actions ||= {} Array(actions).each do |action| @allowed_actions[action.to_s] = block || true end end |
#allow?(action, resource = nil) ⇒ Boolean
30 31 32 33 |
# File 'lib/action_permission/base.rb', line 30 def allow?(action, resource = nil) allowed = @allowed_actions[action.to_s] if @allowed_actions allowed && (allowed == true || resource && allowed.call(resource)) end |
#allow_params(options = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/action_permission/base.rb', line 50 def allow_params =nil @allowed_params ||= [] if @allowed_params = else @allowed_params = Array(params) end end |
#allow_rest_actions(&block) ⇒ Object
42 43 44 |
# File 'lib/action_permission/base.rb', line 42 def allow_rest_actions(&block) allow [:index, :new, :create, :show, :edit, :update, :destroy], &block end |
#load(membership) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/action_permission/base.rb', line 22 def load(membership) @membership = membership role = @membership.identify if role && respond_to?(role) send(role) end end |
#params ⇒ Object
46 47 48 |
# File 'lib/action_permission/base.rb', line 46 def params [] end |