class HealthInspector::Pairing

Attributes

context[R]
errors[R]
local[RW]
name[RW]
server[RW]

Public Class Methods

new(context, opts = {}) click to toggle source
# File lib/health_inspector/pairing.rb, line 19
def initialize(context, opts = {})
  @context     = context
  @name        = opts[:name]
  @local       = opts[:local]
  @server      = opts[:server]

  @validations = []
  @errors      = Errors.new
end

Public Instance Methods

hash_diff(original, other) click to toggle source
# File lib/health_inspector/pairing.rb, line 33
def hash_diff(original, other)
  recursive_diff(stringify_hash_keys(original), stringify_hash_keys(other))
end
recursive_diff(original, other) click to toggle source
# File lib/health_inspector/pairing.rb, line 54
def recursive_diff(original, other)
  (original.keys + other.keys).uniq.reduce({}) do |memo, key|
    unless original[key] == other[key]
      if original[key].is_a?(Hash) && other[key].is_a?(Hash)
        diff = recursive_diff(original[key], other[key])
        memo[key] = diff unless diff.empty?
      else
        memo[key] = { 'server' => original[key], 'local' => other[key] }
      end
    end

    memo
  end
end
stringify_hash_keys(original) click to toggle source
# File lib/health_inspector/pairing.rb, line 37
def stringify_hash_keys(original)
  original.keys.reduce({}) do |original_strkey, key|
    original_strkey[key.to_s] = stringify_item(original[key])
    original_strkey
  end
end
stringify_item(item) click to toggle source
# File lib/health_inspector/pairing.rb, line 44
def stringify_item(item)
  if item.is_a?(Hash)
    stringify_hash_keys(item)
  elsif item.is_a?(Array)
    item.map { |array_item| stringify_item(array_item) }
  else # must be a string
    item
  end
end
validate() click to toggle source
# File lib/health_inspector/pairing.rb, line 29
def validate
  methods.grep(/^validate_/).each { |meth| send(meth) }
end