module Troles::Common::Api::Write

Public Instance Methods

add_role(role_name) click to toggle source

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
add_roles(*new_roles) click to toggle source

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
clear_roles!() click to toggle source

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_role(role_name) click to toggle source

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
remove_roles(*the_roles) click to toggle source

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
set_roles(*roles) click to toggle source

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
static_role!(role_name) click to toggle source

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