Class: TroleGroups::Storage::BaseMany

Inherits:
Troles::Common::Storage show all
Defined in:
lib/trole_groups/storage.rb,
lib/trole_groups/storage/base_many.rb

Overview

autoload :StringMany, ‘trole_groups/storage/string_many’

Direct Known Subclasses

EmbedMany, RefMany

Instance Attribute Summary collapse

Attributes inherited from Troles::Common::Storage

#role_subject

Instance Method Summary collapse

Constructor Details

#initialize(rolegroup_subject) ⇒ BaseMany

initializes storage with reference to role subject

Parameters:

  • the (Object)

    role subject (fx a User or UserAccount)



12
13
14
# File 'lib/trole_groups/storage/base_many.rb', line 12

def initialize rolegroup_subject
  @rolegroup_subject = rolegroup_subject
end

Instance Attribute Details

#rolegroup_subjectObject (readonly)

Returns the value of attribute rolegroup_subject.



8
9
10
# File 'lib/trole_groups/storage/base_many.rb', line 8

def rolegroup_subject
  @rolegroup_subject
end

Instance Method Details

#ds_field_nameSymbol

the name of the role field

Returns:

  • (Symbol)

    the name



42
43
44
# File 'lib/trole_groups/storage/base_many.rb', line 42

def ds_field_name
  rolegroup_field
end

#ds_field_valueObject

the current value of the role field

Returns:



48
49
50
51
# File 'lib/trole_groups/storage/base_many.rb', line 48

def ds_field_value
  # puts "#{rolegroup_subject}.#{ds_field_name}" if Troles::Common::Config.log_on?
  rolegroup_subject.send(ds_field_name)
end

#nameSymbol

name/type of storage

Returns:

  • (Symbol)


24
25
26
# File 'lib/trole_groups/storage/base_many.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



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/trole_groups/storage/base_many.rb', line 55

def persist_role_changes!
  puts "TroleGroups::Storage::BaseMany.persist_role_changes!" if Troles::Common::Config.log_on?
  if !rolegroup_subject.respond_to? :save
    puts "could not save since no #save method on subject: #{rolegroup_subject}" if Troles::Common::Config.log_on?
    return false 
  else      
    puts "#{rolegroup_subject}.save" if Troles::Common::Config.log_on?         
    rolegroup_subject.save
    rolegroup_subject.publish_change :role_groups
  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
# File 'lib/trole_groups/storage/base_many.rb', line 30

def set_ds_field value
  return if ds_field_value == value 
  if Troles::Common::Config.log_on?
    puts "TroleGroups::Storage::BaseMany.set_ds_field:"
    puts "#{rolegroup_subject}.#{ds_field_name} = #{value}"
  end
  rolegroup_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/trole_groups/storage/base_many.rb', line 18

def valid_roles
  rolegroup_subject.class.valid_roles
end