Sha256: d35a1990dc7406c6e55f704c4a38f99ca14204d38bfb3e43d242e49f84b7226a

Contents?: true

Size: 1.13 KB

Versions: 33

Compression:

Stored size: 1.13 KB

Contents

require 'json'

# Extension to FHIR::Model. Prepending this into FHIR::Model (done below)
# allows us to call super() on initialize when we overriding it,
# while also defining new methods and attributes
module InfernoFHIRModelExtensions
  attr_accessor :source_hash, :source_text

  def initialize(hash = {})
    super(hash)
    @source_hash = hash
  end

  def source_contents
    @source_text || JSON.generate(@source_hash)
  end
end

module FHIR
  class Model
    prepend ::InfernoFHIRModelExtensions
  end
end

# Extension to FHIR::Json. Prepending this into FHIR::Json (done below)
# allows us to call super() on from_json
module InfernoJson
  def from_json(json)
    resource = super(json)
    resource&.source_text = json
    resource
  end
end

# Extension to FHIR::Xml. Prepending this into FHIR::Xml (done below)
# allows us to call super() on from_xml
module InfernoXml
  def from_xml(xml)
    resource = super(xml)
    resource&.source_text = xml
    resource
  end
end

module FHIR
  module Json
    class << self
      prepend InfernoJson
    end
  end
end

module FHIR
  module Xml
    class << self
      prepend InfernoXml
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
inferno_core-0.4.43 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.42 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.41 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.40 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.39 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.38 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.35 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.34 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.33 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.32 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.31 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.30 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.29 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.28 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.27 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.26 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.25 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.24 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.23 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.22 lib/inferno/ext/fhir_models.rb