Top Level Namespace
Defined Under Namespace
Modules: Daddy, Itamae
Classes: SqlBuilder
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.app_name ⇒ Object
37
38
39
|
# File 'lib/tasks/task_helper.rb', line 37
def self.app_name
ENV['APP_NAME'] || @_app_name ||= ask('APP_NAME', :default => File.basename(Dir.pwd))
end
|
.ask(prompt, options = {}) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/tasks/task_helper.rb', line 75
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.to_s.empty?
raise "必須です。処理を中止します。"
end
answer.to_s.empty? ? nil : answer
end
|
.ask_env(key, options = {}) ⇒ Object
104
105
106
107
108
|
# File 'lib/tasks/task_helper.rb', line 104
def self.ask_env(key, options = {})
answer = ask(key, options)
ENV[key] ||= answer if answer
answer
end
|
.cli ⇒ Object
15
16
17
|
# File 'lib/tasks/task_helper.rb', line 15
def self.cli
@_cli ||= HighLine.new
end
|
.cookbook_dir ⇒ Object
45
46
47
|
# File 'lib/tasks/task_helper.rb', line 45
def self.cookbook_dir
File.expand_path('../../../itamae/cookbooks', __FILE__)
end
|
.daddy_version ⇒ Object
11
12
13
|
# File 'lib/tasks/task_helper.rb', line 11
def self.daddy_version
Daddy::VERSION
end
|
.dry_run? ⇒ Boolean
49
50
51
52
53
54
55
|
# File 'lib/tasks/task_helper.rb', line 49
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
110
111
112
|
# File 'lib/tasks/task_helper.rb', line 110
def self.quiet?
ARGV.include?('--quiet') or ARGV.include?('-q')
end
|
.rails_env(options = {}) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/tasks/task_helper.rb', line 23
def self.rails_env(options = {})
ret = ENV['RAILS_ENV']
unless ret
cli.say('RAILS_ENV')
@_rails_env ||= cli.choose do ||
.choice 'production'
.choice 'development'
.choice 'test'
.prompt = 'select number above [2]'
.default = 'development'
end
end
end
|
.rails_root ⇒ Object
19
20
21
|
# File 'lib/tasks/task_helper.rb', line 19
def self.rails_root
ENV['RAILS_ROOT'] || @_rails_root ||= ask('RAILS_ROOT', :default => Dir.pwd)
end
|
.render(template, options = {}) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/tasks/task_helper.rb', line 61
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/tasks/task_helper.rb', line 114
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
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/tasks/task_helper.rb', line 130
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
57
58
59
|
# File 'lib/tasks/task_helper.rb', line 57
def self.task_file(*path)
File.join(File.dirname(__FILE__), *path)
end
|
.template_dir ⇒ Object
41
42
43
|
# File 'lib/tasks/task_helper.rb', line 41
def self.template_dir
File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'templates')
end
|
Instance Method Details
#app_name ⇒ Object
1
2
3
|
# File 'lib/daddy/itamae/env/app_name.rb', line 1
def app_name
ret = ENV['APP_NAME']
end
|
#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
|