class AgnosticBackend::RSpec::Matchers::DefineIndexField
Public Class Methods
new(name, for_index: nil, type: nil, **expected_custom_attributes)
click to toggle source
# File lib/agnostic_backend/rspec/matchers.rb, line 19 def initialize(name, for_index: nil, type: nil, **expected_custom_attributes) @name = name @for_index = for_index @type = type @expected_custom_attributes = expected_custom_attributes end
Public Instance Methods
description()
click to toggle source
# File lib/agnostic_backend/rspec/matchers.rb, line 36 def description expectation_message end
failure_message()
click to toggle source
# File lib/agnostic_backend/rspec/matchers.rb, line 40 def failure_message "expected to #{expectation_message}" end
matches?(klass)
click to toggle source
# File lib/agnostic_backend/rspec/matchers.rb, line 26 def matches?(klass) @for_index ||= klass.index_name manager = klass.index_content_manager(@for_index) manager.nil? and return false field = manager.contents[@name.to_s] field.nil? and return false type_matches?(field, @type) && custom_attributes_match?(field, @expected_custom_attributes) rescue false end
Private Instance Methods
custom_attributes_match?(field, expected_attributes)
click to toggle source
# File lib/agnostic_backend/rspec/matchers.rb, line 57 def custom_attributes_match?(field, expected_attributes) return true if expected_attributes.empty? field.type.options == expected_attributes end
expectation_message()
click to toggle source
# File lib/agnostic_backend/rspec/matchers.rb, line 46 def expectation_message "define the index field :#{@name}" + (@type.nil? ? "" : " with type :#{@type}") + (@for_index.nil? ? "" : " for index '#{@for_index}'" ) end
type_matches?(field, expected_type)
click to toggle source
# File lib/agnostic_backend/rspec/matchers.rb, line 52 def type_matches?(field, expected_type) return true if expected_type.nil? field.type.matches?(expected_type) end