Class: Bricolage::JobFile

Inherits:
Object
  • Object
show all
Defined in:
lib/bricolage/jobfile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_id, values, path) ⇒ JobFile

Returns a new instance of JobFile.



112
113
114
115
116
# File 'lib/bricolage/jobfile.rb', line 112

def initialize(class_id, values, path)
  @class_id = class_id
  @values = values
  @path = Pathname(path)
end

Instance Attribute Details

#class_idObject (readonly)

Returns the value of attribute class_id.



118
119
120
# File 'lib/bricolage/jobfile.rb', line 118

def class_id
  @class_id
end

#pathObject (readonly)

Returns the value of attribute path.



120
121
122
# File 'lib/bricolage/jobfile.rb', line 120

def path
  @path
end

#valuesObject (readonly)

Returns the value of attribute values.



119
120
121
# File 'lib/bricolage/jobfile.rb', line 119

def values
  @values
end

Class Method Details

.load(ctx, path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bricolage/jobfile.rb', line 8

def JobFile.load(ctx, path)
  values =
    case path.to_s
    when /\.sql\.job\z/
      load_embedded_definition(ctx, path)
    when /\.(?:rb|py|sh)\.job\z/
      load_program_embedded_definition(ctx, path)
    else
      ctx.parameter_file_loader.load_yaml(path)
    end
  parse(values, path)
end

.parse(values, path) ⇒ Object



105
106
107
108
109
110
# File 'lib/bricolage/jobfile.rb', line 105

def JobFile.parse(values, path)
  values = values.dup
  class_id = values.delete('class') or
      raise ParameterError, "missing job class: #{path}"
  new(class_id, values, path)
end

Instance Method Details

#global_variablesObject



131
132
133
134
135
# File 'lib/bricolage/jobfile.rb', line 131

def global_variables
  {
    'script' => @path.to_s
  }
end

#job_idObject



122
123
124
125
# File 'lib/bricolage/jobfile.rb', line 122

def job_id
  base = @path.basename('.job').to_s
  File.basename(base, '.*')
end

#subsystemObject



127
128
129
# File 'lib/bricolage/jobfile.rb', line 127

def subsystem
  @path.parent.basename.to_s
end