Module: ACLSystem2::AccessControl
- Defined in:
- lib/acl_system2/access_control.rb,
lib/acl_system2/access_control/access_sentry.rb,
lib/acl_system2/access_control/class_methods.rb
Defined Under Namespace
Modules: ClassMethods Classes: AccessSentry
Class Method Summary collapse
Instance Method Summary collapse
-
#access_context(context = {}) ⇒ Object
the current access context; will be created if not setup will add current_user and merge any other elements of context.
-
#access_handler ⇒ Object
return the active access handler, fallback to RoleHandler implement #retrieve_access_handler to return non-default handler.
- #default_access_context ⇒ Object
- #default_access_context=(defaults) ⇒ Object
- #permit?(logicstring, context = {}) ⇒ Boolean
-
#restrict_to(logicstring, context = {}) ⇒ Object
restrict_to “admin | moderator” do link_to “foo” end.
Class Method Details
.included(subject) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/acl_system2/access_control.rb', line 9 def self.included(subject) subject.extend(ClassMethods) if subject.respond_to? :helper_method subject.helper_method(:permit?) subject.helper_method(:restrict_to) end end |
Instance Method Details
#access_context(context = {}) ⇒ Object
the current access context; will be created if not setup will add current_user and merge any other elements of context
29 30 31 |
# File 'lib/acl_system2/access_control.rb', line 29 def access_context(context = {}) default_access_context.merge(context) end |
#access_handler ⇒ Object
return the active access handler, fallback to RoleHandler implement #retrieve_access_handler to return non-default handler
19 20 21 22 23 24 25 |
# File 'lib/acl_system2/access_control.rb', line 19 def access_handler if respond_to?(:retrieve_access_handler) @handler ||= retrieve_access_handler else @handler ||= RoleHandler.new end end |
#default_access_context ⇒ Object
33 34 35 36 37 |
# File 'lib/acl_system2/access_control.rb', line 33 def default_access_context @default_access_context ||= {} @default_access_context[:user] = send(:current_user) if respond_to?(:current_user) @default_access_context end |
#default_access_context=(defaults) ⇒ Object
39 40 41 |
# File 'lib/acl_system2/access_control.rb', line 39 def default_access_context=(defaults) @default_access_context = defaults end |
#permit?(logicstring, context = {}) ⇒ Boolean
43 44 45 |
# File 'lib/acl_system2/access_control.rb', line 43 def permit?(logicstring, context = {}) access_handler.process(logicstring, access_context(context)) end |
#restrict_to(logicstring, context = {}) ⇒ Object
restrict_to “admin | moderator” do
link_to "foo"
end
50 51 52 53 54 55 56 57 |
# File 'lib/acl_system2/access_control.rb', line 50 def restrict_to(logicstring, context = {}) return false if current_user.nil? result = '' if permit?(logicstring, context) result = yield if block_given? end result end |