Class: Itamae::Notification

Inherits:
Struct
  • Object
show all
Defined in:
lib/itamae/notification.rb

Direct Known Subclasses

Subscription

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



4
5
6
# File 'lib/itamae/notification.rb', line 4

def action
  @action
end

#defined_in_resourceObject

Returns the value of attribute defined_in_resource

Returns:

  • (Object)

    the current value of defined_in_resource



4
5
6
# File 'lib/itamae/notification.rb', line 4

def defined_in_resource
  @defined_in_resource
end

#target_resource_descObject

Returns the value of attribute target_resource_desc

Returns:

  • (Object)

    the current value of target_resource_desc



4
5
6
# File 'lib/itamae/notification.rb', line 4

def target_resource_desc
  @target_resource_desc
end

#timingObject

Returns the value of attribute timing

Returns:

  • (Object)

    the current value of timing



4
5
6
# File 'lib/itamae/notification.rb', line 4

def timing
  @timing
end

Class Method Details

.create(*args) ⇒ Object



5
6
7
# File 'lib/itamae/notification.rb', line 5

def self.create(*args)
  self.new(*args).tap(&:validate!)
end

Instance Method Details

#action_resourceObject



17
18
19
# File 'lib/itamae/notification.rb', line 17

def action_resource
  resource
end

#delayed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/itamae/notification.rb', line 25

def delayed?
  [:delay, :delayed].include?(timing)
end

#immediately?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/itamae/notification.rb', line 29

def immediately?
  timing == :immediately
end

#resourceObject



9
10
11
# File 'lib/itamae/notification.rb', line 9

def resource
  runner.children.find_resource_by_description(target_resource_desc)
end

#runObject



13
14
15
# File 'lib/itamae/notification.rb', line 13

def run
  action_resource.run(action)
end

#runnerObject



21
22
23
# File 'lib/itamae/notification.rb', line 21

def runner
  defined_in_resource.recipe.runner
end

#validate!Object



33
34
35
36
37
38
# File 'lib/itamae/notification.rb', line 33

def validate!
  unless [:delay, :delayed, :immediately].include?(timing)
    Itamae.logger.error "'#{timing}' is not valid notification timing. (Valid option is delayed or immediately)"
    abort
  end
end