class Sumcli::Commands::Add::Service

Constants

BIN_PATH
CONFIGS_PATH
DOCKER_FILE
TEMPLATES_PATH
WORKERS_PATH

Public Class Methods

new(name, version, options) click to toggle source
# File lib/sumcli/commands/add/service.rb, line 16
def initialize(name, version, options)
  @name = name.downcase
  @version = version
  @options = options
end

Public Instance Methods

add_postgres() click to toggle source
# File lib/sumcli/commands/add/service.rb, line 78
        def add_postgres
          ver = '10'
          response = ask_to_set(ver) if ver != @version && !@version.nil?
          ver = @version if response

          content = 
<<-TEXT
  db:
    image: 'postgres:#{ver}'
    ports:
      - '5432:5432'
TEXT

          generator.safe_inject_into_file DOCKER_FILE, content, after: "services:\n"
          copy_database_files
        end
add_rabbitmq() click to toggle source
# File lib/sumcli/commands/add/service.rb, line 95
        def add_rabbitmq
          ver = '3-management'
          response = ask_to_set(ver) if ver != @version && !@version.nil?
          ver = @version if response

          content = 
<<-TEXT
  rabbitmq:
    image: 'rabbitmq:#{ver}'
    ports:
      - '15672:15672'
      - '5672:5672'
TEXT

          generator.safe_inject_into_file DOCKER_FILE, content, after: "services:\n"
          copy_messaging_files
        end
ask_to_set(ver) click to toggle source
# File lib/sumcli/commands/add/service.rb, line 117
def ask_to_set(ver)
  prompt.yes?("The default version of #{@name} is #{ver}." + 
    "\n\nDo you want to add version #{@version}?")
end
copy_database_files() click to toggle source
# File lib/sumcli/commands/add/service.rb, line 32
        def copy_database_files
          generator.safe_inject_into_file('Gemfile', after: "# GEMS\n\n") do <<~RUBY
            gem 'pg', '~> 1.1'
            gem "otr-activerecord", '~> 1.3.0'
            RUBY
          end
          generator.copy_file("#{TEMPLATES_PATH}/database.yml", "#{CONFIGS_PATH}/database.yml")
          generator.copy_file("#{TEMPLATES_PATH}/database.yml.ctmpl", "#{CONFIGS_PATH}/database.yml.ctmpl")
          generator.copy_file("#{TEMPLATES_PATH}/database.rb", "#{CONFIGS_PATH}/initializers/database.rb")
          generator.safe_inject_into_file("#{CONFIGS_PATH}/application.rb", after: "require_rel '../api'\n") do
            'require_rel \'initializers\''
          end
          generator.safe_inject_into_file('Rakefile', after: "# TASKS\n") do <<~RUBY.strip
            load "tasks/otr-activerecord.rake"

            namespace :db do
              task :environment do
                require_relative 'config/environment'
              end
            end
            RUBY
          end
        end
copy_messaging_files() click to toggle source
# File lib/sumcli/commands/add/service.rb, line 56
        def copy_messaging_files
          generator.safe_inject_into_file('Gemfile', after: "# GEMS\n\n") do <<~RUBY
            gem 'sneakers', '~> 2.11'
            gem 'sneakers_handlers', '~> 0.0.6'
            RUBY
          end
          generator.copy_file("#{TEMPLATES_PATH}/rabbitmq.yml", "#{CONFIGS_PATH}/rabbitmq.yml")
          generator.copy_file("#{TEMPLATES_PATH}/rabbitmq.yml.ctmpl", "#{CONFIGS_PATH}/rabbitmq.yml.ctmpl")
          generator.copy_file("#{TEMPLATES_PATH}/sneakers.rb", "#{CONFIGS_PATH}/initializers/sneakers.rb")
          generator.safe_inject_into_file("#{CONFIGS_PATH}/application.rb", after: "require_rel '../api'\n") do
            'require_rel \'initializers\''
          end
          generator.copy_file("#{TEMPLATES_PATH}/sample_worker.rb", "#{WORKERS_PATH}/sample_worker.rb")

          generator.copy_file("#{TEMPLATES_PATH}/sneakers", "#{BIN_PATH}/sneakers")
          File.chmod(0744, 'bin/sneakers')
        end
execute(input: $stdin, output: $stdout) click to toggle source
# File lib/sumcli/commands/add/service.rb, line 22
def execute(input: $stdin, output: $stdout)
  if !service_exists?
    self.send("add_#{@name}")
    command.run("bundle install")
    output.puts "\n  #{@name} added to docker-compose"
  else
    output.puts "  #{@name} already added to docker-compose"
  end
end
require_exists?() click to toggle source
# File lib/sumcli/commands/add/service.rb, line 74
def require_exists?
  File.readlines(APPLICATION_FILE).grep(/#{INITIALIZERS_REQUIRE}/).any?
end
service_exists?() click to toggle source
# File lib/sumcli/commands/add/service.rb, line 113
def service_exists?
  File.readlines(DOCKER_FILE).grep(/#{@name}/).any?
end