Sha256: 3cc145fe595ab4433f73b5c7bb0c640812379b56e22502804d15902847e3c52f

Contents?: true

Size: 796 Bytes

Versions: 4

Compression:

Stored size: 796 Bytes

Contents

module Ecoportal
  module API
    module Common
      module DocHelpers
        def get_body(doc)
          if doc.respond_to?(:as_update)
            doc.as_update
          elsif doc.respond_to?(:as_json)
            doc.as_json
          else
            doc
          end
        end
        def get_id(doc)
          id = nil
          id ||= doc.id if doc.respond_to?(:id)
          id ||= doc.external_id if doc.respond_to?(:external_id)
          id ||= doc["id"] if doc.is_a?(Hash)
          id ||= doc["external_id"] if doc.is_a?(Hash)
          id ||= doc if doc.is_a?(String)
          id or raise "No ID has been given!"
          id
        end
        def get_external_id(doc)
          doc.respond_to?(:external_id) ? doc.external_id : nil
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ecoportal-api-0.3.0.pre1 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.2.2 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.2.1 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.2.0 lib/ecoportal/api/common/doc_helpers.rb