class ActionPermission::Base

Attributes

allowed_actions[R]
allowed_params[R]
membership[RW]

Public Class Methods

match_with(source,to) click to toggle source
# File lib/action_permission/base.rb, line 7
def match_with source,to
  Array(to).each do |role|
    alias_method role, source
  end
end
new(membership) click to toggle source
# File lib/action_permission/base.rb, line 18
def initialize(membership)
  load membership
end

Public Instance Methods

allow(actions, &block) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/action_permission/base.rb, line 50
def allow_params options=nil
  @allowed_params ||= []

  if options
    @allowed_params = allow_params_with_options options
  else
    @allowed_params = Array(params)
  end
end
allow_rest_actions(&block) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/action_permission/base.rb, line 46
def params
  []
end

Private Instance Methods

allow_params_with_options(options) click to toggle source
# File lib/action_permission/base.rb, line 62
def allow_params_with_options options
  alt_params = params
  alt_params = Array(options[:only]) if options[:only]
  Array(options[:except]).each {|e| alt_params.delete e } if options[:except]
  alt_params
end