Module: Elastictastic::Properties::InstanceMethods
- Defined in:
- lib/elastictastic/properties.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
- #elasticsearch_doc ⇒ Object
- #elasticsearch_doc=(doc) ⇒ Object
- #initialize(attributes = {}) ⇒ Object
Instance Method Details
#attributes ⇒ Object
125 126 127 |
# File 'lib/elastictastic/properties.rb', line 125 def attributes @attributes.with_indifferent_access end |
#attributes=(attributes) ⇒ Object
129 130 131 132 133 |
# File 'lib/elastictastic/properties.rb', line 129 def attributes=(attributes) attributes.each_pair do |field, value| __send__(:"#{field}=", value) end end |
#elasticsearch_doc ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/elastictastic/properties.rb', line 135 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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/elastictastic/properties.rb', line 152 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
118 119 120 121 122 123 |
# File 'lib/elastictastic/properties.rb', line 118 def initialize(attributes = {}) super @attributes = {} @embeds = {} self.attributes = attributes end |