Sha256: ffde931ee6f23ef4e4bbd1d8a533d1bcaefbbbf5387776a5b847720938183ee6

Contents?: true

Size: 920 Bytes

Versions: 21

Compression:

Stored size: 920 Bytes

Contents

module Itamae
  class Notification < Struct.new(:defined_in_resource, :action, :target_resource_desc, :timing)
    def self.create(*args)
      self.new(*args).tap(&:validate!)
    end

    def resource
      runner.children.find_resource_by_description(target_resource_desc)
    end

    def run
      action_resource.run(action)
    end

    def action_resource
      resource
    end

    def runner
      defined_in_resource.recipe.runner
    end

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

    def immediately?
      timing == :immediately
    end

    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
  end

  class Subscription < Notification
    def action_resource
      defined_in_resource
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
itamae-1.14.1 lib/itamae/notification.rb
itamae-1.14.0 lib/itamae/notification.rb
itamae-1.13.1 lib/itamae/notification.rb
itamae-1.13.0 lib/itamae/notification.rb
itamae-1.12.6 lib/itamae/notification.rb
itamae-1.12.5 lib/itamae/notification.rb
itamae-1.12.4 lib/itamae/notification.rb
itamae-1.12.3 lib/itamae/notification.rb
itamae-1.12.2 lib/itamae/notification.rb
itamae-1.12.1 lib/itamae/notification.rb
itamae-1.12.0 lib/itamae/notification.rb
itamae-1.11.2 lib/itamae/notification.rb
itamae-1.11.1 lib/itamae/notification.rb
itamae-1.11.0 lib/itamae/notification.rb
itamae-1.10.10 lib/itamae/notification.rb
itamae-1.10.9 lib/itamae/notification.rb
itamae-1.10.8 lib/itamae/notification.rb
itamae-1.10.7 lib/itamae/notification.rb
itamae-1.10.6 lib/itamae/notification.rb
itamae-1.10.5 lib/itamae/notification.rb