class Sumcli::Commands::Add::Endpoint
Constants
- ENDPOINT_PATH
- ENTITIES_PATH
- MODELS_PATH
- TEMPLATES_PATH
- TESTS_PATH
Public Class Methods
new(name, method, route, options)
click to toggle source
# File lib/sumcli/commands/add/endpoint.rb, line 18 def initialize(name, method, route, options) @name = name @method = method @route = route @options = options @variables = OpenStruct.new(name: @name, route: @route, method: @method) end
Public Instance Methods
create_endpoint()
click to toggle source
# File lib/sumcli/commands/add/endpoint.rb, line 79 def create_endpoint generator.copy_file( "#{TEMPLATES_PATH}/new.rb.erb", "#{ENDPOINT_PATH}/#{@name.underscore}.rb", context: @variables ) inject_mount end
create_entity()
click to toggle source
# File lib/sumcli/commands/add/endpoint.rb, line 71 def create_entity generator.copy_file( "#{TEMPLATES_PATH}/entity.rb.erb", "#{ENTITIES_PATH}/#{@name.underscore}.rb", context: @variables ) end
create_model()
click to toggle source
# File lib/sumcli/commands/add/endpoint.rb, line 89 def create_model generator.copy_file( "#{TEMPLATES_PATH}/model.rb.erb", "#{MODELS_PATH}/#{@name.underscore}.rb", context: @variables ) end
create_test()
click to toggle source
# File lib/sumcli/commands/add/endpoint.rb, line 63 def create_test generator.copy_file( "#{TEMPLATES_PATH}/test.rb.erb", "#{TESTS_PATH}/#{@name.underscore}_spec.rb", context: @variables ) end
execute(input: $stdin, output: $stdout)
click to toggle source
# File lib/sumcli/commands/add/endpoint.rb, line 26 def execute(input: $stdin, output: $stdout) unless File.file?(".sumcli") pastel = Pastel.new output.puts pastel.red("ERROR!\nYou are no in a sumcli app directory.") output.puts <<-OUT.strip You can execute #{pastel.green('sumcli help new')} to get more info. OUT return end 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_mount()
click to toggle source
# File lib/sumcli/commands/add/endpoint.rb, line 42 def inject_mount generator.inject_into_file("#{ENDPOINT_PATH}/base.rb", after: "# APIs\n") do <<-RB mount API::#{@name.capitalize} RB end end
inject_route()
click to toggle source
# File lib/sumcli/commands/add/endpoint.rb, line 49 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