Module: OpenSearch::DSL::Search::BaseComponent::ClassMethods

Defined in:
lib/opensearch/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


110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/opensearch/dsl/search/base_component.rb', line 110

def name(value = nil)
  if value
    @name = value.to_sym
  else
    @name ||= begin
      value = 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



127
128
129
# File 'lib/opensearch/dsl/search/base_component.rb', line 127

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

#option_methodsObject



131
132
133
# File 'lib/opensearch/dsl/search/base_component.rb', line 131

def option_methods
  @option_methods ||= []
end