Class: Trole::Storage::BitOne

Inherits:
BaseOne show all
Defined in:
lib/trole/storage/bit_one.rb

Instance Attribute Summary

Attributes inherited from Troles::Common::Storage

#role_subject

Instance Method Summary collapse

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

Parameters:

  • the (Symbol)

    role subject



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_rolesArray<Symbol>

display the role as a list of one symbol see Troles::Marshaller::Bitmask

Returns:

  • (Array<Symbol>)

    roles list



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

Parameters:

  • role (Symbol)

    name



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