class Object
Public Instance Methods
array_difference(first, second)
click to toggle source
# File lib/chewy/rspec/update_index.rb, line 241 def array_difference(first, second) difference = first.to_ary.dup second.to_ary.each do |element| index = difference.index(element) difference.delete_at(index) if index end difference.none? end
compare_attributes(expected, real)
click to toggle source
# File lib/chewy/rspec/update_index.rb, line 228 def compare_attributes(expected, real) expected.inject(true) do |result, (key, value)| equal = if value.is_a?(Array) && real[key].is_a?(Array) array_difference(value, real[key]) && array_difference(real[key], value) elsif value.is_a?(Hash) && real[key].is_a?(Hash) compare_attributes(value, real[key]) else real[key] == value end result && equal end end
deep_dup()
click to toggle source
Returns a deep copy of object if it's duplicable. If it's not duplicable, returns self
.
object = Object.new dup = object.deep_dup dup.instance_variable_set(:@a, 1) object.instance_variable_defined?(:@a) # => false dup.instance_variable_defined?(:@a) # => true
# File lib/chewy/backports/deep_dup.rb, line 13 def deep_dup duplicable? ? dup : self end
duplicable?()
click to toggle source
Can you safely dup this object?
False for nil
, false
, true
, symbol, and number objects; true otherwise.
# File lib/chewy/backports/duplicable.rb, line 24 def duplicable? true end
extract_documents(*args)
click to toggle source
# File lib/chewy/rspec/update_index.rb, line 210 def extract_documents(*args) options = args.extract_options! expected_count = options[:times] || options[:count] expected_attributes = (options[:with] || options[:attributes] || {}).deep_symbolize_keys args.flatten.map do |document| id = document.respond_to?(:id) ? document.id.to_s : document.to_s [id, { document: document, expected_count: expected_count, expected_attributes: expected_attributes, real_count: 0, real_attributes: {} }] end.to_h end
mock_bulk_request()
click to toggle source
# File lib/chewy/rspec/update_index.rb, line 206 def mock_bulk_request @mock_bulk_request ||= MockBulkRequest.new end
supports_block_expectations?()
click to toggle source
# File lib/chewy/rspec/update_index.rb, line 91 def supports_block_expectations? true end
try_require(path)
click to toggle source
# File lib/chewy.rb, line 24 def try_require(path) require path rescue LoadError nil end