Class: Arcp::Job::Accepted

Inherits:
Data
  • Object
show all
Defined in:
lib/arcp/job/accepted.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_id:, agent:, accepted_at:, lease: nil, credentials: nil) ⇒ Accepted

Returns a new instance of Accepted.



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

def initialize(job_id:, agent:, accepted_at:, lease: nil, credentials: nil)
  super
end

Instance Attribute Details

#accepted_atObject (readonly)

Returns the value of attribute accepted_at

Returns:

  • (Object)

    the current value of accepted_at



7
8
9
# File 'lib/arcp/job/accepted.rb', line 7

def accepted_at
  @accepted_at
end

#agentObject (readonly)

Returns the value of attribute agent

Returns:

  • (Object)

    the current value of agent



7
8
9
# File 'lib/arcp/job/accepted.rb', line 7

def agent
  @agent
end

#credentialsObject (readonly)

Returns the value of attribute credentials

Returns:

  • (Object)

    the current value of credentials



7
8
9
# File 'lib/arcp/job/accepted.rb', line 7

def credentials
  @credentials
end

#job_idObject (readonly)

Returns the value of attribute job_id

Returns:

  • (Object)

    the current value of job_id



7
8
9
# File 'lib/arcp/job/accepted.rb', line 7

def job_id
  @job_id
end

#leaseObject (readonly)

Returns the value of attribute lease

Returns:

  • (Object)

    the current value of lease



7
8
9
# File 'lib/arcp/job/accepted.rb', line 7

def lease
  @lease
end

Class Method Details

.credentials_from(h) ⇒ Object



30
31
32
33
34
# File 'lib/arcp/job/accepted.rb', line 30

def self.credentials_from(h)
  return nil unless h['credentials']

  Array(h['credentials']).map { |credential| Arcp::Credential.from_h(credential) }.freeze
end

.from_h(h) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/arcp/job/accepted.rb', line 12

def self.from_h(h)
  h = h.transform_keys(&:to_s)
  new(
    job_id: h.fetch('job_id'),
    agent: h.fetch('agent'),
    accepted_at: h['accepted_at'],
    lease: h['lease'] ? Arcp::Lease::Lease.from_h(h['lease']) : nil,
    credentials: credentials_from(h)
  )
end

Instance Method Details

#to_hObject



23
24
25
26
27
28
# File 'lib/arcp/job/accepted.rb', line 23

def to_h
  out = { 'job_id' => job_id, 'agent' => agent, 'accepted_at' => accepted_at }
  out['lease'] = lease.to_h if lease
  out['credentials'] = credentials.map(&:to_h) if credentials && !credentials.empty?
  out
end