module Troles::Common::Api::Write
Public Instance Methods
Add a single new role to the roles of the subject @param [Symbol] role to add @return (see add_roles
)
# 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
Adds a set of new roles to the roles of the subject @param [Array<Symbol>] list of roles to add @return [true, false, Error] true if ok, false if static or invalid, Error on some error
# 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
Clears all the roles of the subject @return [true, false, Error] true if ok, false if roles are static, Error on some error
# File lib/troles/common/api/write.rb, line 59 def clear_roles! store.clear! end
Remove a single role from the roles of the subject @param [Symbol] role to remove @return (see remove_roles
)
# 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
Removes a set of new roles to the roles of the subject (see add_roles
)
# 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
Sets new roles for the subject @param [Array<Symbol>] list of role names @return [true, false, Error] true if set ok, false if any roles were invalid, Error on some error
# 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
Do we need a static_roles! method? I think so!
# 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