Class: TroleGroups::Storage::EmbedMany

Inherits:
BaseMany show all
Defined in:
lib/trole_groups/storage/embed_many.rb

Instance Attribute Summary

Attributes inherited from BaseMany

#rolegroup_subject

Attributes inherited from Troles::Common::Storage

#role_subject

Instance Method Summary collapse

Methods inherited from BaseMany

#ds_field_name, #ds_field_value, #name, #persist_role_changes!, #set_ds_field, #valid_roles

Methods inherited from Troles::Common::Storage

#ds_field_name, #ds_field_value, #name, #persist_role_changes!, #set_ds_field, #valid_roles

Constructor Details

#initialize(rolegroupsubject) ⇒ EmbedMany

constructor

Parameters:

  • the (Object)

    role subject



12
13
14
# File 'lib/trole_groups/storage/embed_many.rb', line 12

def initialize rolegroupsubject
  super
end

Instance Method Details

#clear!Object

clears the role of the user in the data store



43
44
45
# File 'lib/trole_groups/storage/embed_many.rb', line 43

def clear!
  set_ds_field []
end

#display_rolegroupsArray<Symbol>

display the rolegroups as a list of symbols

Returns:

  • (Array<Symbol>)

    rolegroups list



25
26
27
28
# File 'lib/trole_groups/storage/embed_many.rb', line 25

def display_rolegroups
  return [] if !ds_field_value?
  ds_field_value.map{|rolegroup| rolegroup.name.to_sym }
end

#ds_field_value?Boolean

is it set?

Returns:

  • (Boolean)


31
32
33
# File 'lib/trole_groups/storage/embed_many.rb', line 31

def ds_field_value?
  ds_field_value && !ds_field_value.empty?
end

#rolegroups_to_embed(*rolegroups) ⇒ Object



16
17
18
19
20
21
# File 'lib/trole_groups/storage/embed_many.rb', line 16

def rolegroups_to_embed *rolegroups
  rolegroups.flatten.inject([]) do |res, role| 
    res << create_role(role)
    res
  end
end

#set_default_role!Object

sets the role to its default state



48
49
50
# File 'lib/trole_groups/storage/embed_many.rb', line 48

def set_default_role!
  clear!
end

#set_rolegroups(*rolegroups) ⇒ Object

saves the rolegroups for the role subject in the data store

Parameters:

  • rolegroups (Array<Symbol>)

    list



37
38
39
40
# File 'lib/trole_groups/storage/embed_many.rb', line 37

def set_rolegroups *rolegroups
  # creates and embeds new Role instances from symbols
  set_ds_field rolegroups_to_embed(*rolegroups)
end