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.



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/inspec/input.rb', line 62

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.



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

def value
  @value
end

Class Method Details

.probe_stackObject



94
95
96
97
98
# File 'lib/inspec/input.rb', line 94

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



84
85
86
# File 'lib/inspec/input.rb', line 84

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

#to_hObject



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

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

#value_has_been_set?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/inspec/input.rb', line 80

def value_has_been_set?
  @value_has_been_set
end