Class: Troles::Storage::StringMany

Inherits:
BaseMany show all
Defined in:
lib/troles/storage/string_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) ⇒ StringMany

Returns a new instance of StringMany.



9
10
11
# File 'lib/troles/storage/string_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



32
33
34
# File 'lib/troles/storage/string_many.rb', line 32

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
# File 'lib/troles/storage/string_many.rb', line 15

def display_roles
  return [] if !ds_field_value?
  ds_field_value.split(',').map{|r| r.strip }.map(&:to_sym)
end

#ds_field_value?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/troles/storage/string_many.rb', line 20

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

#set_default_role!Object

sets the role to default setting



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

def set_default_role!
  clear!
end

#set_roles(*roles) ⇒ Object

saves the role for the user in the data store

Parameters:

  • roles (Array<Symbol>)

    list



26
27
28
29
# File 'lib/troles/storage/string_many.rb', line 26

def set_roles *roles
  value = roles.flatten.map(&:to_s).join(',')
  set_ds_field value
end