summaryrefslogtreecommitdiff
path: root/lib/dslkeywords/notify.rb
blob: 602d216b3648bca6486c8783efc983d62f8ed087 (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
require 'erb'
require 'fileutils'

require_relative 'resource'

module RCM
  # Only to print out something
  class Notify < Resource
    def initialize(message)
      super(message)
      @message = message
    end

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

    def evaluate! = puts "#{id} => #{@message}"
  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