Class: Trole::Storage::BitOne
- Inherits:
-
BaseOne
- Object
- Troles::Common::Storage
- BaseOne
- Trole::Storage::BitOne
- Defined in:
- lib/trole/storage/bit_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.
-
#initialize(role_subject) ⇒ BitOne
constructor
constructor.
-
#set_role(role) ⇒ Object
saves the role for the role subject in the data store.
Methods inherited from BaseOne
#find_role, #role_model, #role_to_embed, #set_default_role!, #set_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(role_subject) ⇒ BitOne
constructor
13 14 15 |
# File 'lib/trole/storage/bit_one.rb', line 13 def initialize role_subject super end |
Instance Method Details
#clear! ⇒ Object
Clears the role state of the role subject
33 34 35 |
# File 'lib/trole/storage/bit_one.rb', line 33 def clear! set_ds_field false end |
#display_roles ⇒ Array<Symbol>
display the role as a list of one symbol see Troles::Marshaller::Bitmask
20 21 22 23 |
# File 'lib/trole/storage/bit_one.rb', line 20 def display_roles raise "BitOne requires exactly two valid roles, was: #{valid_roles}" if !(valid_roles.size == 2) [bitmask.read].flatten end |
#set_role(role) ⇒ Object
saves the role for the role subject in the data store
27 28 29 30 |
# File 'lib/trole/storage/bit_one.rb', line 27 def set_role role num = bitmask.write role set_ds_field(num == 1 ? false : true) # boolean field in Data store end |