Class: Trole::Storage::StringOne

Inherits:
BaseOne show all
Defined in:
lib/trole/storage/string_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!

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

Parameters:

  • the (Symbol)

    role subject



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

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

display the role as a list of one symbol

Returns:

  • (Array<Symbol>)

    roles list

  • (Array<Symbol>)

    roles list



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?

Returns:

  • (Boolean)


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

Parameters:

  • the (Symbol)

    role name



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

Parameters:

  • roles (Array<Symbol>)

    list

Raises:

  • (ArgumentError)


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