Class: TroleGroups::Storage::EmbedMany
- Inherits:
-
BaseMany
- Object
- Troles::Common::Storage
- BaseMany
- TroleGroups::Storage::EmbedMany
- Defined in:
- lib/trole_groups/storage/embed_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 rolegroups as a list of symbols.
-
#ds_field_value? ⇒ Boolean
is it set?.
-
#initialize(rolegroupsubject) ⇒ EmbedMany
constructor
constructor.
- #rolegroups_to_embed(*rolegroups) ⇒ Object
-
#set_default_role! ⇒ Object
sets the role to its default state.
-
#set_rolegroups(*rolegroups) ⇒ Object
saves the rolegroups for the role subject 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(rolegroupsubject) ⇒ EmbedMany
constructor
12 13 14 |
# File 'lib/trole_groups/storage/embed_many.rb', line 12 def initialize rolegroupsubject super end |
Instance Method Details
#clear! ⇒ Object
clears the role of the user in the data store
43 44 45 |
# File 'lib/trole_groups/storage/embed_many.rb', line 43 def clear! set_ds_field [] end |
#display_rolegroups ⇒ Array<Symbol>
display the rolegroups as a list of symbols
25 26 27 28 |
# File 'lib/trole_groups/storage/embed_many.rb', line 25 def display_rolegroups return [] if !ds_field_value? ds_field_value.map{|rolegroup| rolegroup.name.to_sym } end |
#ds_field_value? ⇒ Boolean
is it set?
31 32 33 |
# File 'lib/trole_groups/storage/embed_many.rb', line 31 def ds_field_value? ds_field_value && !ds_field_value.empty? end |
#rolegroups_to_embed(*rolegroups) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/trole_groups/storage/embed_many.rb', line 16 def *rolegroups rolegroups.flatten.inject([]) do |res, role| res << create_role(role) res end end |
#set_default_role! ⇒ Object
sets the role to its default state
48 49 50 |
# File 'lib/trole_groups/storage/embed_many.rb', line 48 def set_default_role! clear! end |
#set_rolegroups(*rolegroups) ⇒ Object
saves the rolegroups for the role subject in the data store
37 38 39 40 |
# File 'lib/trole_groups/storage/embed_many.rb', line 37 def set_rolegroups *rolegroups # creates and embeds new Role instances from symbols set_ds_field (*rolegroups) end |