Sha256: 508240d2bd78d1db0fe36456a8b77259631c845dc9ae09e035f8e34940119129

Contents?: true

Size: 697 Bytes

Versions: 21

Compression:

Stored size: 697 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
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ecoportal-api-0.8.5 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.8.4 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.8.3 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.8.2 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.7.5 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.7.4 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.7.3 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.7.2 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.7.1 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.7.0 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.6.0 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.5.8 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.5.7 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.5.6 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.5.5 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.5.3 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.5.1 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.5.0 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.4.3 lib/ecoportal/api/common/doc_helpers.rb
ecoportal-api-0.4.2 lib/ecoportal/api/common/doc_helpers.rb