Class: Heathen::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/heathen/job.rb

Overview

This is the instance of a conversion job itself. All the information needed by the conversion tasks is held here.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, content, language = 'en', sandbox_dir = nil) ⇒ Job

Constructs a new job

Parameters:

  • action (String)

    the action to be performed

  • content (String)

    the file body

  • language (String) (defaults to: 'en')

    the file's language

  • sandbox_dir (String) (defaults to: nil)

    sandbox directory for temporary files


28
29
30
31
32
33
34
35
# File 'lib/heathen/job.rb', line 28

def initialize action, content, language='en', sandbox_dir=nil
  @action = action
  @language = language
  @original_content = content
  @original_mime_type = content.mime_type
  self.content = @original_content
  @sandbox_dir = sandbox_dir
end

Instance Attribute Details

#actionObject

The action to be performed


8
9
10
# File 'lib/heathen/job.rb', line 8

def action
  @action
end

#contentObject

The current content (this may change, step-by-step)


16
17
18
# File 'lib/heathen/job.rb', line 16

def content
  @content
end

#languageObject

The original document's language


10
11
12
# File 'lib/heathen/job.rb', line 10

def language
  @language
end

#mime_typeObject (readonly)

The current content's mime type


18
19
20
# File 'lib/heathen/job.rb', line 18

def mime_type
  @mime_type
end

#original_contentObject

The original document content


14
15
16
# File 'lib/heathen/job.rb', line 14

def original_content
  @original_content
end

#original_mime_typeObject

The original document's mime_type


12
13
14
# File 'lib/heathen/job.rb', line 12

def original_mime_type
  @original_mime_type
end

#sandbox_dirObject

A scratch directory, where temporary files may be placed, in the knowledge that they will be cleaned up when the job completes.


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

def sandbox_dir
  @sandbox_dir
end

Instance Method Details

#content_file(suffix = '') ⇒ Object

Returns a path to the content stored on disk. This is needed by those conversion steps which work only on files, rather than content in memory. The first time this method is called, for a given step, a temporary file is created and the content is written to it. This will persist until the content is changed.


50
51
52
53
54
55
56
57
58
59
# File 'lib/heathen/job.rb', line 50

def content_file suffix=''
  @tempfile ||= begin
    t = Tempfile.new ["heathen",suffix], @sandbox_dir
    t.binmode
    t.write @content
    t.close
    t
  end
  @tempfile.path
end

#reset_content_file!Object

Call this to reset the tempfile between multisteps tasks


62
63
64
# File 'lib/heathen/job.rb', line 62

def reset_content_file!
  @tempfile = nil
end