Class: Troles::Common::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/troles/common/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role_subject) ⇒ Storage

initializes storage with reference to role subject

Parameters:

  • the (Object)

    role subject (fx a User or UserAccount)



12
13
14
# File 'lib/troles/common/storage.rb', line 12

def initialize role_subject
  @role_subject = role_subject
end

Instance Attribute Details

#role_subjectObject (readonly)

Returns the value of attribute role_subject.



8
9
10
# File 'lib/troles/common/storage.rb', line 8

def role_subject
  @role_subject
end

Instance Method Details

#ds_field_nameSymbol

the name of the role field

Returns:

  • (Symbol)

    the name



44
45
46
# File 'lib/troles/common/storage.rb', line 44

def ds_field_name
  role_field
end

#ds_field_valueObject

the current value of the role field

Returns:



50
51
52
# File 'lib/troles/common/storage.rb', line 50

def ds_field_value
  role_subject.send(ds_field_name)
end

#nameSymbol

name/type of storage

Returns:

  • (Symbol)


24
25
26
# File 'lib/troles/common/storage.rb', line 24

def name
  :generic
end

#persist_role_changes!true, ...

Attempts to persist the role field changes

Returns:

  • (true, false, error)

    true if saved, false if no save! method, Error on some error



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/troles/common/storage.rb', line 56

def persist_role_changes!           
  puts "Troles::Common::Storage::BaseMany.persist_role_changes!" if Troles::Common::Config.log_on?
  if !role_subject.respond_to? :save
    puts "could not save since no #save method on subject: #{role_subject}" if Troles::Common::Config.log_on?
    return false 
  else      
    puts "#{role_subject}.save" if Troles::Common::Config.log_on?         
    role_subject.save
    role_subject.publish_change :roles
  end
end

#set_ds_field(value) ⇒ Object

sets the value of the role field (@trole or @troles) and persists the value (in the data store)

Parameters:

  • the (Object)

    value to set on the role field of the role subject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/troles/common/storage.rb', line 30

def set_ds_field value
  return if ds_field_value == value

  if Troles::Common::Config.log_on?
    puts "Troles::Common::Storage.set_ds_field:"
    puts "#{rolegroup_subject}.#{ds_field_name} = #{value}"
  end

  role_subject.send(:"#{ds_field_name}=", value)
  persist_role_changes!
end

#valid_rolesArray<Symbol>

valid roles of the role subjects class (fx account - i.e the account rules!)

Returns:

  • (Array<Symbol>)

    the list of valid roles



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

def valid_roles
  role_subject.class.valid_roles
end