Class: Troles::Storage::EmbedMany

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

Instance Attribute Summary

Attributes inherited from Common::Storage

#role_subject

Instance Method Summary collapse

Methods inherited from Common::Storage

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

Constructor Details

#initialize(role_subject) ⇒ EmbedMany

constructor

Parameters:

  • the (Object)

    role subject



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

def initialize role_subject
  super
end

Instance Method Details

#clear!Object

clears the role of the user in the data store



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

def clear!
  set_ds_field []
end

#display_rolesArray<Symbol>

display the roles as a list of symbols

Returns:

  • (Array<Symbol>)

    roles list



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

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

#ds_field_value?Boolean

is it set?

Returns:

  • (Boolean)


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

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

#roles_to_embed(*roles) ⇒ Object



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

def roles_to_embed *roles
  roles.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/troles/storage/embed_many.rb', line 48

def set_default_role!
  clear!
end

#set_roles(*roles) ⇒ Object

saves the roles for the role subject in the data store

Parameters:

  • roles (Array<Symbol>)

    list



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

def set_roles *roles
  # creates and embeds new Role instances from symbols
  set_ds_field roles_to_embed(*roles)
end