Module: IAmICan::Permission::Definition

Defined in:
lib/i_am_i_can/permission/definition.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(kls) ⇒ Object



20
21
22
# File 'lib/i_am_i_can/permission/definition.rb', line 20

def self.extended(kls)
  kls.delegate :deconstruct_obj, to: kls
end

Instance Method Details

#deconstruct_obj(obj) ⇒ Object



16
17
18
# File 'lib/i_am_i_can/permission/definition.rb', line 16

def deconstruct_obj(obj)
  i_am_i_can.permission_model.deconstruct_obj(obj)
end

#have_permission(*actions, obj: nil, remarks: nil) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/i_am_i_can/permission/definition.rb', line 6

def have_permission *actions, obj: nil, remarks: nil
  return unless actions.tap(&:flatten!).first.class.in?([ Symbol, String ])
  objs = obj ? Array(obj) : [nil]
  permissions = actions.product(objs).map { |(p, o)| { action: p, **deconstruct_obj(o), remarks: remarks } }
  definition = _create_permissions(permissions)
  ResultOf.permissions definition, i_am_i_can, given: permissions.map { |pms| pms.values.compact.join('_').to_sym }
end