Sha256: 45c7ea3df06a76ed80baf0016f33b578fe36571e17bd95819c1dda059a86f641

Contents?: true

Size: 963 Bytes

Versions: 86

Compression:

Stored size: 963 Bytes

Contents

require 'itamae-mitsurin'

module ItamaeMitsurin
  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)
        ItamaeMitsurin.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

86 entries across 47 versions & 1 rubygems

Version Path
itamae-mitsurin-1.0.3 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-1.0.2 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-1.0.1 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-1.0.0 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-0.50 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.49 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.48 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.47 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.46 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-0.46 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.45 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-0.45 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.44 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-0.44 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.43 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-0.43 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.42 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-0.42 test/test_itamae-mitsurin/test_notification.rb
itamae-mitsurin-0.41 lib/itamae-mitsurin/notification.rb
itamae-mitsurin-0.41 test/test_itamae-mitsurin/test_notification.rb