Module: TroleGroups::Api::Write

Defined in:
lib/trole_groups/api/write.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_rolegroup(rolegroup_name) ⇒ true, ...

Add a single new rolegroup to the rolegroups of the subject

Parameters:

  • rolegroup (Symbol)

    to add

Returns:

  • (true, false, Error)

    true if ok, false if static or invalid, Error on some error

Raises:

  • (ArgumentError)


6
7
8
9
# File 'lib/trole_groups/api/write.rb', line 6

def add_rolegroup rolegroup_name
  raise ArgumentError, "Take a single rolegroup name, was: #{rolegroup_name}" if !rolegroup_name || !rolegroup_name.kind_of_label?
  add_rolegroups rolegroup_name
end

#add_rolegroups(*new_rolegroups) ⇒ true, ...

Adds a set of new rolegroups to the rolegroups of the subject

Parameters:

  • list (Array<Symbol>)

    of rolegroups to add

Returns:

  • (true, false, Error)

    true if ok, false if static or invalid, Error on some error



22
23
24
# File 'lib/trole_groups/api/write.rb', line 22

def add_rolegroups *new_rolegroups      
  group_store.set_rolegroups (rolegroup_list | new_rolegroups.to_symbols_uniq) # Set Union (joined set)
end

#clear_rolegroups!true, ...

Clears all the rolegroups of the subject

Returns:

  • (true, false, Error)

    true if ok, false if rolegroups are static, Error on some error



43
44
45
# File 'lib/trole_groups/api/write.rb', line 43

def clear_rolegroups!
  group_store.clear!
end

#remove_rolegroup(rolegroup_name) ⇒ Object

Remove a single rolegroup from the rolegroups of the subject

Parameters:

  • rolegroup (Symbol)

    to remove

Raises:

  • (ArgumentError)


14
15
16
17
# File 'lib/trole_groups/api/write.rb', line 14

def remove_rolegroup rolegroup_name
  raise ArgumentError, "Take a single rolegroup name, was: #{rolegroup_name}" if !rolegroup_name || !rolegroup_name.kind_of_label?
  remove_rolegroups rolegroup_name
end

#remove_rolegroups(*the_rolegroups) ⇒ Object

Removes a set of new rolegroups to the rolegroups of the subject (see #add_rolegroups)



28
29
30
# File 'lib/trole_groups/api/write.rb', line 28

def remove_rolegroups *the_rolegroups
  group_store.set_rolegroups (rolegroup_list - the_rolegroups.to_symbols_uniq)
end

#set_rolegroups(*rolegroups) ⇒ true, ...

Sets new rolegroups for the subject

Parameters:

  • list (Array<Symbol>)

    of rolegroup names

Returns:

  • (true, false, Error)

    true if set ok, false if any rolegroups were invalid, Error on some error



35
36
37
38
39
# File 'lib/trole_groups/api/write.rb', line 35

def set_rolegroups *rolegroups
  rolegroups_to_set = make_valid_rolegroups(*rolegroups).flat_uniq
  return false if !rolegroups_to_set || rolegroups_to_set.empty?
  group_store.set_rolegroups(rolegroups_to_set) 
end