Class: Inspec::Input::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/objects/input.rb

Overview

Information about how the input obtained its value. Each time it changes, an Input::Event is added to the #events array.

Constant Summary collapse

EVENT_PROPERTIES =
[
  :action,   # :create, :set, :fetch
  :provider, # Name of the plugin
  :priority, # Priority of this plugin for resolving conflicts.  1-100, higher numbers win.
  :value,    # New value, if provided.
  :file,     # File containing the input-changing action, if known
  :line,     # Line in file containing the input-changing action, if known
  :hit,      # if action is :fetch, true if the remote source had the input
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties = {}) ⇒ Event

Returns a new instance of Event.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/inspec/objects/input.rb', line 41

def initialize(properties = {})
  @value_has_been_set = false

  properties.each do |prop_name, prop_value|
    if EVENT_PROPERTIES.include? prop_name
      # OK, save the property
      send((prop_name.to_s + '=').to_sym, prop_value)
    else
      raise "Unrecognized property to Input::Event: #{prop_name}"
    end
  end
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



39
40
41
# File 'lib/inspec/objects/input.rb', line 39

def value
  @value
end

Class Method Details

.probe_stackObject



74
75
76
77
78
# File 'lib/inspec/objects/input.rb', line 74

def self.probe_stack
  frames = caller_locations(2, 40)
  frames.reject! { |f| f.path && f.path.include?('/lib/inspec/') }
  frames.first
end

Instance Method Details

#diagnostic_stringObject



64
65
66
# File 'lib/inspec/objects/input.rb', line 64

def diagnostic_string
  to_h.reject { |_, val| val.nil? }.to_a.map { |pair| "#{pair[0]}: '#{pair[1]}'" }.join(', ')
end

#to_hObject



68
69
70
71
72
# File 'lib/inspec/objects/input.rb', line 68

def to_h
  EVENT_PROPERTIES.each_with_object({}) do |prop, hash|
    hash[prop] = send(prop)
  end
end

#value_has_been_set?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/inspec/objects/input.rb', line 60

def value_has_been_set?
  @value_has_been_set
end