Module: RDF::Util::File

Defined in:
lib/rdf/util/file.rb

Overview

Wrapper for Kernel.open. Allows implementations to override to get more suffisticated behavior for HTTP resources (e.g., Accept header).

Also supports the file: scheme for access to local files.

Classes include this module when they represent some form of a file as a base resource, for instance an HTTP resource representing the serialization of a Graph.

This module may be monkey-patched to allow for more options and interfaces.

Since:

  • 0.2.4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#content_typeString

Content

Returns:

  • (String)

Since:

  • 0.2.4



19
20
21
# File 'lib/rdf/util/file.rb', line 19

def content_type
  @content_type
end

Class Method Details

.open_file(filename_or_url, options = {}) {|IO| ... } ⇒ IO

Open the file, returning or yielding an IO stream and mime_type.

Parameters:

  • filename_or_url (String)

    to open

  • options (Hash{Symbol => Object}) (defaults to: {})

    options are ignored in this implementation. Applications are encouraged to override this implementation to provide more control over HTTP headers and redirect following.

Options Hash (options):

  • :headers (Array, String)

    HTTP Request headers.

Yields:

  • (IO)

    File stream

Returns:

  • (IO)

    File stream

Since:

  • 0.2.4



33
34
35
36
# File 'lib/rdf/util/file.rb', line 33

def self.open_file(filename_or_url, options = {}, &block)
  filename_or_url = $1 if filename_or_url.to_s.match(/^file:(.*)$/)
  Kernel.open(filename_or_url.to_s, &block)
end