Class: CapistranoNotification::Base

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/capistrano-notification.rb

Direct Known Subclasses

IRC

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vars = {}, &block) ⇒ Base

Returns a new instance of Base.



40
41
42
43
44
45
46
# File 'lib/capistrano-notification.rb', line 40

def initialize(vars = {}, &block)
  vars.each do |k, v|
    send k, v
  end

  block.call(self) if block
end

Class Method Details

.var(name, opts = {}) ⇒ Object



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
# File 'lib/capistrano-notification.rb', line 14

def self.var(name, opts = {})
  define_method name do |*args, &block|
    case args.size
    when 0
      unless block
        if value = instance_variable_get("@#{name}")
          value.is_a?(Proc) ? value.call(self) : value
        else
          default = opts[:default]
          send name, default.is_a?(Proc) ? default.call(self) : default
        end
      else
        instance_variable_set "@#{name}", block
      end
    when 1
      instance_variable_set "@#{name}", args.first
    else
      raise ArgumentError, "wrong number of arguments (#{args.size} for 0 or 1)"
    end
  end

  if opts[:required]
    validates_presence_of name
  end
end