module Chewy::Index::Wrapper
Attributes
_data[RW]
_object[RW]
attributes[R]
Public Class Methods
new(attributes = {})
click to toggle source
# File lib/chewy/index/wrapper.rb, line 24 def initialize(attributes = {}) @attributes = attributes.stringify_keys end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
# File lib/chewy/index/wrapper.rb, line 28 def ==(other) return true if super if other.is_a?(Chewy::Index) self.class == other.class && (respond_to?(:id) ? id == other.id : attributes == other.attributes) elsif other.respond_to?(:id) self.class.adapter.target.is_a?(Class) && other.is_a?(self.class.adapter.target) && id.to_s == other.id.to_s else false end end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/chewy/index/wrapper.rb, line 48 def method_missing(method, *args, &block) m = method.to_s if (name = highlight_name(m)) highlight(name) elsif (name = highlight_names(m)) highlights(name) elsif @attributes.key?(m) @attributes[m] elsif attribute_defined?(m) nil else super end end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/chewy/index/wrapper.rb, line 63 def respond_to_missing?(method, include_private = false) m = method.to_s highlight_name(m) || highlight_names(m) || @attributes.key?(m) || attribute_defined?(m) || super end
Private Instance Methods
attribute_defined?(attribute)
click to toggle source
# File lib/chewy/index/wrapper.rb, line 78 def attribute_defined?(attribute) self.class.root && self.class.root.children.find { |a| a.name.to_s == attribute }.present? end
highlight(attribute)
click to toggle source
# File lib/chewy/index/wrapper.rb, line 82 def highlight(attribute) _data['highlight'][attribute].first if highlight?(attribute) end
highlight?(attribute)
click to toggle source
# File lib/chewy/index/wrapper.rb, line 90 def highlight?(attribute) _data.key?('highlight') && _data['highlight'].key?(attribute) end
highlight_name(method)
click to toggle source
# File lib/chewy/index/wrapper.rb, line 70 def highlight_name(method) method.sub(/_highlight\z/, '') if method.end_with?('_highlight') end
highlight_names(method)
click to toggle source
# File lib/chewy/index/wrapper.rb, line 74 def highlight_names(method) method.sub(/_highlights\z/, '') if method.end_with?('_highlights') end
highlights(attribute)
click to toggle source
# File lib/chewy/index/wrapper.rb, line 86 def highlights(attribute) _data['highlight'][attribute] if highlight?(attribute) end