Sha256: d1d2b959b880e75a7fe6d5d33ab80e9970689247bc6e16e41974d73f65c4a9be

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

module RailsConnector

module ObjBody
  # Returns the body (main content) of the Obj for non-binary Objs.
  # Returns nil for binary Objs.
  def body
    if binary?
      nil
    else
      StringTagging.tag_as_html(read_attribute_value('body'), self)
    end
  end

  # for binary Objs body_length equals the file size
  # for non-binary Objs body_length equals the number of characters in the body (main content)
  def body_length
    if binary?
      blob = find_blob
      blob ? blob.length : 0
    else
      (body || "").length
    end
  end

  # returns an URL to retrieve the Obj's body for binary Objs.
  # returns nil for non-binary Objs.
  def body_data_url
    if binary?
      blob = find_blob
      blob.url if blob
    end
  end

  def body_data_path # :nodoc:
    # not needed/supported when using cloud connector.
    nil
  end

  # returns the content type of the Obj's body for binary Objs.
  # returns nil for non-binary Objs.
  def body_content_type
    if binary?
      blob = find_blob
      if blob
        blob.content_type
      else
        "application/octet-stream"
      end
    end
  end

  private

  def find_blob
    blob_spec = read_attribute_value('blob')
    Blob.find(blob_spec["id"], :context => path) if blob_spec
  end
end

end # module RailsConnector

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.0.beta.200.891.647580e lib/rails_connector/obj_body.rb
infopark_cloud_connector-6.8.0.beta.200.889.d503e42 lib/rails_connector/obj_body.rb
infopark_cloud_connector-6.8.0.beta.200.883.f5f063b lib/rails_connector/obj_body.rb
infopark_cloud_connector-6.8.0.beta.200.884.4bd86e6 lib/rails_connector/obj_body.rb
infopark_cloud_connector-6.8.0.beta.200.869.9609b39 lib/rails_connector/obj_body.rb
infopark_cloud_connector-6.8.0.beta.200.856.8c0fec5 lib/rails_connector/obj_body.rb
infopark_cloud_connector-6.8.0.beta.200.809.bdfa8c3 lib/rails_connector/obj_body.rb
infopark_cloud_connector-6.8.0.beta.200.785.05d4af9 lib/rails_connector/obj_body.rb