class SecureScope::ControllerInitializer::ActionController::Base
Public Class Methods
method_builder(scopes_hash, action_key)
click to toggle source
# File lib/secure_scope/controller_initializer.rb, line 10 def self.method_builder(scopes_hash, action_key) define_method "#{action_key.to_s}_secure_scope" do scopes_hash[action_key].keys.each do |permission_key| if user_type_match?(permission_key) return scope_builder scopes_hash[action_key][permission_key] end end raise NotAllowed end end
secure_scope(scopes_hash)
click to toggle source
# File lib/secure_scope/controller_initializer.rb, line 4 def self.secure_scope(scopes_hash) scopes_hash.keys.each do |action_key| method_builder(scopes_hash, action_key) if scopes_hash[action_key] end end
Public Instance Methods
get_model(permission_key)
click to toggle source
# File lib/secure_scope/controller_initializer.rb, line 25 def get_model(permission_key) Kernel.const_get(permission_key.to_s.camelize) end
scope_builder(scope)
click to toggle source
# File lib/secure_scope/controller_initializer.rb, line 29 def scope_builder(scope) return scope unless scope.kind_of?(Proc) scope.call(current_authenticated) end
user_type_match?(permission_key)
click to toggle source
# File lib/secure_scope/controller_initializer.rb, line 21 def user_type_match?(permission_key) current_authenticated.kind_of? get_model(permission_key) end