Module: Elastictastic::Properties
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/elastictastic/properties.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #_routing ⇒ Object
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
- #elasticsearch_doc ⇒ Object
- #elasticsearch_doc=(doc) ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #inspect ⇒ Object
Instance Method Details
#_routing ⇒ Object
202 203 |
# File 'lib/elastictastic/properties.rb', line 202 def _routing end |
#attributes ⇒ Object
145 146 147 |
# File 'lib/elastictastic/properties.rb', line 145 def attributes super.merge(@_attributes).with_indifferent_access end |
#attributes=(attributes) ⇒ Object
149 150 151 152 153 |
# File 'lib/elastictastic/properties.rb', line 149 def attributes=(attributes) attributes.each_pair do |field, value| __send__(:"#{field}=", value) end end |
#elasticsearch_doc ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/elastictastic/properties.rb', line 165 def elasticsearch_doc {}.tap do |doc| @_attributes.each_pair do |field, value| next if value.nil? doc[field] = Util.call_or_map(value) do |item| serialize_value(field, item) end end @_embeds.each_pair do |field, | next if .nil? doc[field] = Util.call_or_map() do |item| item.elasticsearch_doc end end end end |
#elasticsearch_doc=(doc) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/elastictastic/properties.rb', line 182 def elasticsearch_doc=(doc) return if doc.nil? doc.each_pair do |field_name, value| if self.class.properties.has_key?(field_name) = self.class.[field_name] if = Util.call_or_map(value) do |item| .clazz.new.tap { |e| e.elasticsearch_doc = item } end (field_name, ) else deserialized = Util.call_or_map(value) do |item| deserialize_value(field_name, item) end write_attribute(field_name, deserialized) end end end end |
#initialize(attributes = {}) ⇒ Object
138 139 140 141 142 143 |
# File 'lib/elastictastic/properties.rb', line 138 def initialize(attributes = {}) super() @_attributes = {} @_embeds = {} self.attributes = attributes end |
#inspect ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/elastictastic/properties.rb', line 155 def inspect inspected = "#<#{self.class.name}" if attributes.any? inspected << ' ' << attributes.each_pair.map do |attr, value| "#{attr}: #{value.inspect}" end.join(', ') end inspected << '>' end |