Top Level Namespace
Defined Under Namespace
Modules: ActiveSupport, Daddy, Differ
Classes: SqlBuilder
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.app_name ⇒ Object
13
14
15
|
# File 'lib/tasks/task_helper.rb', line 13
def self.app_name
YAML.load_file("#{rails_root}/config/database.yml")[rails_env]['database']
end
|
.ask(prompt, options = {}) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/tasks/task_helper.rb', line 44
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
|
.dry_run? ⇒ Boolean
21
22
23
24
25
26
27
|
# File 'lib/tasks/task_helper.rb', line 21
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
73
74
75
|
# File 'lib/tasks/task_helper.rb', line 73
def self.quiet?
ARGV.include?('--quiet') or ARGV.include?('-q')
end
|
.rails_env ⇒ Object
9
10
11
|
# File 'lib/tasks/task_helper.rb', line 9
def self.rails_env
ENV['RAILS_ENV'] || @_rails_env ||= ask('RAILS_ENV', :default => 'development')
end
|
.rails_root ⇒ Object
5
6
7
|
# File 'lib/tasks/task_helper.rb', line 5
def self.rails_root
ENV['RAILS_ROOT'] || @_rails_root ||= ask('RAILS_ROOT', :default => Rails.root)
end
|
.render(template, options = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/tasks/task_helper.rb', line 33
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)
end
text
end
|
.run(*commands) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/tasks/task_helper.rb', line 77
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
|
.task_file(*path) ⇒ Object
29
30
31
|
# File 'lib/tasks/task_helper.rb', line 29
def self.task_file(*path)
File.join(File.dirname(__FILE__), *path)
end
|
.template_dir ⇒ Object
17
18
19
|
# File 'lib/tasks/task_helper.rb', line 17
def self.template_dir
File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'templates')
end
|
Instance Method Details
#override_method(obj, method_name, &block) ⇒ Object
21
22
23
24
25
|
# File 'lib/daddy/cucumber.rb', line 21
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
|