Class: CaTissue::SpecimenEventParameters
- Inherits:
-
Object
- Object
- CaTissue::SpecimenEventParameters
- Defined in:
- lib/catissue/migration/shims.rb,
lib/catissue/migration/migratable.rb,
lib/catissue/domain/specimen_event_parameters.rb
Class Method Summary collapse
-
.create_parameters(type, scg_or_specimen, params = Hash::EMPTY_HASH) ⇒ Object
Creates a SpecimenEventParameters of the specified subclass type.
Instance Method Summary collapse
-
#collection_protocol ⇒ CaTissue::CollectionProtocol
The SCG protocol.
-
#migrate_specimen_collection_group(scg, row) ⇒ Object
Returns nil by default, since only CollectibleEventParameters have a SCG owner.
-
#subject ⇒ CaTissue::Collectible
Specimen or SCG to which this event is attached.
- #subject=(scg_or_specimen) ⇒ Object
Class Method Details
.create_parameters(type, scg_or_specimen, params = Hash::EMPTY_HASH) ⇒ Object
Creates a SpecimenEventParameters of the specified subclass type. The type is a SpecimenEventParameters subclass name without the EventParameters
suffix, e.g. Collection
. Lower-case, underscore symbols are supported and preferred, e.g. the :collection type creates a CollectionEventParameters.
The required scg_or_specimen argument is either a SpecimenCollectionGroup or a Specimen.
The optional params argument are attribute => value associations, e.g.
SpecimenEventParameters.create_parameters(:collection, scg, :user => collector, :timestamp => DateTime.now)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/catissue/domain/specimen_event_parameters.rb', line 29 def self.create_parameters(type, scg_or_specimen, params=Hash::EMPTY_HASH) # make the class name by joining the camel-cased type prefix to the subclass suffix. # classify converts a lower_case, underscore type to a valid class name, # e.g. +:check_in_check_out+ becomes +CheckInCheckOut+. class_name = type.to_s.classify + SUBCLASS_SUFFIX begin klass = CaTissue.const_get(class_name.to_sym) rescue raise ArgumentError.new("Unsupported event parameters type: #{type}; #{class_name} must be a subtype of #{self}") end ep = klass.new(params) case scg_or_specimen when CaTissue::SpecimenCollectionGroup then ep.specimen_collection_group = scg_or_specimen when CaTissue::Specimen then ep.specimen = scg_or_specimen when nil then raise ArgumentError.new("Missing SpecimenEventParameters SCG or Specimen owner argument") else raise ArgumentError.new("Unsupported SpecimenEventParameters factory argument - expected SpecimenCollectionGroup or Specimen, found #{scg_or_specimen.class}") end ep end |
Instance Method Details
#collection_protocol ⇒ CaTissue::CollectionProtocol
Returns the SCG protocol.
65 66 67 |
# File 'lib/catissue/domain/specimen_event_parameters.rb', line 65 def collection_protocol specimen_collection_group.collection_protocol if specimen_collection_group end |
#migrate_specimen_collection_group(scg, row) ⇒ Object
Returns nil by default, since only CollectibleEventParameters have a SCG owner. CollectibleEventParameters#migrate_specimen_collection_group overrides this method.
86 87 88 |
# File 'lib/catissue/migration/shims.rb', line 86 def migrate_specimen_collection_group(scg, row) nil end |
#subject ⇒ CaTissue::Collectible
Returns specimen or SCG to which this event is attached.
51 52 53 |
# File 'lib/catissue/domain/specimen_event_parameters.rb', line 51 def subject specimen.nil? ? specimen_collection_group : specimen end |
#subject=(scg_or_specimen) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/catissue/domain/specimen_event_parameters.rb', line 56 def subject=(scg_or_specimen) spc_subject = scg_or_specimen if Specimen === scg_or_specimen scg_subject = scg_or_specimen if SpecimenCollectionGroup === scg_or_specimen specimen = spc_subject specimen_collection_group = scg_subject scg_or_specimen end |