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)
if @accessors_module.nil?
@accessors_module = Named::Module.new("SearchlightAccessors(#{self})") do
private
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
|