Class: TroleGroups::Storage::RefMany
- Inherits:
-
BaseMany
- Object
- Troles::Common::Storage
- BaseMany
- TroleGroups::Storage::RefMany
- Defined in:
- lib/trole_groups/storage/ref_many.rb
Instance Attribute Summary
Attributes inherited from BaseMany
Attributes inherited from Troles::Common::Storage
Instance Method Summary collapse
-
#clear! ⇒ Object
clears the role of the user in the data store.
-
#display_rolegroups ⇒ Array<Symbol>
display the roles as a list of symbols.
- #display_roles ⇒ Object
- #display_roles_for(*names) ⇒ Object
-
#ds_field_value? ⇒ Boolean
is it set?.
-
#initialize(rolegroup_subject) ⇒ RefMany
constructor
A new instance of RefMany.
-
#set_default_role! ⇒ Object
sets the role to default setting.
-
#set_rolegroups(*rolegroups) ⇒ Object
saves the role for the user in the data store.
Methods inherited from BaseMany
#ds_field_name, #ds_field_value, #name, #persist_role_changes!, #set_ds_field, #valid_roles
Methods inherited from Troles::Common::Storage
#ds_field_name, #ds_field_value, #name, #persist_role_changes!, #set_ds_field, #valid_roles
Constructor Details
#initialize(rolegroup_subject) ⇒ RefMany
Returns a new instance of RefMany.
3 4 5 |
# File 'lib/trole_groups/storage/ref_many.rb', line 3 def initialize rolegroup_subject super end |
Instance Method Details
#clear! ⇒ Object
clears the role of the user in the data store
38 39 40 |
# File 'lib/trole_groups/storage/ref_many.rb', line 38 def clear! set_ds_field [] end |
#display_rolegroups ⇒ Array<Symbol>
display the roles as a list of symbols
18 19 20 21 22 23 |
# File 'lib/trole_groups/storage/ref_many.rb', line 18 def display_rolegroups return [] if !ds_field_value? ds_field_value.flatten.map do |rolegroup| rolegroup.name.to_sym end end |
#display_roles ⇒ Object
7 8 9 |
# File 'lib/trole_groups/storage/ref_many.rb', line 7 def display_roles display_roles_for rolegroup_list end |
#display_roles_for(*names) ⇒ Object
11 12 13 14 |
# File 'lib/trole_groups/storage/ref_many.rb', line 11 def display_roles_for *names groups = find_rolegroups names.to_symbols_uniq groups.inject([]) {|res, group| res << group.roles }.flat_uniq end |
#ds_field_value? ⇒ Boolean
is it set?
26 27 28 |
# File 'lib/trole_groups/storage/ref_many.rb', line 26 def ds_field_value? ds_field_value && !ds_field_value.empty? end |
#set_default_role! ⇒ Object
sets the role to default setting
43 44 45 |
# File 'lib/trole_groups/storage/ref_many.rb', line 43 def set_default_role! clear! end |
#set_rolegroups(*rolegroups) ⇒ Object
saves the role for the user in the data store
31 32 33 34 35 |
# File 'lib/trole_groups/storage/ref_many.rb', line 31 def set_rolegroups *rolegroups # finds and sets references to existing Role instances from symbols found = find_rolegroups(*rolegroups) set_ds_field found end |