Top Level Namespace
Defined Under Namespace
Modules: Daddy, Differ, Itamae
Classes: SqlBuilder
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.app_name ⇒ Object
22
23
24
|
# File 'lib/tasks/task_helper.rb', line 22
def self.app_name
ENV['APP_NAME'] || @_app_name ||= ask('APP_NAME', :default => File.basename(Dir.pwd))
end
|
.ask(prompt, options = {}) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/tasks/task_helper.rb', line 60
def self.ask(prompt, options = {})
if options[:default]
print prompt + " [#{options[:default]}]: "
else
print prompt + ": "
end
if options[:password]
system("stty -echo")
at_exit do
system("stty echo")
end
end
answer = STDIN.gets.strip
answer = options[:default] if answer.empty?
if options[:password]
system("stty echo")
puts
end
if options[:required] and answer.empty?
raise "必須です。処理を中止します。"
end
answer.empty? ? nil : answer
end
|
.cookbook_dir ⇒ Object
30
31
32
|
# File 'lib/tasks/task_helper.rb', line 30
def self.cookbook_dir
File.expand_path('../../../itamae/cookbooks', __FILE__)
end
|
.daddy_version ⇒ Object
10
11
12
|
# File 'lib/tasks/task_helper.rb', line 10
def self.daddy_version
Daddy::VERSION
end
|
.dry_run? ⇒ Boolean
34
35
36
37
38
39
40
|
# File 'lib/tasks/task_helper.rb', line 34
def self.dry_run?
%w{ DRY_RUN DR }.each do |key|
return true if %w{ true t yes y 1 }.include?(ENV[key].to_s.downcase)
end
false
end
|
.quiet? ⇒ Boolean
89
90
91
|
# File 'lib/tasks/task_helper.rb', line 89
def self.quiet?
ARGV.include?('--quiet') or ARGV.include?('-q')
end
|
.rails_env(options = {}) ⇒ Object
18
19
20
|
# File 'lib/tasks/task_helper.rb', line 18
def self.rails_env(options = {})
ENV['RAILS_ENV'] || @_rails_env ||= ask('RAILS_ENV', :default => options.fetch(:default, 'development'))
end
|
.rails_root ⇒ Object
14
15
16
|
# File 'lib/tasks/task_helper.rb', line 14
def self.rails_root
ENV['RAILS_ROOT'] || @_rails_root ||= ask('RAILS_ROOT', :default => Dir.pwd)
end
|
.render(template, options = {}) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/tasks/task_helper.rb', line 46
def self.render(template, options = {})
text = ERB.new(File.read(template), 0, '-').result
if options[:to]
FileUtils.mkdir_p(File.dirname(options[:to]))
File.write(options[:to], text)
ret = File.new(options[:to])
else
ret = text
end
ret
end
|
.run(*commands) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/tasks/task_helper.rb', line 93
def self.run(*commands)
options = commands.pop if commands.last.is_a?(Hash)
options ||= {}
commands.each do |c|
masked_command = options[:mask] ? c.gsub(*options[:mask]) : c
if dry_run?
puts "command to be run: #{masked_command}" unless quiet?
else
puts masked_command unless quiet?
fail unless system(c)
end
end
end
|
.run_itamae(*recipes) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/tasks/task_helper.rb', line 109
def self.run_itamae(*recipes)
options = []
options << '--ohai'
options << '--log-level=debug' if ENV['DEBUG']
recipe_files = []
recipes.each do |recipe|
recipe = "#{recipe}.rb" unless recipe.end_with?('.rb')
recipe_files << File.join(cookbook_dir, recipe)
end
run "bundle exec itamae local #{options.join(' ')} #{recipe_files.join(' ')}"
end
|
.task_file(*path) ⇒ Object
42
43
44
|
# File 'lib/tasks/task_helper.rb', line 42
def self.task_file(*path)
File.join(File.dirname(__FILE__), *path)
end
|
.template_dir ⇒ Object
26
27
28
|
# File 'lib/tasks/task_helper.rb', line 26
def self.template_dir
File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'templates')
end
|
Instance Method Details
#dad_env ⇒ Object
1
2
3
4
5
|
# File 'lib/daddy/itamae/env/dad_env.rb', line 1
def dad_env
ret = ENV['DAD_ENV']
ret ||= ENV['RAILS_ENV']
ret ||= 'development'
end
|
#os_version ⇒ Object
1
2
3
|
# File 'lib/daddy/itamae/env/os_version.rb', line 1
def os_version
"#{node.platform_family}-#{node.platform_version}"
end
|