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



2
3
4
# File 'lib/itamae/notification.rb', line 2

def action
  @action
end

#defined_in_resourceObject

Returns the value of attribute defined_in_resource

Returns:

  • (Object)

    the current value of defined_in_resource



2
3
4
# File 'lib/itamae/notification.rb', line 2

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



2
3
4
# File 'lib/itamae/notification.rb', line 2

def target_resource_desc
  @target_resource_desc
end

#timingObject

Returns the value of attribute timing

Returns:

  • (Object)

    the current value of timing



2
3
4
# File 'lib/itamae/notification.rb', line 2

def timing
  @timing
end

Class Method Details

.create(*args) ⇒ Object



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

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

Instance Method Details

#action_resourceObject



15
16
17
# File 'lib/itamae/notification.rb', line 15

def action_resource
  resource
end

#delayed?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/itamae/notification.rb', line 23

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

#immediately?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/itamae/notification.rb', line 27

def immediately?
  timing == :immediately
end

#resourceObject



7
8
9
# File 'lib/itamae/notification.rb', line 7

def resource
  runner.children.find_resource_by_description(target_resource_desc)
end

#runObject



11
12
13
# File 'lib/itamae/notification.rb', line 11

def run
  action_resource.run(action)
end

#runnerObject



19
20
21
# File 'lib/itamae/notification.rb', line 19

def runner
  defined_in_resource.recipe.runner
end

#validate!Object



31
32
33
34
35
36
# File 'lib/itamae/notification.rb', line 31

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