Module: Ohm::LunarMacros

Defined in:
lib/ohm/contrib/lunar_macros.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/ohm/contrib/lunar_macros.rb', line 9

def self.included(base)
  base.send  :include, Ohm::Callbacks
  base.after :save,   :update_lunar_index
  base.after :delete, :delete_lunar_index

  base.extend ClassMethods
end

Instance Method Details

#update_lunar_indexObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ohm/contrib/lunar_macros.rb', line 34

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
      end
    end
  end
end