Sha256: 81c6ecbfe4497715a5598d1d2aebbc533071ab1ba79ab2165cd5d1a22d9436a4

Contents?: true

Size: 1.13 KB

Versions: 45

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

45 entries across 45 versions & 3 rubygems

Version Path
us_core_test_kit-0.4.5 lib/us_core_test_kit/ext/fhir_models.rb
inferno_core-0.4.8 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.7 lib/inferno/ext/fhir_models.rb
us_core_test_kit-0.4.4 lib/us_core_test_kit/ext/fhir_models.rb
inferno_core-0.4.7.pre lib/inferno/ext/fhir_models.rb
us_core_test_kit-0.4.3 lib/us_core_test_kit/ext/fhir_models.rb
inferno_core-0.4.6 lib/inferno/ext/fhir_models.rb
us_core_test_kit-0.4.2 lib/us_core_test_kit/ext/fhir_models.rb
inferno_core-0.4.5 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.4 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.3 lib/inferno/ext/fhir_models.rb
us_core_test_kit-0.4.1 lib/us_core_test_kit/ext/fhir_models.rb
us_core_test_kit-0.4.0 lib/us_core_test_kit/ext/fhir_models.rb
ipa_test_kit-0.2.0 lib/ipa_test_kit/ext/fhir_models.rb
inferno_core-0.4.2 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.2.pre lib/inferno/ext/fhir_models.rb
inferno_core-0.4.1 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.1.pre2 lib/inferno/ext/fhir_models.rb
inferno_core-0.4.1.pre lib/inferno/ext/fhir_models.rb
inferno_core-0.4.0 lib/inferno/ext/fhir_models.rb