Class: ActionController::Base
- Inherits:
-
Object
- Object
- ActionController::Base
- Defined in:
- lib/secure_scope/controller_initializer.rb
Defined Under Namespace
Classes: NotAllowed
Class Method Summary collapse
Instance Method Summary collapse
- #get_model(permission_key) ⇒ Object
- #scope_builder(scope) ⇒ Object
- #user_type_match?(permission_key) ⇒ Boolean
Class Method Details
.method_builder(scopes_hash, action_key) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# 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 || if user_type_match?() return scope_builder scopes_hash[action_key][] end end raise NotAllowed end end |
.secure_scope(scopes_hash) ⇒ Object
4 5 6 7 8 |
# 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 |
Instance Method Details
#get_model(permission_key) ⇒ Object
25 26 27 |
# File 'lib/secure_scope/controller_initializer.rb', line 25 def get_model() Kernel.const_get(.to_s.camelize) end |
#scope_builder(scope) ⇒ Object
29 30 31 32 |
# 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) ⇒ Boolean
21 22 23 |
# File 'lib/secure_scope/controller_initializer.rb', line 21 def user_type_match?() current_authenticated.kind_of? get_model() end |