Class: KManager::Resources::ResourceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/k_manager/resources/resource_factory.rb

Instance Method Summary collapse

Instance Method Details

#instance(resource_uri, **opts) ⇒ Object

Create a resource based on a resource URI.

Resources may be of type File or Web

The resource content_type should be passed in when it cannot be inferred (e.g. WebResource) for a FileResource this option is optional and will be inferred from the file extension.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/k_manager/resources/resource_factory.rb', line 14

def instance(resource_uri, **opts)
  scheme = resource_uri.scheme.to_sym

  case scheme
  when :file
    FileResource.new(resource_uri, **opts)
  when :http, :https
    WebResource.new(resource_uri, **opts)
  else
    raise 'Unknown schema'
  end
end