Class: Trole::Storage::StringOne
- Inherits:
-
BaseOne
- Object
- Troles::Common::Storage
- BaseOne
- Trole::Storage::StringOne
- Defined in:
- lib/trole/storage/string_one.rb
Instance Attribute Summary
Attributes inherited from Troles::Common::Storage
Instance Method Summary collapse
-
#clear! ⇒ Object
Clears the role state of the role subject.
-
#display_roles ⇒ Array<Symbol>
display the role as a list of one symbol see Troles::Marshaller::Bitmask display the role as a list of one symbol.
-
#ds_field_value? ⇒ Boolean
is it set?.
-
#initialize(role_subject) ⇒ StringOne
constructor
constructor.
-
#set_role(role) ⇒ Object
saves the role of the role subject in the data store.
-
#set_roles(*roles) ⇒ Object
saves the roles for the role subject in the data store see Troles::Marshaller::Bitmask.
Methods inherited from BaseOne
#find_role, #role_model, #role_to_embed, #set_default_role!
Methods inherited from Troles::Common::Storage
#ds_field_name, #ds_field_value, #name, #persist_role_changes!, #set_ds_field, #valid_roles
Constructor Details
#initialize(role_subject) ⇒ StringOne
constructor
11 12 13 |
# File 'lib/trole/storage/string_one.rb', line 11 def initialize role_subject super end |
Instance Method Details
#clear! ⇒ Object
Clears the role state of the role subject
46 47 48 |
# File 'lib/trole/storage/string_one.rb', line 46 def clear! set_ds_field "" end |
#display_roles ⇒ Array<Symbol>
display the role as a list of one symbol see Troles::Marshaller::Bitmask
display the role as a list of one symbol
20 21 22 23 |
# File 'lib/trole/storage/string_one.rb', line 20 def display_roles return [] if ds_field_value? [ds_field_value.to_sym] end |
#ds_field_value? ⇒ Boolean
is it set?
26 27 28 |
# File 'lib/trole/storage/string_one.rb', line 26 def ds_field_value? ds_field_value && !!ds_field_value.empty? end |
#set_role(role) ⇒ Object
saves the role of the role subject in the data store
41 42 43 |
# File 'lib/trole/storage/string_one.rb', line 41 def set_role role set_ds_field role.to_s end |
#set_roles(*roles) ⇒ Object
saves the roles for the role subject in the data store see Troles::Marshaller::Bitmask
33 34 35 36 37 |
# File 'lib/trole/storage/string_one.rb', line 33 def set_roles *roles roles = roles.flatten raise ArgumentError, "For a single role strategy you can only set one role, was: #{roles.flatten}" if roles.empty? || (roles.size > 1) set_role roles.first end |