Class: Cyclid::API::Job::JobView

Inherits:
Object
  • Object
show all
Defined in:
app/cyclid/job/job.rb

Overview

Non-ActiveRecord class which holds a complete Job, complete with serialised stages and the resolved sequence.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, context, org) ⇒ JobView

Returns a new instance of JobView.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/cyclid/job/job.rb', line 27

def initialize(job, context, org)
  @name = job[:name]
  @version = job[:version] || '1.0.0'

  @context = context
  @organization = org.name
  @environment = job[:environment] || {}
  @sources = job[:sources] || []
  @secrets = setec_astronomy(org, (job[:secrets] || {}))

  # Build a single unified list of StageViews
  @stages, @sequence = build_stage_collection(job, org)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'app/cyclid/job/job.rb', line 25

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



25
26
27
# File 'app/cyclid/job/job.rb', line 25

def version
  @version
end

Instance Method Details

#to_hashObject

Return everything, serialized into a hash



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/cyclid/job/job.rb', line 42

def to_hash
  hash = {}
  hash[:name] = @name
  hash[:version] = @version
  hash[:context] = @context
  hash[:organization] = @organization
  hash[:environment] = @environment
  hash[:sources] = @sources
  hash[:secrets] = @secrets
  hash[:stages] = @stages.each_with_object({}) do |(name, stage), h|
    h[name.to_sym] = Oj.dump(stage)
  end
  hash[:sequence] = @sequence

  return hash
end