Class: Sincli::Generators::Config
- Inherits:
-
Base
- Object
- Thor::Group
- Base
- Sincli::Generators::Config
show all
- Defined in:
- lib/sincli/generators/config.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #options
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#db_config ⇒ Object
29
30
31
32
33
34
|
# File 'lib/sincli/generators/config.rb', line 29
def db_config
return unless db = @options[:db]
@options[:adapter] = db == 'pg' ? 'postgresql' : db
template('database.yml.tt', 'config/database.yml')
end
|
#environment ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/sincli/generators/config.rb', line 42
def environment
copy_file('environment.rb', 'config/environment.rb')
@extensions = extensions.map do |e|
ext = e == 'json' ? e.upcase : e.camelize
"Sinatra::#{ext}"
end
template('application.rb.tt', 'config/application.rb')
end
|
#generate ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/sincli/generators/config.rb', line 4
def generate
Dir.mkdir('config')
sec_key
db_config
environment
puma_config
locales
end
|
#locales ⇒ Object
51
52
53
|
# File 'lib/sincli/generators/config.rb', line 51
def locales
directory('locales', 'config/locales')
end
|
#puma_config ⇒ Object
36
37
38
39
40
|
# File 'lib/sincli/generators/config.rb', line 36
def puma_config
return unless @options[:server] == 'puma'
copy_file('puma.rb', 'config/puma.rb')
end
|
#sec_key ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/sincli/generators/config.rb', line 18
def sec_key
begin
require 'securerandom'
sec_key = SecureRandom.hex(64)
rescue LoadError, NotImplementedError
sec_key = '%064x' % Kernel.rand(2**256 - 1)
end
create_file('config/.secret_key', sec_key)
end
|