Module: Elasticsearch::DSL::Search::BaseComponent::ClassMethods

Defined in:
lib/elasticsearch/dsl/search/base_component.rb

Instance Method Summary collapse

Instance Method Details

#name(value = nil) ⇒ Object

Get or set the name for the DSL class

Examples:

Set the index name for the ‘Article` model and re-evaluate it on each call


class MyQuery
  include BaseComponent
  name :my_special_query
end

MyQuery.name
# => :my_special_query


90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/elasticsearch/dsl/search/base_component.rb', line 90

def name(value=nil)
  if value
    @name = value.to_sym
  else
    @name ||= begin
      value = self.to_s.split('::').last
      value.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
      value.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
      value.tr!("-", "_")
      value.downcase!
      value.to_sym
    end
  end
end

#name=(value) ⇒ Object

Set the name for the DSL class



107
108
109
# File 'lib/elasticsearch/dsl/search/base_component.rb', line 107

def name=(value)
  @name = value.to_sym
end

#option_methodsObject



111
112
113
# File 'lib/elasticsearch/dsl/search/base_component.rb', line 111

def option_methods
  @option_methods ||= []
end