Class: Caoutsearch::Search::DSL::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/caoutsearch/search/dsl/item.rb

Constant Summary collapse

PROPERTIES_TO_INSPECT =
i[name options block].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Item

Returns a new instance of Item.



11
12
13
14
15
# File 'lib/caoutsearch/search/dsl/item.rb', line 11

def initialize(name, options = {}, &block)
  @name = name
  @options = options
  @block = block if block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



7
8
9
# File 'lib/caoutsearch/search/dsl/item.rb', line 7

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/caoutsearch/search/dsl/item.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/caoutsearch/search/dsl/item.rb', line 7

def options
  @options
end

Instance Method Details

#has_block?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/caoutsearch/search/dsl/item.rb', line 17

def has_block?
  block.present?
end

#indexesObject



21
22
23
# File 'lib/caoutsearch/search/dsl/item.rb', line 21

def indexes
  @indexes ||= Array.wrap(options[:indexes].presence || name)
end

#inspectObject



25
26
27
28
29
# File 'lib/caoutsearch/search/dsl/item.rb', line 25

def inspect
  properties = properties_to_inspect.map { |k, v| " #{k}: #{v}" }

  "#<#{self.class}#{properties.join(",")}>"
end