Class: PuppetX::Relay::Agent::Model::TaskRun

Inherits:
Object
  • Object
show all
Includes:
Stateful
Defined in:
lib/puppet_x/relay/agent/model/task_run.rb

Defined Under Namespace

Classes: MissingNameError, MissingScopeError

Instance Attribute Summary collapse

Attributes included from Stateful

#id, #state

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Stateful

#with_state

Constructor Details

#initialize(opts) ⇒ TaskRun

Returns a new instance of TaskRun.

Parameters:

  • opts (Hash)

Raises:



46
47
48
49
50
51
52
53
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 46

def initialize(opts)
  opts = defaults.merge(opts)

  raise MissingScopeError unless opts.key? 'scope'
  raise MissingNameError unless opts.key? 'name'

  opts.each { |key, value| instance_variable_set("@#{key}", value) }
end

Instance Attribute Details

#environmentString (readonly)

Returns:

  • (String)


28
29
30
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 28

def environment
  @environment
end

#nameString (readonly)

Returns:

  • (String)


34
35
36
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 34

def name
  @name
end

#noopBoolean (readonly)

Returns:

  • (Boolean)


40
41
42
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 40

def noop
  @noop
end

#paramsHash (readonly)

Returns:

  • (Hash)


37
38
39
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 37

def params
  @params
end

#scopeScope (readonly)

Returns:



31
32
33
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 31

def scope
  @scope
end

#targetsArray<Hash> (readonly)

Returns:

  • (Array<Hash>)


43
44
45
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 43

def targets
  @targets
end

Class Method Details

.from_h(hsh) ⇒ Object



19
20
21
22
23
24
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 19

def from_h(hsh)
  hsh = hsh.dup
  hsh['scope'] = Scope.from_h(hsh['scope']) if hsh.key? 'scope'
  hsh['state'] = State.from_h(hsh['state']) if hsh.key? 'state'
  new(hsh)
end

Instance Method Details

#to_json(*args) ⇒ String

Returns:

  • (String)


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/puppet_x/relay/agent/model/task_run.rb', line 56

def to_json(*args)
  {
    id: id,
    environment: environment,
    scope: scope,
    name: name,
    params: params,
    noop: noop,
    targets: targets,
    state: state,
  }.to_json(*args)
end