-
Notifications
You must be signed in to change notification settings - Fork 7
/
names.rb
78 lines (63 loc) · 1.68 KB
/
names.rb
1
2
3
4
5
6
7
8
9
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true
module Starter
module Names
def klass_name
for_klass = prepare_klass
singular? ? for_klass.classify : for_klass.classify.pluralize
end
def lib_klass_name
return klass_name unless @orm
case ::Starter::Config.read[:orm]
when 'sequel'
require 'starter/builder/templates/sequel'
extend(::Starter::Templates::Sequel)
"#{klass_name} < #{model_klass}"
when 'activerecord', 'ar'
require 'starter/builder/templates/activerecord'
extend(::Starter::Templates::ActiveRecord)
"#{klass_name} < #{model_klass}"
else
klass_name
end
end
def base_file_name
@resource.tr('/', '-').downcase + '.rb'
end
def base_spec_name
base_file_name.gsub(/.rb$/, '_spec.rb')
end
def mount_point
" mount Endpoints::#{klass_name}\n"
end
def api_base_file_name
File.join(Dir.getwd, 'api', 'base.rb')
end
# resource file
def api_file_name
File.join(Dir.getwd, 'api', 'endpoints', base_file_name)
end
# resource file
def entity_file_name
File.join(Dir.getwd, 'api', 'entities', base_file_name)
end
# lib file
def lib_file_name
File.join(Dir.getwd, 'lib', 'models', base_file_name)
end
# resource spec
def api_spec_name
File.join(Dir.getwd, 'spec', 'requests', base_spec_name)
end
# lib spec
def lib_spec_name
File.join(Dir.getwd, 'spec', 'lib', 'models', base_spec_name)
end
private
def prepare_klass
@resource.tr('-', '/')
end
def singular?
@resource.singularize.inspect == @resource.inspect
end
end
end