Module: Searchlight::DSL

Included in:
Search
Defined in:
lib/searchlight/dsl.rb

Instance Method Summary collapse

Instance Method Details

#search_on(target) ⇒ Object



4
5
6
# File 'lib/searchlight/dsl.rb', line 4

def search_on(target)
  @search_target = target
end

#searches(*attribute_names) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/searchlight/dsl.rb', line 8

def searches(*attribute_names)

  # Ensure this class only adds one accessors module to the ancestors chain
  if @accessors_module.nil?
    @accessors_module = Named::Module.new("SearchlightAccessors(#{self})") do
      private
      # Treat 0 (eg, from checkboxes) as false
      def truthy?(value)
        !(['0', 'false', ''].include?(value.to_s.strip))
      end
    end
    include @accessors_module
  end

  eval_string = "attr_accessor *#{attribute_names}\n"
  eval_string << attribute_names.map { |attribute_name|
    <<-LEPRECHAUN_JUICE
      def #{attribute_name}?
        truthy?(public_send("#{attribute_name}"))
      end
    LEPRECHAUN_JUICE
  }.join
  @accessors_module.module_eval(eval_string, __FILE__, __LINE__)
end