Class: RbacCore::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rbac_core/mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(set, **constraints) ⇒ Mapper

:nodoc:



5
6
7
8
# File 'lib/rbac_core/mapper.rb', line 5

def initialize(set, **constraints) #:nodoc:
  @constraints = constraints
  @set = set
end

Instance Method Details

#group(name, **constraints, &block) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rbac_core/mapper.rb', line 15

def group(name, **constraints, &block)
  raise ArgumentError, "`name` can't be blank" if name.blank?
  raise ArgumentError, "must provide a block" unless block_given?

  sub_permission_set_class =
    if @set.nested_classes.has_key?(name)
      @set.nested_classes[name]
    else
      klass = PermissionSet.derive "#{name.to_s.classify}"
      @set.embeds_one(name, anonymous_class: klass)

      klass
    end

  sub_permission_set_class.draw(@constraints.merge(constraints), &block)

  self
end

#permission(name, default: false, **options, &block) ⇒ Object



10
11
12
13
# File 'lib/rbac_core/mapper.rb', line 10

def permission(name, default: false, **options, &block)
  @set.register_permission name, default, @constraints.merge(options), &block
  self
end