Class: Sumcli::Commands::G::Endpoint
Constant Summary
collapse
- ENDPOINT_PATH =
'api/endpoints'
- ENTITIES_PATH =
'api/entities'
- TESTS_PATH =
'spec/api'
Instance Method Summary
collapse
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(name, method, route, options) ⇒ Endpoint
Returns a new instance of Endpoint.
14
15
16
17
18
19
20
|
# File 'lib/sumcli/commands/g/endpoint.rb', line 14
def initialize(name, method, route, options)
@name = name
@method = method
@route = route
@options = options
@variables = OpenStruct.new(name: @name, route: @route, method: @method)
end
|
Instance Method Details
#create_endpoint ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/sumcli/commands/g/endpoint.rb', line 59
def create_endpoint
generator.copy_file(
'lib/sumcli/templates/g/endpoint/new.rb.erb',
"#{ENDPOINT_PATH}/#{@name.underscore}.rb",
context: @variables
)
end
|
#create_entity ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/sumcli/commands/g/endpoint.rb', line 51
def create_entity
generator.copy_file(
'lib/sumcli/templates/g/endpoint/entity.rb.erb',
"#{ENTITIES_PATH}/#{@name.underscore}.rb",
context: @variables
)
end
|
#create_test ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/sumcli/commands/g/endpoint.rb', line 43
def create_test
generator.copy_file(
'lib/sumcli/templates/g/endpoint/test.rb.erb',
"#{TESTS_PATH}/#{@name.underscore}_spec.rb",
context: @variables
)
end
|
#execute(input: $stdin, output: $stdout) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/sumcli/commands/g/endpoint.rb', line 22
def execute(input: $stdin, output: $stdout)
create_entity unless File.file?("#{ENTITIES_PATH}/#{@name.underscore}.rb")
create_test unless File.file?("#{TESTS_PATH}/#{@name.underscore}.rb")
create_endpoint unless File.file?("#{ENDPOINT_PATH}/#{@name.underscore}.rb")
inject_route unless @method.nil?
end
|
#inject_route ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/sumcli/commands/g/endpoint.rb', line 29
def inject_route
generator.inject_into_file("#{ENDPOINT_PATH}/#{@name.underscore}.rb", after: "# ENDPOINTS\n") do <<-RB
desc 'Describe your endpoint'
params do
# requires :id, type: Integer
end
#{@method.downcase} '#{@route}' do
# write code here..
end
RB
end
end
|