Class: Troles::Storage::StringMany
- Inherits:
-
BaseMany
- Object
- Common::Storage
- BaseMany
- Troles::Storage::StringMany
- Defined in:
- lib/troles/storage/string_many.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Common::Storage
Instance Method Summary collapse
-
#clear! ⇒ Object
clears the role of the user in the data store.
-
#display_roles ⇒ Array<Symbol>
display the roles as a list of symbols.
- #ds_field_value? ⇒ Boolean
-
#initialize(role_subject) ⇒ StringMany
constructor
A new instance of StringMany.
-
#set_default_role! ⇒ Object
sets the role to default setting.
-
#set_roles(*roles) ⇒ Object
saves the role for the user in the data store.
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_roles ⇒ Array<Symbol>
display the roles as a list of symbols
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
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
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 |