10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/hanami/sequel/commands/model.rb', line 10
def call(name:, **options)
under_name = Utils::String.underscore(name)
table_name = Utils::String.pluralize(under_name)
camel_name = Utils::String.classify(name)
model_name = "#{camel_name}Model"
b = ErBinding.new(model_name: model_name,
table_name: table_name)
now = Time.now.strftime('%Y%m%d%H%M%S')
destination = File.join(CLI.config.migrations,
"#{now}_create_#{table_name}.rb")
CLI.generate(CLI.template('model-migration'), b, destination)
destination = File.join(CLI.lib_path,
'models',
"/#{under_name}_model.rb")
CLI.generate(CLI.template('model-sequel'), b, destination)
destination = File.join(CLI.spec_path,
'models',
"/#{under_name}_model_spec.rb")
model_spec = "model-spec-#{CLI.hanamirc_test}"
CLI.generate(CLI.template(model_spec), b, destination)
dest_helper = 'spec/models_helper.rb'
if File.exist?(dest_helper)
CLI.log_file_handling('skip', dest_helper)
else
model_helper = "models-helper-#{CLI.hanamirc_test}"
CLI.generate(CLI.template(model_helper), nil, dest_helper)
CLI.log_file_handling('create', dest_helper)
end
end
|