Top Level Namespace
Defined Under Namespace
Modules: ActiveSupport, Daddy, Differ, Itamae
Classes: SqlBuilder
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.app_name ⇒ Object
21
22
23
|
# File 'lib/tasks/task_helper.rb', line 21
def self.app_name
YAML.load_file("#{rails_root}/config/database.yml")[rails_env]['database']
end
|
.ask(prompt, options = {}) ⇒ Object
59
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
|
# File 'lib/tasks/task_helper.rb', line 59
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.blank?
if options[:password]
system("stty echo")
puts
end
if options[:required] and answer.blank?
raise "必須です。処理を中止します。"
end
answer.blank? ? nil : answer
end
|
.cookbook_dir ⇒ Object
29
30
31
|
# File 'lib/tasks/task_helper.rb', line 29
def self.cookbook_dir
File.expand_path('../../../itamae/cookbooks', __FILE__)
end
|
.daddy_version ⇒ Object
9
10
11
|
# File 'lib/tasks/task_helper.rb', line 9
def self.daddy_version
Daddy::VERSION
end
|
.dry_run? ⇒ Boolean
33
34
35
36
37
38
39
|
# File 'lib/tasks/task_helper.rb', line 33
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
88
89
90
|
# File 'lib/tasks/task_helper.rb', line 88
def self.quiet?
ARGV.include?('--quiet') or ARGV.include?('-q')
end
|
.rails_env(options = {}) ⇒ Object
17
18
19
|
# File 'lib/tasks/task_helper.rb', line 17
def self.rails_env(options = {})
ENV['RAILS_ENV'] || @_rails_env ||= ask('RAILS_ENV', :default => options.fetch(:default, 'development'))
end
|
.rails_root ⇒ Object
13
14
15
|
# File 'lib/tasks/task_helper.rb', line 13
def self.rails_root
ENV['RAILS_ROOT'] || @_rails_root ||= ask('RAILS_ROOT', :default => Rails.root)
end
|
.render(template, options = {}) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/tasks/task_helper.rb', line 45
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/tasks/task_helper.rb', line 92
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
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/tasks/task_helper.rb', line 108
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
41
42
43
|
# File 'lib/tasks/task_helper.rb', line 41
def self.task_file(*path)
File.join(File.dirname(__FILE__), *path)
end
|
.template_dir ⇒ Object
25
26
27
|
# File 'lib/tasks/task_helper.rb', line 25
def self.template_dir
File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'templates')
end
|
Instance Method Details
#os_version ⇒ Object
1
2
3
|
# File 'lib/daddy/itamae/os_version.rb', line 1
def os_version
@_os_version ||= "#{node[:platform_family]}-#{node[:platform_version]}"
end
|
#override_method(obj, method_name, &block) ⇒ Object
13
14
15
16
17
|
# File 'lib/daddy/cucumber.rb', line 13
def override_method(obj, method_name, &block)
klass = class <<obj; self; end
klass.send(:undef_method, method_name)
klass.send(:define_method, method_name, block)
end
|