Class: VagrantPlugins::Lifecycle::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-lifecycle/config.rb

Constant Summary collapse

MAYBE =
Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



16
17
18
19
20
21
22
23
# File 'lib/vagrant-lifecycle/config.rb', line 16

def initialize
  super

  @default_event = nil
  @events = Hash.new

  @__finalized = false
end

Instance Attribute Details

#default_eventSymbol

Override default provision

Returns:

  • (Symbol)


14
15
16
# File 'lib/vagrant-lifecycle/config.rb', line 14

def default_event
  @default_event
end

#eventsHash

Lifecycle events configuration.

Returns:

  • (Hash)


10
11
12
# File 'lib/vagrant-lifecycle/config.rb', line 10

def events
  @events
end

Instance Method Details

#finalize!Object



25
26
27
# File 'lib/vagrant-lifecycle/config.rb', line 25

def finalize!
  @__finalized = true
end

#missing?(obj) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/vagrant-lifecycle/config.rb', line 66

def missing?(obj)
  obj.to_s.strip.empty?
end

#to_hashObject



57
58
59
60
61
62
63
64
# File 'lib/vagrant-lifecycle/config.rb', line 57

def to_hash
  raise "Must finalize first." if !@__finalized

  {
      default_event: @default_event,
      events: @events
  }
end

#validate(machine) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vagrant-lifecycle/config.rb', line 29

def validate(machine)
  errors = _detected_errors

  unless @default_event.nil?
    unless @events.key?(@default_event) || @events.key?(@default_event.to_s) || @events.key?(@default_event.to_sym)
      errors << "#{@default_event} event configuration not found!"
    end
  end

  if @events.is_a?(Hash)
    @events.each do |k, v|
      if v.respond_to? :call
        unless v.arity == 2
          errors << "#{k} event configuration is expected to be lambda with 2 arguments!"
        end
      else
        errors << "#{k} event configuration is expected to be lambda!"
      end
    end
  else
    errors << "events configuration is expected to be a hash!"
  end

  {
      "Lifecycle" => errors
  }
end