Module: Troles::Common::Api::Write
- Defined in:
- lib/troles/common/api/write.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#add_role(role_name) ⇒ true, ...
Add a single new role to the roles of the subject.
-
#add_roles(*new_roles) ⇒ true, ...
Adds a set of new roles to the roles of the subject.
-
#clear_roles! ⇒ true, ...
Clears all the roles of the subject.
-
#remove_role(role_name) ⇒ Object
Remove a single role from the roles of the subject.
-
#remove_roles(*the_roles) ⇒ Object
Removes a set of new roles to the roles of the subject (see #add_roles).
-
#set_roles(*roles) ⇒ true, ...
Sets new roles for the subject.
-
#static_role!(role_name) ⇒ Object
Do we need a static_roles! method? I think so!.
Instance Method Details
#add_role(role_name) ⇒ true, ...
Add a single new role to the roles of the subject
22 23 24 25 |
# File 'lib/troles/common/api/write.rb', line 22 def add_role role_name raise ArgumentError, "Take a single role name, was: #{role_name}" if !role_name || !role_name.kind_of_label? add_roles role_name end |
#add_roles(*new_roles) ⇒ true, ...
Adds a set of new roles to the roles of the subject
38 39 40 |
# File 'lib/troles/common/api/write.rb', line 38 def add_roles *new_roles store.set_roles (role_list | new_roles.to_symbols_uniq) # Set Union (joined set) end |
#clear_roles! ⇒ true, ...
Clears all the roles of the subject
59 60 61 |
# File 'lib/troles/common/api/write.rb', line 59 def clear_roles! store.clear! end |
#remove_role(role_name) ⇒ Object
Remove a single role from the roles of the subject
30 31 32 33 |
# File 'lib/troles/common/api/write.rb', line 30 def remove_role role_name raise ArgumentError, "Take a single role name, was: #{role_name}" if !role_name || !role_name.kind_of_label? remove_roles role_name end |
#remove_roles(*the_roles) ⇒ Object
Removes a set of new roles to the roles of the subject (see #add_roles)
44 45 46 |
# File 'lib/troles/common/api/write.rb', line 44 def remove_roles *the_roles store.set_roles (role_list - the_roles.to_symbols_uniq) end |
#set_roles(*roles) ⇒ true, ...
Sets new roles for the subject
51 52 53 54 55 |
# File 'lib/troles/common/api/write.rb', line 51 def set_roles *roles roles_to_set = make_valid_roles(*roles).flat_uniq return false if !roles_to_set || roles_to_set.empty? store.set_roles(roles_to_set) end |
#static_role!(role_name) ⇒ Object
Do we need a static_roles! method? I think so!
9 10 11 12 13 14 15 16 17 |
# File 'lib/troles/common/api/write.rb', line 9 def static_role! role_name raise ArgumentError, "Take a single role name, was: #{role_name}" if !role_name || !role_name.kind_of_label? troles_config.add_valid_roles role_name if set_roles role_name define_method :static_roles? do true end end end |