Class: Troles::Storage::RefMany

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

Direct Known Subclasses

JoinRefMany

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) ⇒ RefMany

Returns a new instance of RefMany.



9
10
11
# File 'lib/troles/storage/ref_many.rb', line 9

def initialize role_subject
  super
end

Instance Method Details

#clear!Object

clears the role of the user in the data store



34
35
36
# File 'lib/troles/storage/ref_many.rb', line 34

def clear!
  set_ds_field []
end

#display_rolesArray<Symbol>

display the roles as a list of symbols

Returns:

  • (Array<Symbol>)

    roles list



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

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

#ds_field_value?Boolean

is it set?

Returns:

  • (Boolean)


23
24
25
# File 'lib/troles/storage/ref_many.rb', line 23

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

#set_default_role!Object

sets the role to default setting



39
40
41
# File 'lib/troles/storage/ref_many.rb', line 39

def set_default_role!
  clear!
end

#set_roles(*roles) ⇒ Object

saves the role for the user in the data store



28
29
30
31
# File 'lib/troles/storage/ref_many.rb', line 28

def set_roles *roles
  # finds and sets references to existing Role instances from symbols
  set_ds_field find_roles(*roles)
end