module FlameServerToys::Template::Base::CommonCode

Common code for toys

Private Instance Methods

development_restart() click to toggle source
# File lib/flame_server_toys/template/_base.rb, line 64
def development_restart
        spawn_development_filewatchers

        puma_command File.exist?(@config[:server][:puma_pid_file]) ? 'restart' : 'start'
end
puma_command(command) click to toggle source
# File lib/flame_server_toys/template/_base.rb, line 59
def puma_command(command)
        ## Don't use `bundle exec`: https://github.com/dazuma/toys/issues/65
        sh "pumactl #{command}"
end
server(command) click to toggle source
# File lib/flame_server_toys/template/_base.rb, line 41
def server(command)
        puts "Environment: #{@config[:environment]}"

        sh "#{context_directory}/exe/setup/ruby.sh"
        sh("#{context_directory}/exe/setup/node.sh") if %i[start restart].include?(command)

        web_server(command)
end
sh(command, print: true, exit_on_fail: true) click to toggle source
Calls superclass method
# File lib/flame_server_toys/template/_base.rb, line 27
def sh(command, print: true, exit_on_fail: true)
        options = {}
        options[:log_level] = Logger::UNKNOWN if print
        options[:exit_on_nonzero_status] = exit_on_fail
        super sh_command(command), **options
end
sh_command(command) click to toggle source
# File lib/flame_server_toys/template/_base.rb, line 34
def sh_command(command)
        require 'shellwords'

        escaped_command = Shellwords.escape(command)
        "sh -c #{escaped_command}"
end
spawn_development_filewatchers() click to toggle source
# File lib/flame_server_toys/template/_base.rb, line 70
def spawn_development_filewatchers
        require 'filewatcher/matrix'

        Thread.new do
                matrix = Filewatcher::Matrix.new("#{context_directory}/filewatchers.yaml")
                matrix.start
        end
end
waiting_mailing_lock() click to toggle source
# File lib/flame_server_toys/template/_base.rb, line 79
def waiting_mailing_lock
        while Dir[File.join(@config[:tmp_dir], 'mailing_*')].any?
                puts Paint['Mails sending in progress!', :bold, :red]
                puts 'Waiting...'
                sleep 1
        end
end
web_server(command) click to toggle source
# File lib/flame_server_toys/template/_base.rb, line 50
def web_server(command)
        if @config[:environment] == 'development' && %i[start restart].include?(command)
                return development_restart
        end

        waiting_mailing_lock if %i[stop restart phased-restart].include?(command)
        puma_command command
end