Class: RoleCore::Mapper
- Inherits:
-
Object
- Object
- RoleCore::Mapper
- Defined in:
- lib/role_core/mapper.rb
Instance Method Summary collapse
- #group(name, **constraints, &block) ⇒ Object
-
#initialize(set, **constraints) ⇒ Mapper
constructor
:nodoc:.
- #permission(name, default: false, **options, &block) ⇒ Object
Constructor Details
#initialize(set, **constraints) ⇒ Mapper
:nodoc:
5 6 7 8 9 |
# File 'lib/role_core/mapper.rb', line 5 def initialize(set, **constraints) #:nodoc: @constraints = constraints @constraints[:_namespace] ||= [] @set = set end |
Instance Method Details
#group(name, **constraints, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/role_core/mapper.rb', line 16 def group(name, **constraints, &block) raise ArgumentError, "`name` can't be blank" if name.blank? raise ArgumentError, "must provide a block" unless block_given? constraints[:_namespace] ||= @constraints[:_namespace].dup constraints[:_namespace] << name = if @set.nested_classes.has_key?(name) @set.nested_classes[name] else klass_name = constraints[:_namespace].map { |n| n.to_s.classify }.join("::") klass = PermissionSet.derive klass_name @set.(name, anonymous_class: klass) klass end .draw(@constraints.merge(constraints), &block) self end |
#permission(name, default: false, **options, &block) ⇒ Object
11 12 13 14 |
# File 'lib/role_core/mapper.rb', line 11 def (name, default: false, **, &block) @set. name, default, @constraints.merge(), &block self end |