Class: Troles::Storage::BitMany

Inherits:
BaseMany show all
Defined in:
lib/troles/storage/bit_many.rb

Instance Attribute Summary

Attributes inherited from Common::Storage

#role_subject

Instance Method Summary collapse

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) ⇒ BitMany

constructor

Parameters:

  • the (Object)

    role subject



11
12
13
# File 'lib/troles/storage/bit_many.rb', line 11

def initialize role_subject
  super
end

Instance Method Details

#clear!Object

Clears the role state of the role subject



37
38
39
# File 'lib/troles/storage/bit_many.rb', line 37

def clear!
  set_ds_field 0
end

#display_rolesArray<Symbol>

display the roles as a list of symbols see Troles::Marshaller::Bitmask

Returns:

  • (Array<Symbol>)

    roles list



18
19
20
21
# File 'lib/troles/storage/bit_many.rb', line 18

def display_roles
  return [] if !ds_field_value?
  bitmask.read
end

#ds_field_value?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/troles/storage/bit_many.rb', line 23

def ds_field_value?
  ds_field_value > 0
end

#set_default_role!Object

Sets role to default state



42
43
44
# File 'lib/troles/storage/bit_many.rb', line 42

def set_default_role!
  clear!
end

#set_roles(*roles) ⇒ Object

saves the roles for the role subject in the data store see Troles::Marshaller::Bitmask

Parameters:

  • roles (Array<Symbol>)

    list



30
31
32
33
34
# File 'lib/troles/storage/bit_many.rb', line 30

def set_roles *roles
  roles = roles.to_symbols_uniq
  return clear! if roles.empty?
  set_ds_field bitmask.write(roles.to_symbols)
end