Module: IAmICan::Subject::RoleQuerying
- Defined in:
- lib/i_am_i_can/subject/role_querying.rb
Instance Method Summary collapse
- #is!(role_name, with_tmp: true) ⇒ Object (also: #is_role!, #has_role!)
-
#is?(role_name, with_tmp: true) ⇒ Boolean
(also: #is_role?, #has_role?)
Role Querying ===.
- #is_every!(*role_names, with_tmp: true) ⇒ Object (also: #is_every_role_in!)
- #is_every?(*role_names, with_tmp: true) ⇒ Boolean (also: #is_every_role_in?)
- #is_in_one_of?(*group_names) ⇒ Boolean (also: #in_one_of?)
-
#is_in_role_group?(name) ⇒ Boolean
(also: #in_role_group?)
Group Querying ===.
- #is_one_of!(*role_names, with_tmp: true) ⇒ Object (also: #is_one_of_roles!)
- #is_one_of?(*role_names, with_tmp: true) ⇒ Boolean (also: #is_one_of_roles?)
- #isnt?(role_name, with_tmp: true) ⇒ Boolean
Instance Method Details
#is!(role_name, with_tmp: true) ⇒ Object Also known as: is_role!, has_role!
22 23 24 25 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 22 def is! role_name, with_tmp: true raise VerificationFailed if isnt? role_name, with_tmp: with_tmp true end |
#is?(role_name, with_tmp: true) ⇒ Boolean Also known as: is_role?, has_role?
Role Querying ===
9 10 11 12 13 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 9 def is? role_name, with_tmp: true role_id = i_am_i_can.role_model.find_by(name: role_name)&.id return false unless role_id get_roles(with_tmp: with_tmp).exists?(id: role_id) end |
#is_every!(*role_names, with_tmp: true) ⇒ Object Also known as: is_every_role_in!
53 54 55 56 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 53 def is_every! *role_names, with_tmp: true raise VerificationFailed unless is_every?(*role_names, with_tmp: true) true end |
#is_every?(*role_names, with_tmp: true) ⇒ Boolean Also known as: is_every_role_in?
45 46 47 48 49 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 45 def is_every? *role_names, with_tmp: true role_ids = i_am_i_can.role_model.where(name: role_names).ids return false if role_ids.size != role_names.size get_roles(with_tmp: with_tmp).where(id: role_ids).size == role_names.size end |
#is_in_one_of?(*group_names) ⇒ Boolean Also known as: in_one_of?
69 70 71 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 69 def is_in_one_of? *group_names group_names.each { |name| return true if is_in_role_group? name } && false end |
#is_in_role_group?(name) ⇒ Boolean Also known as: in_role_group?
Group Querying ===
62 63 64 65 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 62 def is_in_role_group? name group_members = i_am_i_can.role_group_model.find_by!(name: name)._roles.names (get_roles.names & group_members).present? end |
#is_one_of!(*role_names, with_tmp: true) ⇒ Object Also known as: is_one_of_roles!
38 39 40 41 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 38 def is_one_of! *role_names, with_tmp: true raise VerificationFailed unless is_one_of? *role_names, with_tmp: with_tmp true end |
#is_one_of?(*role_names, with_tmp: true) ⇒ Boolean Also known as: is_one_of_roles?
30 31 32 33 34 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 30 def is_one_of? *role_names, with_tmp: true role_ids = i_am_i_can.role_model.where(name: role_names).ids return false if role_ids.blank? get_roles(with_tmp: with_tmp).exists?(id: role_ids) end |
#isnt?(role_name, with_tmp: true) ⇒ Boolean
18 19 20 |
# File 'lib/i_am_i_can/subject/role_querying.rb', line 18 def isnt? role_name, with_tmp: true !is? role_name, with_tmp: with_tmp end |