Class: IMW::Resource

Inherits:
Object
  • Object
show all
Includes:
Utils::DynamicallyExtendable, Utils::HasURI
Defined in:
lib/imw.rb,
lib/imw/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ Resource

Returns a new instance of Resource.

Raises:



28
29
30
31
# File 'lib/imw.rb', line 28

def initialize(uri, mode='r')
  raise FileModeError.new("'#{mode}' is not a valid access mode") unless valid_modes.include? mode
  @uri = Uri.new(uri)
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



6
7
8
# File 'lib/imw/resource.rb', line 6

def mode
  @mode
end

#resource_optionsObject

Returns the value of attribute resource_options.



6
7
8
# File 'lib/imw/resource.rb', line 6

def resource_options
  @resource_options
end

#uriObject (readonly)

Returns the value of attribute uri.



26
27
28
# File 'lib/imw.rb', line 26

def uri
  @uri
end

Class Method Details

.exists?(resource) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/imw.rb', line 42

def self.exists? resource
  true
end

.open(uri, mode = 'r', &blk) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/imw.rb', line 33

def self.open(uri, mode='r', &blk)
  resource = Resource.new(uri, mode)
  if block_given?
    yield resource
  else
    return resource
  end
end

Instance Method Details

#closeObject



33
34
# File 'lib/imw/resource.rb', line 33

def close
end

#reopenObject



36
37
38
# File 'lib/imw/resource.rb', line 36

def reopen
  IMW.open(uri.to_s)
end

#should_exist!(message = nil) ⇒ Object

Raises:



26
27
28
29
30
31
# File 'lib/imw/resource.rb', line 26

def should_exist!(message=nil)
  raise IMW::Error.new([message, "No path defined for #{self.inspect} extended by #{modules.join(' ')}"].compact.join(', '))          unless respond_to?(:path)
  raise IMW::Error.new([message, "No exist? method defined for #{self.inspect} extended by #{modules.join(' ')}"].compact.join(', ')) unless respond_to?(:exist?)
  raise IMW::PathError.new([message, "#{path} does not exist"].compact.join(', '))                                                    unless exist?
  self
end