Module: Lycra::Document::Proxy::InstanceMethods
- Defined in:
- lib/lycra/document/proxy.rb
Instance Method Summary collapse
- #_indexed ⇒ Object
- #_indexed? ⇒ Boolean
- #as_indexed_json(options = {}) ⇒ Object
- #as_json(options = {}) ⇒ Object
- #index!(options = {}) ⇒ Object
- #indexed ⇒ Object
- #indexed? ⇒ Boolean
- #inspect ⇒ Object
- #reload ⇒ Object
- #update!(options = {}) ⇒ Object
- #update_attributes!(*attrs, **options) ⇒ Object
Instance Method Details
#_indexed ⇒ Object
306 307 308 |
# File 'lib/lycra/document/proxy.rb', line 306 def _indexed @indexed ||= self.class.search({query: {terms: {_id: [subject.id]}}}).results.first end |
#_indexed? ⇒ Boolean
318 319 320 |
# File 'lib/lycra/document/proxy.rb', line 318 def _indexed? !!@indexed end |
#as_indexed_json(options = {}) ⇒ Object
273 274 275 |
# File 'lib/lycra/document/proxy.rb', line 273 def as_indexed_json(={}) resolve!.as_json() end |
#as_json(options = {}) ⇒ Object
328 329 330 331 332 333 334 335 336 337 |
# File 'lib/lycra/document/proxy.rb', line 328 def as_json(={}) resolve! unless resolved? { index: self.class.index_name, document: self.class.document_type, subject: self.class.subject_type.name, resolved: resolved.map { |k,a| [k, a.as_json] }.to_h, indexed: indexed? && indexed.map { |k,a| [k, a.as_json] }.to_h } .as_json() end |
#index!(options = {}) ⇒ Object
277 278 279 280 281 282 |
# File 'lib/lycra/document/proxy.rb', line 277 def index!(={}) raise Lycra::AbstractClassError, "Cannot index using an abstract class" if abstract? @indexed = nil __lycra__.index_document() end |
#indexed ⇒ Object
310 311 312 |
# File 'lib/lycra/document/proxy.rb', line 310 def indexed _indexed&._source&.to_h end |
#indexed? ⇒ Boolean
314 315 316 |
# File 'lib/lycra/document/proxy.rb', line 314 def indexed? !!indexed end |
#inspect ⇒ Object
339 340 341 342 |
# File 'lib/lycra/document/proxy.rb', line 339 def inspect attr_str = "#{attributes.map { |key,attr| "#{key}: #{(resolved? && resolved[key].try(:to_json)) || (_indexed? && indexed[key.to_s].try(:to_json)) || (attr.nested? ? "[#{attr.type.type}]" : attr.type.type)}"}.join(', ')}>" "#<#{self.class.name} index: #{self.class.index_name}, document: #{self.class.document_type}, subject: #{self.class.subject_type}, #{attr_str}" end |
#reload ⇒ Object
322 323 324 325 326 |
# File 'lib/lycra/document/proxy.rb', line 322 def reload super if defined?(super) @indexed = nil self end |
#update!(options = {}) ⇒ Object
284 285 286 287 288 289 |
# File 'lib/lycra/document/proxy.rb', line 284 def update!(={}) raise Lycra::AbstractClassError, "Cannot update using an abstract class" if abstract? @indexed = nil __lycra__.update_document() end |
#update_attributes!(*attrs, **options) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/lycra/document/proxy.rb', line 291 def update_attributes!(*attrs, **) raise Lycra::AbstractClassError, "Cannot update using an abstract class" if abstract? if attrs.empty? document_attrs = resolve! else document_attrs = resolve!(only: attrs) end @indexed = nil __lycra__.update_document_attributes(document_attrs, ) rescue Elasticsearch::Transport::Transport::Errors::NotFound => e index!() end |