Class: Bushido::Generators::HooksGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/bushido/hooks_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_hooks_fileObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/bushido/hooks_generator.rb', line 5

def create_hooks_file

  lib("bushido/hooks/user_hooks.rb") do
<<-EOF
class BushidoUserHooks < Bushido::EventObserver
  def user_added
    user.create(:email  => params['data']['email'],
:ido_id => params['data']['ido_id'],
:active => true)
  end

  def user_removed
    User.find_by_ido_id(params['data']['ido_id']).try(:disable!)
  end
end
EOF
  end
  
  lib('bushido/hooks/app_hooks.rb') do
<<-EOF
class BushidoAppHooks < Bushido::EventObserver
  def app_claimed
    User.find(1).update_attributes(:email  => params['data']['email'],
:ido_id => params['data']['ido_id'])
  end
end
EOF
  end
  
  initializer "bushido_hooks.rb" do
<<-EOF
Dir["\#{Dir.pwd}/lib/bushido/**/*.rb"].each { |file| require file }
EOF
  end
end