Sha256: 8d207541b0f3c8bd1130483194cefeff1e85bd769bf3db19c92ab31de005dbeb

Contents?: true

Size: 1.78 KB

Versions: 16

Compression:

Stored size: 1.78 KB

Contents

require 'thor'
require 'thor/group'

module Utter
  module Generators
    # Usage
    # generator = Utter::Generators::Microservice.new
    # generator.destination_root = path #optional, will use current directory by default
    # generator.invoke_all
    class Microservice < Thor::Group
      include Thor::Actions

      desc 'Generate an utter microservice directory structure'
      def create_microservice params={}
	path 		= params[:path]
	module_name 	= params[:module_name]
	api_version 	= params[:api_version]
	service_name 	= params[:service_name]

	empty_directory "#{path}/microservice"
	empty_directory "#{path}/microservice/lib"
	empty_directory "#{path}/microservice/lib/internals"
	# microservice/lib/main.rb 
	create_file  	"#{path}/microservice/lib/main.rb"
	@file = <<-FOO
require 'utter'
require 'json'
Dir[File.dirname(__FILE__) + '/**/*.rb'].each {|file| require_relative file }
module #{module_name.capitalize}
  module #{api_version.capitalize}
    class #{service_name.capitalize} < Utter::Microservice 
      \$log.info("mounting \#{self}")
      get '/' do
	domain_stack = Utter::Stack.new do  
	  #use MyDomainExtension, "data message"
	end
        \$log.info(domain_stack.to_s)
	{"status": "running"}.to_json
      end 
      #run! if app_file == $0
    end 
  end 
end
	FOO
	append_to_file "#{path}/microservice/lib/main.rb", @file

	# end of microservice/lib/main.rb 

	empty_directory "#{path}/microservice/spec"
	create_file 	"#{path}/microservice/spec/main_spec.rb"
	create_file 	"#{path}/microservice/spec/spec_helper.rb"

	# microservice/README.md
	create_file 	"#{path}/microservice/README.md"
	@file = <<-FOO
# describe how to use the microservice here
	FOO

	append_to_file "#{path}/microservice/README.md", @file

	# end of microservice/README.md 

      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
utter-1.9.0 lib/generators/service_gem_generator.rb
utter-1.8.0 lib/generators/service_gem_generator.rb
utter-1.7.0 lib/generators/service_gem_generator.rb
utter-1.6.0 lib/generators/service_gem_generator.rb
utter-1.5.0 lib/generators/service_gem_generator.rb
utter-1.4.0 lib/generators/service_gem_generator.rb
utter-1.3.2 lib/generators/service_gem_generator.rb
utter-1.3.1 lib/generators/service_gem_generator.rb
utter-1.3.0 lib/generators/service_gem_generator.rb
utter-1.2.0 lib/generators/service_gem_generator.rb
utter-1.1.0 lib/generators/service_gem_generator.rb
utter-1.0.23 lib/generators/service_gem_generator.rb
utter-1.0.21 bin/generators/microservice.rb
utter-1.0.20 bin/generators/microservice.rb
utter-1.0.19 bin/generators/microservice.rb
utter-1.0.18 bin/generators/microservice.rb