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.



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

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.



37
38
39
# File 'lib/inspec/objects/input.rb', line 37

def value
  @value
end

Class Method Details

.probe_stackObject



72
73
74
75
76
# File 'lib/inspec/objects/input.rb', line 72

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



62
63
64
# File 'lib/inspec/objects/input.rb', line 62

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

#to_hObject



66
67
68
69
70
# File 'lib/inspec/objects/input.rb', line 66

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

#value_has_been_set?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/inspec/objects/input.rb', line 58

def value_has_been_set?
  @value_has_been_set
end