Module: Controlist
- Defined in:
- lib/controlist.rb,
lib/controlist/errors.rb,
lib/controlist/version.rb,
lib/controlist/permission.rb,
lib/controlist/interceptor.rb,
lib/controlist/managers/base_manager.rb,
lib/controlist/permissions/constrain.rb,
lib/controlist/permissions/operation.rb,
lib/controlist/permissions/ordered_package.rb,
lib/controlist/permissions/simple_constrain.rb,
lib/controlist/managers/thread_based_manager.rb,
lib/controlist/permissions/advanced_constrain.rb
Defined Under Namespace
Modules: Managers, Permissions Classes: ControlistError, Interceptor, NoPermissionError, NotReuseableError, Permission, PermissionForbidden
Constant Summary collapse
- VERSION =
"0.3.2"
Class Attribute Summary collapse
-
.attribute_proxy ⇒ Object
Returns the value of attribute attribute_proxy.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.permission_manager ⇒ Object
Returns the value of attribute permission_manager.
-
.value_object_proxy ⇒ Object
Returns the value of attribute value_object_proxy.
Class Method Summary collapse
- .debug(*args, &block) ⇒ Object
- .enable_logger ⇒ Object
- .has_permission(klass, operation) ⇒ Object
-
.initialize(permission_manager, config = {}) ⇒ Object
example: Controlist.initialize Controlist::Managers::ThreadBasedManager attribute_proxy: “_val”, value_object_proxy: “_value_object”, logger: Logger.new(STDOUT).
- .is_activerecord3? ⇒ Boolean
-
.skip ⇒ Object
Skip Controlist interceptor.
Class Attribute Details
.attribute_proxy ⇒ Object
Returns the value of attribute attribute_proxy.
11 12 13 |
# File 'lib/controlist.rb', line 11 def attribute_proxy @attribute_proxy end |
.logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/controlist.rb', line 11 def logger @logger end |
.permission_manager ⇒ Object
Returns the value of attribute permission_manager.
11 12 13 |
# File 'lib/controlist.rb', line 11 def @permission_manager end |
.value_object_proxy ⇒ Object
Returns the value of attribute value_object_proxy.
11 12 13 |
# File 'lib/controlist.rb', line 11 def value_object_proxy @value_object_proxy end |
Class Method Details
.debug(*args, &block) ⇒ Object
57 58 59 |
# File 'lib/controlist.rb', line 57 def debug(*args, &block) logger.debug *args, &block if @logger_enabled end |
.enable_logger ⇒ Object
61 62 63 |
# File 'lib/controlist.rb', line 61 def enable_logger @logger_enabled = true end |
.has_permission(klass, operation) ⇒ Object
65 66 67 68 |
# File 'lib/controlist.rb', line 65 def (klass, operation) = @permission_manager. && .(klass, operation) end |
.initialize(permission_manager, config = {}) ⇒ Object
example:
Controlist.initialize Controlist::Managers::ThreadBasedManager
attribute_proxy: "_val",
value_object_proxy: "_value_object",
logger: Logger.new(STDOUT)
attribute_proxy and value_object_proxy are to avoid ActiveModel::MissingAttributeError due to select(attributes) according to constrains, suppose attribute_proxy is :_val, value_object_proxy is :_value_object
user = User.find 1
user.id
user._val(:attr_might_not_be_accessed)
user._value_object.attr_might_not_be_accessed
28 29 30 31 32 33 34 |
# File 'lib/controlist.rb', line 28 def initialize(, config={}) @permission_manager = @attribute_proxy = config[:attribute_proxy] || "_val" @value_object_proxy = config[:value_object_proxy] || "_value_object" @logger = config[:logger] || Logger.new(STDOUT) Interceptor.hook end |
.is_activerecord3? ⇒ Boolean
53 54 55 |
# File 'lib/controlist.rb', line 53 def is_activerecord3? ActiveRecord::VERSION::MAJOR == 3 end |
.skip ⇒ Object
Skip Controlist interceptor
Controlist.skip do
relation = User.unscoped
sql = relation.to_sql
assert_equal "SELECT \"users\".* FROM \"users\"", sql.strip
end
45 46 47 48 49 50 51 |
# File 'lib/controlist.rb', line 45 def skip is_skip = @permission_manager.skip? @permission_manager.enable_skip result = yield @permission_manager.disable_skip unless is_skip result end |