Module: OpenSearch::DSL::Search::BaseComponent::InstanceMethods
- Defined in:
- lib/opensearch/dsl/search/base_component.rb
Instance Method Summary collapse
-
#call ⇒ self
Evaluates any block passed to the query.
-
#empty? ⇒ Boolean
Return true when the component definition is empty.
-
#name ⇒ String
Return the name for instance of the DSL class.
-
#to_hash(_options = {}) ⇒ Hash
Convert the query definition to a Hash.
Instance Method Details
#call ⇒ self
Evaluates any block passed to the query
149 150 151 152 153 154 |
# File 'lib/opensearch/dsl/search/base_component.rb', line 149 def call if @block @block.arity < 1 ? instance_eval(&@block) : @block.call(self) end self end |
#empty? ⇒ Boolean
Return true when the component definition is empty
158 159 160 |
# File 'lib/opensearch/dsl/search/base_component.rb', line 158 def empty? to_hash[name].respond_to?(:empty?) && to_hash[name].empty? end |
#name ⇒ String
Return the name for instance of the DSL class
141 142 143 |
# File 'lib/opensearch/dsl/search/base_component.rb', line 141 def name self.class.name end |
#to_hash(_options = {}) ⇒ Hash
Convert the query definition to a Hash
A default implementation, DSL classes can overload it.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/opensearch/dsl/search/base_component.rb', line 168 def to_hash( = {}) # 1. Create hash from the block if @block @hash = @args && !@args.empty? ? { name => { @args => {} } } : { name => {} } call @hash[name.to_sym].update @options unless @options.empty? @hash # 2. Hash created with option methods elsif @hash[name.to_sym] && !@args.is_a?(Hash) && @hash[name.to_sym][@args] @hash[name.to_sym].update @options unless @options.empty? @hash # 3. Hash passsed as @args elsif @hash[name.to_sym] && @args.respond_to?(:to_hash) && !@args.empty? { name => @args.to_hash } # 4. Hash already built else @hash end end |