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