Class: Dragonfly::Job::FetchUrl

Inherits:
Step show all
Defined in:
lib/dragonfly/job/fetch_url.rb

Defined Under Namespace

Classes: BadURI, CannotHandle, ErrorResponse, TooManyRedirects

Instance Attribute Summary

Attributes inherited from Step

#args, #job

Instance Method Summary collapse

Methods inherited from Step

abbreviation, #app, basename, #initialize, #inspect, step_name, #to_a

Constructor Details

This class inherits a constructor from Dragonfly::Job::Step

Instance Method Details

#applyObject



42
43
44
45
46
47
48
49
# File 'lib/dragonfly/job/fetch_url.rb', line 42

def apply
  if data_uri?
    update_from_data_uri
  else
    data = get_following_redirects(url)
    job.content.update(data, 'name' => filename)
  end
end

#data_uri?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/dragonfly/job/fetch_url.rb', line 38

def data_uri?
  uri =~ /\Adata:/
end

#filenameObject



33
34
35
36
# File 'lib/dragonfly/job/fetch_url.rb', line 33

def filename
  return if data_uri?
  @filename ||= parse_url(url).path[/[^\/]+\z/]
end

#initObject



21
22
23
# File 'lib/dragonfly/job/fetch_url.rb', line 21

def init
  job.url_attributes.name = filename
end

#uriObject



25
26
27
# File 'lib/dragonfly/job/fetch_url.rb', line 25

def uri
  args.first
end

#urlObject



29
30
31
# File 'lib/dragonfly/job/fetch_url.rb', line 29

def url
  @url ||= uri =~ /\A\w+:[^\d]/ ? uri : "http://#{uri}"
end