Class: DaemonKit::Generators::AppGenerator

Inherits:
Base show all
Defined in:
lib/generators/daemon_kit/app/app_generator.rb

Constant Summary collapse

INSTALLERS =
%w( default amqp cron nanite_agent ruote xmpp )
DEPLOYERS =
%w( capistrano )
TEST_FRAMEWORKS =
%w( none rspec test_unit )

Instance Attribute Summary

Attributes included from Thor::Actions

#behavior

Attributes included from Thor::Base

#options

Instance Method Summary collapse

Methods inherited from Base

desc

Methods included from Thor::Actions

#action, #append_file, #apply, #chmod, #copy_file, #create_file, #destination_root, #destination_root=, #directory, #empty_directory, #find_in_source_paths, #get, #gsub_file, #in_root, included, #inject_into_class, #inject_into_file, #inside, #prepend_file, #relative_to_original_destination_root, #remove_file, #run, #run_ruby_script, #source_paths, #template, #thor

Methods inherited from Thor::Group

class_options_help, desc, get_options_from_invocations, handle_argument_error, help, invocation_blocks, invocations, invoke, invoke_from_option, printable_tasks, remove_invocation, start

Methods included from Thor::Base

included, register_klass_file, shell, shell=, subclass_files, subclasses

Constructor Details

#initialize(*args) ⇒ AppGenerator

Returns a new instance of AppGenerator.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 23

def initialize( *args )
  super

  unless INSTALLERS.include?( options[:installer] )
    raise Error, "Invalid value for --installer option. Supported installers are: #{INSTALLERS.join(', ')}"
  end

  if options[:deployer] && !DEPLOYERS.include?( options[:deployer] )
    raise Error, "Invalid value for --deployer option. Supported deployers are: #{DEPLOYERS.join(', ')}"
  end

  unless TEST_FRAMEWORKS.include?( options[:test_framework] )
    raise Error, "Invalid value for --test_framework option. Supported frameworks are: #{TEST_FRAMEWORKS.join(', ')}"
  end
end

Instance Method Details

#create_bin_filesObject



51
52
53
54
55
56
57
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 51

def create_bin_files
  empty_directory 'bin'
  template 'bin/daemon.tt', "bin/#{app_name}" do |content|
    "#{shebang}\n" + content
  end
  chmod "bin", 0755, :verbose => false
end

#create_config_filesObject



59
60
61
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 59

def create_config_files
  directory 'config'
end

#create_cucumberObject



127
128
129
130
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 127

def create_cucumber
  return unless options.cucumber?
  invoke DaemonKit::Generators::CucumberGenerator
end

#create_deployment_configObject



107
108
109
110
111
112
113
114
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 107

def create_deployment_config
  return unless options[:deployer]

  case options[:deployer]
  when 'capistrano'
    invoke DaemonKit::Generators::CapistranoGenerator
  end
end

#create_lib_execObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 90

def create_lib_exec
  case options[:installer]
  when 'default'
    directory 'libexec'
  when 'amqp'
    invoke DaemonKit::Generators::AmqpGenerator
  when 'cron'
    invoke DaemonKit::Generators::CronGenerator
  when 'nanite_agent'
    invoke DaemonKit::Generators::NaniteAgentGenerator
  when 'ruote'
    invoke DaemonKit::Generators::RuoteGenerator
  when 'xmpp'
    invoke DaemonKit::Generators::XmppGenerator
  end
end

#create_lib_filesObject



86
87
88
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 86

def create_lib_files
  directory 'lib'
end

#create_log_directoryObject



74
75
76
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 74

def create_log_directory
  empty_directory 'log'
end

#create_rootObject



39
40
41
42
43
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 39

def create_root
  self.destination_root = File.expand_path( app_path, destination_root )
  empty_directory('.')
  FileUtils.cd( destination_root )
end

#create_root_filesObject



45
46
47
48
49
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 45

def create_root_files
  template 'README.tt', 'README'
  copy_file 'Rakefile'
  copy_file 'Gemfile'
end

#create_script_filesObject



63
64
65
66
67
68
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 63

def create_script_files
  directory 'script' do |content|
    "#{shebang}\n" + content
  end
  chmod 'script', 0755, :verbose => false
end

#create_task_directoryObject



70
71
72
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 70

def create_task_directory
  empty_directory 'tasks'
end

#create_test_environmentObject



116
117
118
119
120
121
122
123
124
125
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 116

def create_test_environment
  return if options[:test_framework] == 'none'

  case options[:test_framework]
  when 'rspec'
    invoke DaemonKit::Generators::SpecGenerator
  when 'test_unit'
    invoke DaemonKit::Generators::TestUnitGenerator
  end
end

#create_tmp_directoryObject



78
79
80
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 78

def create_tmp_directory
  empty_directory 'tmp'
end

#create_vendor_directoryObject



82
83
84
# File 'lib/generators/daemon_kit/app/app_generator.rb', line 82

def create_vendor_directory
  empty_directory 'vendor'
end