Class: Troles::Storage::RefMany
- Inherits:
-
BaseMany
- Object
- Common::Storage
- BaseMany
- Troles::Storage::RefMany
- Defined in:
- lib/troles/storage/ref_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
is it set?.
-
#initialize(role_subject) ⇒ RefMany
constructor
A new instance of RefMany.
-
#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) ⇒ 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_roles ⇒ Array<Symbol>
display the roles as a list of symbols
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?
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 |