Sha256: 37b3924f49f2faaf1dc744ee1bad6096ce59e324de5c64e79bacc8bfbde1261f

Contents?: true

Size: 949 Bytes

Versions: 41

Compression:

Stored size: 949 Bytes

Contents

require 'itamae'

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(options)
      action_resource.run(action, options)
    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)
        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

41 entries across 41 versions & 1 rubygems

Version Path
itamae-1.4.5 lib/itamae/notification.rb
itamae-1.4.4 lib/itamae/notification.rb
itamae-1.4.3 lib/itamae/notification.rb
itamae-1.4.2 lib/itamae/notification.rb
itamae-1.4.1 lib/itamae/notification.rb
itamae-1.4.0 lib/itamae/notification.rb
itamae-1.3.6 lib/itamae/notification.rb
itamae-1.3.5 lib/itamae/notification.rb
itamae-1.3.4 lib/itamae/notification.rb
itamae-1.3.3 lib/itamae/notification.rb
itamae-1.3.2 lib/itamae/notification.rb
itamae-1.3.1 lib/itamae/notification.rb
itamae-1.3.0 lib/itamae/notification.rb
itamae-1.2.21 lib/itamae/notification.rb
itamae-1.2.19 lib/itamae/notification.rb
itamae-1.2.18 lib/itamae/notification.rb
itamae-1.2.17 lib/itamae/notification.rb
itamae-1.2.16 lib/itamae/notification.rb
itamae-1.2.15 lib/itamae/notification.rb
itamae-1.2.14 lib/itamae/notification.rb