Class: Lims::Core::Persistence::UuidResource::UuidResourcePersistor

Inherits:
Persistor
  • Object
show all
Defined in:
lib/lims-core/persistence/uuid_resource_persistor.rb

Constant Summary collapse

Model =
UuidResource

Instance Method Summary collapse

Methods inherited from Persistor

#[], #bind_state_to_id, #bind_state_to_resource, #bulk_delete, #bulk_delete_raw, #bulk_insert, #bulk_retrieve, #bulk_update, #children, #count, #deletable_children, #deletable_parents, #dirty_key_for, #for_each_in_slice, #id_for, #ids_for, inherited, #initialize, #invalid_resource?, #load_children, #model, #new_from_attributes, #new_object, #object_for, #on_object_load, #parents, #parents_for_attributes, #purge_invalid_object, register_model, #retrieve, #slice, #state_for, #state_for?, #state_for_id

Constructor Details

This class inherits a constructor from Lims::Core::Persistence::Persistor

Instance Method Details

#filter_attributes_on_load(attributes) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/lims-core/persistence/uuid_resource_persistor.rb', line 29

def filter_attributes_on_load(attributes)
  attributes.mash do |k,v|
    case k
    when :model_class then [ k, @session.class_for(v) ]
    when :uuid then [ k, @session.unpack_uuid(v) ]
    when :key then [:state, @session.persistor_for(attributes[:model_class]).state_for_id(attributes[:key])]
    else [k, v]
    end
  end
end

#filter_attributes_on_save(attributes) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lims-core/persistence/uuid_resource_persistor.rb', line 17

def filter_attributes_on_save(attributes)
  attributes.mash do |k,v|
    case k
    when :model_class then   [ k, @session.model_name_for(v) ]
    when :uuid then [ k, @session.pack_uuid(v) ]
    when :state
      [:key, v && v.id]
    else [k, v]
    end
  end
end

#parents_for(resource) ⇒ Object



13
14
15
# File 'lib/lims-core/persistence/uuid_resource_persistor.rb', line 13

def parents_for(resource)
  resource.state && resource.state.resource ? [resource.state] : []
end