summaryrefslogtreecommitdiff
path: root/lib/dslkeywords/notify.rb
blob: 3a973b8ffd25fedc25e198fe6e14051dd0a27d21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'erb'
require 'fileutils'

require_relative 'resource'
require_relative '../chained'

module RCM
  # Only to print out something
  class Notify < Resource
    include Chained

    def initialize(message)
      super(message)
      @message = message
    end

    def message(msg)
      @message = msg unless msg.nil?
    end

    def evaluate!
      return unless super

      do? "Notifying #{@message}" do
        puts "#{id} => #{@message}"
      end
    end
  end

  # Add notify keyword to the DSL
  class DSL
    def notify(message = nil, &block)
      return unless @conds_met

      n = Notify.new(message.nil? ? '' : message)
      n.message(n.instance_eval(&block)) if block
      self << n
      n
    end
  end
end