module Dilute::Modelize::ClassMethods

Public Instance Methods

add_attribute_accessors() click to toggle source
# File lib/dilute/modelize.rb, line 60
def add_attribute_accessors
  type.properties.keys.each do |k|
    define_method k do
      attributes["_source"] && attributes["_source"][k]
    end
    define_method "#{k}=" do |new_var|
      attributes["_source"] && attributes["_source"][k] = new_var
    end
  end
end
all(query = {}, page_size = 10) click to toggle source
# File lib/dilute/modelize.rb, line 33
def all(query = {}, page_size = 10)

  # search_results = type.search(size: page_size, query: {match_all: {}})
  # search_results.raw["hits"]["hits"].collect {|r| new(r) }
  Dilute::Query.new(self)
end
application_name() click to toggle source
# File lib/dilute/modelize.rb, line 45
def application_name
  if Kernel.const_defined? :Rails
    Rails.application.class.parent_name
  else
    "DefaultDiluteIndexName"
  end
end
define_type(options = {}, &blk) click to toggle source
# File lib/dilute/modelize.rb, line 40
def define_type(options = {}, &blk)
  @type ||= Dilute::Type.new(type_defaults.merge(options), &blk)
  add_attribute_accessors
end
find(id) click to toggle source
# File lib/dilute/modelize.rb, line 29
def find(id)
  new(type.get(id, {}, true))
end
name() click to toggle source
Calls superclass method
# File lib/dilute/modelize.rb, line 25
def name
  super || "DefaultDilutedModel"
end
refresh() click to toggle source
# File lib/dilute/modelize.rb, line 21
def refresh
  type.server.refresh
end
type() click to toggle source
# File lib/dilute/modelize.rb, line 71
def type
  @type or raise "No type defined!"
end
type_defaults() click to toggle source
# File lib/dilute/modelize.rb, line 53
def type_defaults
  HashWithIndifferentAccess.new({
    index_name: application_name,
    type_name: model_name.plural
  })
end