Class: ActsAsApprovableGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActsAsApprovable::Generators::Base
Defined in:
lib/generators/acts_as_approvable/acts_as_approvable_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_routesObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/generators/acts_as_approvable/acts_as_approvable_generator.rb', line 51

def add_routes
  resource = []
  resource << 'resources :approvals, :only => [:index] do'
  resource << '    collection do'
  resource << '      get \'index\''
  resource << '      get \'history\''
  resource << '      get \'mine\'' if owner?
  resource << '    end'
  resource << '    member do'
  resource << '      post \'approve\''
  resource << '      post \'reject\''
  resource << '      post \'assign\'' if owner?
  resource << '    end'
  resource << '  end'

  route(resource.join("\n"))
end

#check_class_collisionsObject



16
17
18
# File 'lib/generators/acts_as_approvable/acts_as_approvable_generator.rb', line 16

def check_class_collisions
  class_collisions '', 'ApprovalsController'
end

#create_controller_fileObject



20
21
22
# File 'lib/generators/acts_as_approvable/acts_as_approvable_generator.rb', line 20

def create_controller_file
  template 'approvals_controller.rb', File.join('app/controllers', 'approvals_controller.rb')
end

#create_initializer_fileObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/acts_as_approvable/acts_as_approvable_generator.rb', line 29

def create_initializer_file
  initializer('acts_as_approvable.rb') do
    data = ''

    if owner?
      data << 'ActsAsApprovable::Ownership.configure'
      data << "(:owner => #{owner})" if owner != 'User'
    end

    data << "\n"
  end
end

#create_migration_fileObject



24
25
26
27
# File 'lib/generators/acts_as_approvable/acts_as_approvable_generator.rb', line 24

def create_migration_file
  number = ActiveRecord::Generators::Base.next_migration_number('db/migrate')
  template 'create_approvals.rb', "db/migrate/#{number}_create_approvals.rb"
end

#create_script_filesObject



42
43
44
45
46
47
# File 'lib/generators/acts_as_approvable/acts_as_approvable_generator.rb', line 42

def create_script_files
  return unless scripts?

  template 'jquery.form.js', 'public/javascripts/jquery.form.js'
  template 'approvals.js', 'public/javascripts/approvals.js'
end