Module: Bushido::Models::ClassMethods

Defined in:
lib/bushido/models.rb

Instance Method Summary collapse

Instance Method Details

#bushido(model) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bushido/models.rb', line 43

def bushido model
  self.class_variable_set("@@bushi_model", model)

  [:create, :update, :destroy].each do |event|
    puts "Hooking into #{model}.#{event}..."

    Bushido::Data.listen("#{model}.#{event}") do |data, hook|
      puts "#{hook}.) Firing off #{model}.#{event} now with data: #{data}"
      self.send("on_bushido_#{event}".to_sym, self.from_bushido(data))
    end
  end
  
  before_save :bushido_save
end