Top Level Namespace

Defined Under Namespace

Modules: ActiveSupport, Daddy, Differ Classes: SqlBuilder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.app_nameObject



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

Returns:

  • (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

.rails_envObject



9
10
11
# File 'lib/tasks/task_helper.rb', line 9

def self.rails_env
  ENV['RAILS_ENV'] || 'development'
end

.rails_rootObject



5
6
7
# File 'lib/tasks/task_helper.rb', line 5

def self.rails_root
  ENV['RAILS_ROOT'] || 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



73
74
75
76
77
78
79
80
# File 'lib/tasks/task_helper.rb', line 73

def self.run(*commands)
  return if dry_run?

  commands.each do |c|
    puts c
    fail unless system(c)
  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_dirObject



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



29
30
31
32
33
# File 'lib/daddy/cucumber.rb', line 29

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