Class: Cloudfuji::Generators::HooksGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/cloudfuji/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/cloudfuji/hooks_generator.rb', line 5

def create_hooks_file

  lib("cloudfuji/hooks/user_hooks.rb") do
<<-EOF
class CloudfujiUserHooks < Cloudfuji::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('cloudfuji/hooks/app_hooks.rb') do
<<-EOF
class CloudfujiAppHooks < Cloudfuji::EventObserver
  def app_claimed
    User.find(1).update_attributes(:email  => params['data']['email'],
:ido_id => params['data']['ido_id'])
  end
end
EOF
  end
  
  initializer "cloudfuji_hooks.rb" do
<<-EOF
Dir["\#{Dir.pwd}/lib/cloudfuji/**/*.rb"].each { |file| require file }
EOF
  end
end