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/syncer.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/import/routine.rb,
lib/chewy/type/adapter/mongoid.rb,
lib/chewy/type/import/bulk_builder.rb,
lib/chewy/type/import/bulk_request.rb,
lib/chewy/type/adapter/active_record.rb,
lib/chewy/type/import/journal_builder.rb

Defined Under Namespace

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

Constant Summary collapse

IMPORT_OPTIONS_KEYS =
%i[batch_size bulk_size refresh consistency replication raw_import journal].freeze

Constants included from Import

Import::IMPORT_WORKER, Import::LEFTOVERS_WORKER

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)

43
44
45
# File 'lib/chewy/type.rb', line 43

def adapter
  raise NotImplementedError
end

.const_missing(name) ⇒ Object


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/chewy/type.rb', line 100

def const_missing(name)
  to_resolve = "#{self}::#{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


80
81
82
83
# File 'lib/chewy/type.rb', line 80

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

.derivable_nameString?

Appends type name to Index.derivable_name

Examples:

class Namespace::UsersIndex < Chewy::Index
  define_type User
end
UsersIndex::User.derivable_name # => 'namespace/users#user'

Returns:

  • (String, nil)

    derivable name or nil when it is impossible to calculate

See Also:


63
64
65
# File 'lib/chewy/type.rb', line 63

def derivable_name
  @derivable_name ||= [index.derivable_name, type_name].join('#') if index && index.derivable_name
end

.indexObject

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

Raises:

  • (NotImplementedError)

36
37
38
# File 'lib/chewy/type.rb', line 36

def index
  raise NotImplementedError, 'Looks like this type ws defined outside the index scope and `.index` method is undefined for it'
end

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


85
86
87
88
89
90
91
92
93
94
# File 'lib/chewy/type.rb', line 85

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

.respond_to_missing?(method, _) ⇒ Boolean

Returns:

  • (Boolean)

96
97
98
# File 'lib/chewy/type.rb', line 96

def respond_to_missing?(method, _)
  index.scopes.include?(method) || super
end

.scopesObject

Returns list of public class methods defined in current type


76
77
78
# File 'lib/chewy/type.rb', line 76

def scopes
  public_methods - Chewy::Type.public_methods
end

.type_nameObject

Returns type name string


49
50
51
# File 'lib/chewy/type.rb', line 49

def type_name
  adapter.type_name
end

.typesChewy::Type

This method is an API shared with Index, added for convenience.

Returns:


70
71
72
# File 'lib/chewy/type.rb', line 70

def types
  [self]
end