module VsAccessControl
include VsAccessControl
to the class you want access control tell to AccessControl which methods allow access like
allow_access :create do
user_signed_in?
end
default is close all access
Constants
- VERSION
Attributes
auth_procs_hash[RW]
Public Class Methods
included(base)
click to toggle source
# File lib/vs_access_control.rb, line 13 def self.included(base) base.extend ClassMethods base.instance_eval do before_action :auth? class << self attr_accessor :auth_procs_hash end self.auth_procs_hash = {} end end
Private Instance Methods
access_denied()
click to toggle source
# File lib/vs_access_control.rb, line 54 def access_denied render :text => "Not authorized.", :status => 403 end
auth?()
click to toggle source
# File lib/vs_access_control.rb, line 40 def auth? auth_proc = self.class.auth_procs_hash[action_name.to_sym] return access_denied if auth_proc.nil? if auth_proc != :not_required # it will call the block when you define the allow_access # access_denied if false unless self.instance_eval &auth_proc return access_denied end end end