Class: Chewy::Type

Inherits:
Object show all
Includes:
Search, Actions, Crutch, Import, Mapping, Observe, Witchcraft, Wrapper
Defined in:
lib/chewy/type.rb,
lib/chewy/type/crutch.rb,
lib/chewy/type/import.rb,
lib/chewy/type/actions.rb,
lib/chewy/type/mapping.rb,
lib/chewy/type/observe.rb,
lib/chewy/type/wrapper.rb,
lib/chewy/type/witchcraft.rb,
lib/chewy/type/adapter/orm.rb,
lib/chewy/type/adapter/base.rb,
lib/chewy/type/adapter/object.rb,
lib/chewy/type/adapter/sequel.rb,
lib/chewy/type/adapter/mongoid.rb,
lib/chewy/type/adapter/active_record.rb

Defined Under Namespace

Modules: Actions, Adapter, Crutch, Import, Mapping, Observe, Witchcraft, Wrapper

Constant Summary collapse

IMPORT_OPTIONS_KEYS =
[:batch_size, :bulk_size, :refresh, :consistency, :replication]

Constants included from Import

Import::BULK_OPTIONS

Instance Attribute Summary

Attributes included from Wrapper

#_data, #_object, #attributes

Class Method Summary collapse

Methods included from Observe::Helpers

#extract_callback_options!, #update_proc

Methods included from Wrapper

#==, #initialize, #method_missing, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chewy::Type::Wrapper

Class Method Details

.adapterObject

Current type adapter. Defined inside ‘Chewy.create_type`, derived from `Chewy::Index.define_type` arguments.

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/chewy/type.rb', line 41

def self.adapter
  raise NotImplementedError
end

.const_missing(name) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/chewy/type.rb', line 73

def self.const_missing(name)
  to_resolve = "#{self.to_s}::#{name}"
  to_resolve[index.to_s] = ''

  @__resolved_constants ||= {}

  if to_resolve.empty? || @__resolved_constants[to_resolve]
    super
  else
    @__resolved_constants[to_resolve] = true
    to_resolve.constantize
  end
rescue NotImplementedError
  super
end

.default_import_options(params) ⇒ Object



57
58
59
60
# File 'lib/chewy/type.rb', line 57

def self.default_import_options(params)
  params.assert_valid_keys(IMPORT_OPTIONS_KEYS)
  self._default_import_options = _default_import_options.merge(params)
end

.indexObject

Chewy index current type belongs to. Defined inside ‘Chewy.create_type`

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/chewy/type.rb', line 34

def self.index
  raise NotImplementedError
end

.method_missing(method, *args, &block) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/chewy/type.rb', line 62

def self.method_missing(method, *args, &block)
  if index.scopes.include?(method)
    define_singleton_method method do |*args, &block|
      all.scoping { index.public_send(method, *args, &block) }
    end
    send(method, *args, &block)
  else
    super
  end
end

.scopesObject

Returns list of public class methods defined in current type



53
54
55
# File 'lib/chewy/type.rb', line 53

def self.scopes
  public_methods - Chewy::Type.public_methods
end

.type_nameObject

Returns type name string



47
48
49
# File 'lib/chewy/type.rb', line 47

def self.type_name
  adapter.type_name
end