Class: Inspec::Input::Event

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

Overview

TODO: break this out to its own file under inspec/input? 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.



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/inspec/input.rb', line 54

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.



52
53
54
# File 'lib/inspec/input.rb', line 52

def value
  @value
end

Class Method Details

.probe_stackObject



87
88
89
90
91
# File 'lib/inspec/input.rb', line 87

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



77
78
79
# File 'lib/inspec/input.rb', line 77

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

#to_hObject



81
82
83
84
85
# File 'lib/inspec/input.rb', line 81

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

#value_has_been_set?Boolean

Returns:

  • (Boolean)


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

def value_has_been_set?
  @value_has_been_set
end