lib/ohm/contrib/lunar_macros.rb in ohm-contrib-0.0.31 vs lib/ohm/contrib/lunar_macros.rb in ohm-contrib-0.0.33

- old
+ new

@@ -17,30 +17,30 @@ module ClassMethods def fuzzy(*atts) lunar_fields(:fuzzy, *atts) end def text(*atts) lunar_fields(:text, *atts) end def number(*atts) lunar_fields(:number, *atts) end def sortable(*atts) lunar_fields(:sortable, *atts) end - + def lunar_fields(type, *atts) @lunar_fields ||= Hash.new { |h, k| h[k] = [] } - atts.each { |att| + atts.each { |att| @lunar_fields[type] << att unless @lunar_fields[type].include?(att) } @lunar_fields[type] end end def update_lunar_index Lunar.index self.class do |i| i.id id - + [:fuzzy, :text, :number, :sortable].each do |type| self.class.lunar_fields(type).each do |field| value = send(field) - + if type == :text and value.kind_of?(Enumerable) i.text field, value.join(' ') unless value.empty? else i.send type, field, value unless value.to_s.empty? end @@ -53,5 +53,6 @@ def delete_lunar_index Lunar.delete self.class, id end end end +