Class: SearchableBy::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/searchable_by/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



6
7
8
9
10
11
12
# File 'lib/searchable_by/config.rb', line 6

def initialize
  @columns = []
  @max_terms = 5
  @min_length = 0
  @options = {}
  scope { all }
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



3
4
5
# File 'lib/searchable_by/config.rb', line 3

def columns
  @columns
end

#max_termsObject

Returns the value of attribute max_terms.



4
5
6
# File 'lib/searchable_by/config.rb', line 4

def max_terms
  @max_terms
end

#min_lengthObject

Returns the value of attribute min_length.



4
5
6
# File 'lib/searchable_by/config.rb', line 4

def min_length
  @min_length
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/searchable_by/config.rb', line 3

def options
  @options
end

#scopingObject (readonly)

Returns the value of attribute scoping.



3
4
5
# File 'lib/searchable_by/config.rb', line 3

def scoping
  @scoping
end

Instance Method Details

#column(*attrs, &block) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/searchable_by/config.rb', line 26

def column(*attrs, &block)
  opts = attrs.extract_options!
  attrs.each do |attr|
    columns.push Column.new(attr, **@options, **opts)
  end
  columns.push Column.new(block, **@options, **opts) if block
  columns
end

#configure(max_terms, min_length, **options, &block) ⇒ Object



14
15
16
17
18
19
# File 'lib/searchable_by/config.rb', line 14

def configure(max_terms, min_length, **options, &block)
  instance_eval(&block)
  self.max_terms = max_terms if max_terms
  self.min_length = min_length
  self.options.update(options) unless options.empty?
end

#initialize_copy(other) ⇒ Object



21
22
23
24
# File 'lib/searchable_by/config.rb', line 21

def initialize_copy(other)
  @columns = other.columns.dup
  super
end

#scope(&block) ⇒ Object



35
36
37
# File 'lib/searchable_by/config.rb', line 35

def scope(&block)
  @scoping = block
end