Top Level Namespace

Defined Under Namespace

Modules: RailsNew

Instance Method Summary collapse

Instance Method Details

#apply_template(file) ⇒ Object



20
21
22
23
24
# File 'lib/template.rb', line 20

def apply_template(file)
  template "#{File.dirname(__FILE__)}/files/#{file}.erb", file, force: true
  system "sed '/^$/N;/^\\n$/D' #{file} > sed_output" # remove duplicated empty lines
  system "mv sed_output #{file}"
end

#commit(description) ⇒ Object



26
27
28
29
30
# File 'lib/template.rb', line 26

def commit(description)
  system 'git add .'
  system 'git add --update .'
  system "git commit -am '#{description}'"
end

#database_adapterObject



32
33
34
35
36
37
38
39
# File 'lib/template.rb', line 32

def database_adapter
  case @database
  when 'postgresql', 'postgres', 'psql' then 'pg'
  when 'mysql'                          then 'mysql2'
  when 'sqlite'                         then 'sqlite3'
  else @database
  end
end

#database_encodingObject



48
49
50
51
52
53
# File 'lib/template.rb', line 48

def database_encoding
  case database_adapter
  when 'pg'     then 'unicode'
  when 'mysql2' then 'utf8'
  end
end

#database_yaml_adapterObject



41
42
43
44
45
46
# File 'lib/template.rb', line 41

def database_yaml_adapter
  case database_adapter
  when 'pg' then 'postgresql'
  else database_adapter
  end
end

#prompt(question, options) ⇒ Object



15
16
17
18
# File 'lib/template.rb', line 15

def prompt(question, options)
  answer = ask("     \e[1m\e[32mpromp".rjust(10) + "  \e[0m#{question} \e[33m[#{options[:default_answer]}]\e[0m").strip
  answer.present? ? answer : options[:default_answer]
end

#yes?(question) ⇒ Boolean

generate(:scaffold, “person name:string”) route “root to: ‘people#index’”

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
# File 'lib/template.rb', line 4

def yes?(question)
  return true unless @customized

  answer = ask "     \e[1m\e[32mpromp".rjust(10) + "  \e[0m#{question} \e[33m(y/n)\e[0m"
  case answer.downcase
  when 'yes', 'y' then true
  when 'no',  'n' then false
  else yes?(question)
  end
end