Parent

Files

Class/Module Index [+]

Quicksearch

Dragonfly::Job

Constants

STEPS

Attributes

app[R]
next_step_index[RW]
steps[RW]
temp_object[R]
url_attrs[R]

Public Class Methods

deserialize(string, app) click to toggle source
# File lib/dragonfly/job.rb, line 174
def deserialize(string, app)
  array = begin
    Serializer.json_decode(string)
  rescue Serializer::BadString
    if app.allow_legacy_urls
      Serializer.marshal_decode(string, :check_malicious => true) # legacy strings
    else
      raise
    end
  end
  from_a(array, app)
end
from_a(steps_array, app) click to toggle source
# File lib/dragonfly/job.rb, line 161
def from_a(steps_array, app)
  unless steps_array.is_a?(Array) &&
         steps_array.all?{|s| s.is_a?(Array) && step_abbreviations[s.first.to_s] }
    raise InvalidArray, "can't define a job from #{steps_array.inspect}"
  end
  job = app.new_job
  steps_array.each do |step_array|
    step_class = step_abbreviations[step_array.shift.to_s]
    job.steps << step_class.new(job, *step_array)
  end
  job
end
new(app, content=nil, meta={}, url_attrs={}) click to toggle source
# File lib/dragonfly/job.rb, line 221
def initialize(app, content=nil, meta={}, url_attrs={})
  @app = app
  @steps = []
  @next_step_index = 0
  @previous_temp_objects = []
  update(content, meta) if content
  self.url_attrs = url_attrs
end
step_abbreviations() click to toggle source
# File lib/dragonfly/job.rb, line 187
def step_abbreviations
  @step_abbreviations ||= STEPS.inject({}){|hash, step_class| hash[step_class.abbreviation] = step_class; hash }
end
step_names() click to toggle source
# File lib/dragonfly/job.rb, line 191
def step_names
  @step_names ||= STEPS.map{|step_class| step_class.step_name }
end

Public Instance Methods

analyse(method, *args) click to toggle source
# File lib/dragonfly/job.rb, line 261
def analyse(method, *args)
  analyser.analyse(result, method, *args)
end
applied?() click to toggle source
# File lib/dragonfly/job.rb, line 273
def applied?
  next_step_index == steps.length
end
applied_steps() click to toggle source
# File lib/dragonfly/job.rb, line 277
def applied_steps
  steps[0...next_step_index]
end
apply() click to toggle source

Applying, etc.

# File lib/dragonfly/job.rb, line 267
def apply
  pending_steps.each{|step| step.apply }
  self.next_step_index = steps.length
  self
end
b64_data() click to toggle source
# File lib/dragonfly/job.rb, line 332
def b64_data
  "data:#{mime_type};base64,#{Base64.encode64(data)}"
end
close() click to toggle source
# File lib/dragonfly/job.rb, line 407
def close
  previous_temp_objects.each{|temp_object| temp_object.close }
  temp_object.close if temp_object
end
encode_step() click to toggle source
# File lib/dragonfly/job.rb, line 380
def encode_step
  last_step_of_type(Encode)
end
fetch_file_step() click to toggle source
# File lib/dragonfly/job.rb, line 368
def fetch_file_step
  last_step_of_type(FetchFile)
end
fetch_step() click to toggle source
# File lib/dragonfly/job.rb, line 360
def fetch_step
  last_step_of_type(Fetch)
end
fetch_url_step() click to toggle source
# File lib/dragonfly/job.rb, line 372
def fetch_url_step
  last_step_of_type(FetchUrl)
end
generate_step() click to toggle source
# File lib/dragonfly/job.rb, line 364
def generate_step
  last_step_of_type(Generate)
end
initialize_copy(other) click to toggle source

Used by 'dup' and 'clone'

# File lib/dragonfly/job.rb, line 231
def initialize_copy(other)
  self.steps = other.steps.map do |step|
    step.class.new(self, *step.args)
  end
