module IAmICan::Role::Assignment

Public Instance Methods

_roles_assignment(action = :assign, roles, save, exp: nil) click to toggle source
# File lib/i_am_i_can/role/assignment.rb, line 39
def _roles_assignment(action = :assign, roles, save, exp: nil)
  instances, names = Role.extract(roles.flatten, i_am_i_can)
  if save
    assignment = _stored_roles_exec(action, instances, name: names)
    _set_roles_expire(exp, assignment.map(&:id)) if exp
  else
    assignment = _temporary_roles_exec(action, instances, name: names)
  end

  ResultOf.role assignment, i_am_i_can, given: [instances, names]
end
_set_roles_expire(exp, ids) click to toggle source
# File lib/i_am_i_can/role/assignment.rb, line 51
def _set_roles_expire(exp, ids)
  send("assoc_with_#{__roles}")
      .where("#{i_am_i_can.role_class.underscore}_id" => ids)
      .update_all(expire_at: exp)
end
aname(*roles, which_can: [ ], obj: nil, _d: i_am_i_can.auto_definition, auto_definition: _d || which_can.present?, expires_in: nil, expires_at: (expires_in.after if expires_in), save: true)
Alias for: becomes_a
becomes_a(*roles, which_can: [ ], obj: nil, _d: i_am_i_can.auto_definition, auto_definition: _d || which_can.present?, expires_in: nil, expires_at: (expires_in.after if expires_in), save: true) click to toggle source
# File lib/i_am_i_can/role/assignment.rb, line 6
def becomes_a *roles, which_can: [ ], obj: nil,
              _d: i_am_i_can.auto_definition, auto_definition: _d || which_can.present?,
              expires_in: nil, expires_at: (expires_in.after if expires_in), save: true
  self.class.have_roles *roles, which_can: which_can, obj: obj if auto_definition
  run_callbacks(save ? :role_assign : :role_none) do
    _roles_assignment(roles, save, exp: expires_at)
  end
end
Also aliased as: aname
falls_from(*roles, saved: true) click to toggle source
# File lib/i_am_i_can/role/assignment.rb, line 19
def falls_from *roles, saved: true
  run_callbacks(saved ? :cancel_role_assign : :role_none) do
    _roles_assignment(:cancel, roles, saved)
  end
end
Also aliased as: aname
is_a_temporary(*roles, **options) click to toggle source
# File lib/i_am_i_can/role/assignment.rb, line 15
def is_a_temporary *roles, **options
  becomes_a *roles, save: false, **options
end
is_not_a_temporary(*roles) click to toggle source
# File lib/i_am_i_can/role/assignment.rb, line 25
def is_not_a_temporary *roles
  falls_from *roles, saved: false
end
is_only_a(*roles) click to toggle source
# File lib/i_am_i_can/role/assignment.rb, line 29
def is_only_a *roles
  run_callbacks(:role_update) do
    _roles_assignment(:replace, roles, true)
  end
end
Also aliased as: aname