Class: OpenEHR::RM::Factory
- Inherits:
-
Object
- Object
- OpenEHR::RM::Factory
- Defined in:
- lib/openehr/rm/factory.rb
Direct Known Subclasses
Constant Summary collapse
- NON_POLYMORPHIC_TYPE_FOR_KEY =
Attribute keys whose openEHR RM type is always exactly one concrete class (never actually polymorphic), so a real-world canonical-JSON serializer may legally omit _type for them - e.g. openehr-rails's own CanonicalSerializer does. Consulted only as a fallback when _type is absent; see convert_hash below.
Deliberately does NOT include attributes whose declared type is abstract (e.g. LOCATABLE.uid : UID_BASED_ID, which could be an ObjectVersionID or a HierObjectID; OBJECT_REF.id : OBJECT_ID, similarly abstract) - guessing there would silently build the wrong object instead of failing loudly.
{ archetype_id: 'ARCHETYPE_ID', template_id: 'TEMPLATE_ID', terminology_id: 'TERMINOLOGY_ID' }.freeze
- KNOWN_DERIVED_CACHE_TYPES =
%w[TIMEZONE UID VERSION_TREE_ID].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(cobject) ⇒ Factory
constructor
A new instance of Factory.
Constructor Details
#initialize(cobject) ⇒ Factory
Returns a new instance of Factory.
25 26 27 |
# File 'lib/openehr/rm/factory.rb', line 25 def initialize(cobject) @cobject = cobject end |
Class Method Details
.create(type, **param) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/openehr/rm/factory.rb', line 30 def create(type, **param) if type.include? '_' type = type.downcase.camelize else type = type.capitalize end class_eval("#{type}Factory").create(params(param)) end |
.params(param) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/openehr/rm/factory.rb', line 39 def params(param) param.each_with_object({}) do |item, parameters| key = item.shift value = item.shift parameters[key] = convert_value(key, value) end end |