Class: Bali::Rules
- Inherits:
-
Object
- Object
- Bali::Rules
- Extended by:
- Statics::Authorizer, Statics::ScopeRuler, Forwardable
- Defined in:
- lib/bali/rules.rb
Class Attribute Summary collapse
-
.current_role ⇒ Object
writeonly
Sets the attribute current_role.
-
.ruler ⇒ Object
readonly
Returns the value of attribute ruler.
Class Method Summary collapse
- .for(record_class) ⇒ Object
- .inheritable_role ⇒ Object
- .model_class ⇒ Object
- .role(*role_names, &block) ⇒ Object
Class Attribute Details
.current_role=(value) ⇒ Object (writeonly)
Sets the attribute current_role
10 11 12 |
# File 'lib/bali/rules.rb', line 10 def current_role=(value) @current_role = value end |
.ruler ⇒ Object (readonly)
Returns the value of attribute ruler.
11 12 13 |
# File 'lib/bali/rules.rb', line 11 def ruler @ruler end |
Class Method Details
.for(record_class) ⇒ Object
20 21 22 23 |
# File 'lib/bali/rules.rb', line 20 def self.for(record_class) rule_maker_cls_str = "#{record_class}#{Bali.config.suffix}" rule_maker_cls_str.safe_constantize end |
.inheritable_role ⇒ Object
48 49 50 |
# File 'lib/bali/rules.rb', line 48 def self.inheritable_role ruler[nil] end |
.model_class ⇒ Object
25 26 27 28 29 30 |
# File 'lib/bali/rules.rb', line 25 def self.model_class class_name = to_s suffix = Bali.config.suffix rule_class_maker_str = class_name[0...class_name.length - suffix.length] rule_class_maker_str.constantize end |
.role(*role_names, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bali/rules.rb', line 32 def self.role(*role_names, &block) role_names.each do |role_name| if Bali::Role::IDENTIFIER_CLASSES.include?(role_name.class) role = ruler.find_or_create_role role_name role.instance_eval(&block) else raise Bali::DslError, "Cannot define role using #{param.class}. " + "Please use either a Symbol, a String or nil" end end end |