Class: Putpaws::Provision::Resources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/putpaws/provision/resources/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, state:, clients:) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
# File 'lib/putpaws/provision/resources/base.rb', line 8

def initialize(config:, state:, clients:)
  @config = config
  @state = state
  @clients = clients
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



7
8
9
# File 'lib/putpaws/provision/resources/base.rb', line 7

def clients
  @clients
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/putpaws/provision/resources/base.rb', line 7

def config
  @config
end

#stateObject (readonly)

Returns the value of attribute state.



7
8
9
# File 'lib/putpaws/provision/resources/base.rb', line 7

def state
  @state
end

Instance Method Details

#changed?(_current) ⇒ Boolean

Subclasses implement: name, current, create!, outputs(current) and optionally: changed?(current), update!(current)

Returns:

  • (Boolean)


21
22
23
# File 'lib/putpaws/provision/resources/base.rb', line 21

def changed?(_current)
  false
end

#ensure!Object

Idempotent apply. Always returns the outputs hash.



32
33
34
35
36
37
38
39
40
41
# File 'lib/putpaws/provision/resources/base.rb', line 32

def ensure!
  c = current
  if c.nil?
    create!
  elsif changed?(c)
    update!(c)
  else
    outputs(c)
  end
end

#kindObject



14
15
16
# File 'lib/putpaws/provision/resources/base.rb', line 14

def kind
  self.class.name.split('::').last
end

#planObject



25
26
27
28
29
# File 'lib/putpaws/provision/resources/base.rb', line 25

def plan
  c = current
  action = c.nil? ? :create : (changed?(c) ? :update : :skip)
  {action: action, kind: kind, name: name}
end

#update!(_current) ⇒ Object

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/putpaws/provision/resources/base.rb', line 43

def update!(_current)
  raise NotImplementedError, "#{kind} does not support update"
end