end
inspect() click to toggle source
# File lib/dragonfly/job.rb, line 395
def inspect
  "<Dragonfly::Job app=#{app.name.inspect}, steps=#{steps.inspect}, temp_object=#{temp_object.inspect}, steps applied:#{applied_steps.length}/#{steps.length} >"
end
pending_steps() click to toggle source
# File lib/dragonfly/job.rb, line 281
def pending_steps
  steps[next_step_index..-1]
end
process_steps() click to toggle source
# File lib/dragonfly/job.rb, line 376
def process_steps
  steps.select{|s| s.is_a?(Process) }
end
serialize() click to toggle source
# File lib/dragonfly/job.rb, line 297
def serialize
  Serializer.json_encode(to_a)
end
sha() click to toggle source
# File lib/dragonfly/job.rb, line 305
def sha
  Digest::SHA1.hexdigest("#{to_unique_s}#{app.secret}")[0...8]
end
step_types() click to toggle source
# File lib/dragonfly/job.rb, line 384
def step_types
  steps.map{|s| s.class.step_name }
end
store(opts={}) click to toggle source

Misc

# File lib/dragonfly/job.rb, line 390
def store(opts={})
  temp_object = result
  app.store(temp_object, opts_for_store.merge(opts).merge(:meta => temp_object.meta))
end
temp_object=(temp_object) click to toggle source
# File lib/dragonfly/job.rb, line 240
def temp_object=(temp_object)
  previous_temp_objects.push(@temp_object) if @temp_object
  @temp_object = temp_object
end
to_a() click to toggle source
# File lib/dragonfly/job.rb, line 285
def to_a
  steps.map{|step|
    [step.class.abbreviation, *step.args]
  }
end
to_app() click to toggle source

to_stuff...

# File lib/dragonfly/job.rb, line 338
def to_app
  JobEndpoint.new(self)
end
to_fetched_job(uid) click to toggle source
# File lib/dragonfly/job.rb, line 346
def to_fetched_job(uid)
  new_job = self.class.new(app, temp_object, meta, url_attrs)
  new_job.fetch!(uid)
  new_job.next_step_index = 1
  new_job
end
to_response(env={"REQUEST_METHOD" => "GET"}) click to toggle source
# File lib/dragonfly/job.rb, line 342
def to_response(env={"REQUEST_METHOD" => "GET"})
  to_app.call(env)
end
to_unique_s() click to toggle source

Serializing, etc.

# File lib/dragonfly/job.rb, line 293
def to_unique_s
  to_a.to_dragonfly_unique_s
end
uid() click to toggle source

Step inspection

# File lib/dragonfly/job.rb, line 355
def uid
  step = fetch_step
  step.uid if step
end
unique_signature() click to toggle source
# File lib/dragonfly/job.rb, line 301
def unique_signature
  Digest::SHA1.hexdigest(to_unique_s)
end
update(content, new_meta) click to toggle source
# File lib/dragonfly/job.rb, line 399
def update(content, new_meta)
  if new_meta
    new_meta.merge!(new_meta.delete(:meta)) if new_meta[:meta] # legacy data etc. may have nested meta hash - deprecate gracefully here
  end
  old_meta = temp_object ? temp_object.meta : {}
  self.temp_object = TempObject.new(content, old_meta.merge(new_meta || {}))
end
url(opts={}) click to toggle source

URLs, etc.

# File lib/dragonfly/job.rb, line 322
def url(opts={})
  app.url_for(self, attributes_for_url.merge(opts)) unless steps.empty?
end
url_attrs=(hash) click to toggle source
# File lib/dragonfly/job.rb, line 326
def url_attrs=(hash)
  @url_attrs = UrlAttributes[hash]
end
validate_sha!(sha) click to toggle source
# File lib/dragonfly/job.rb, line 309
def validate_sha!(sha)
  case sha
  when nil
    raise NoSHAGiven
  when self.sha
    self
  else
    raise IncorrectSHA, sha
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.