Sha256: 3e475ff3eecb68046e97e3713d0cded9ba13860944e598fc5d3ebd29a437beab

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

module Spontaneous::Publishing::Steps
  class GenerateRackupFile < BaseStep

    def call
      @progress.stage("create server config")
      File.open(config_path, "w:UTF-8") do |file|
        file.write(config)
      end
      @progress.step(count, config_path.inspect)
    end

    def count
      1
    end

    def rollback
      FileUtils.rm(config_path) if File.exists?(config_path)
    end

    def config_path
      (@site.revision_dir(revision) / "config.ru").tap do |path|
        dir = File.dirname(path)
        FileUtils.mkdir_p(dir) unless File.directory?(dir)
      end
    end

    def path
      @path ||= Pathname.new(@site.root).realpath.to_s
    end

    def config
      path = Pathname.new(Spontaneous.root).realpath.to_s
      rackup = "config/front.ru"

      template = (<<-RACKUP).gsub(/^ +/, '')
        # This is an automatically generated file *DO NOT EDIT*
        # To configure your Rack application make your changes in
        # '#{path}/#{rackup}'

        # Set the revision to display
        ENV["#{Spontaneous::SPOT_REVISION_NUMBER}"] = "#{revision}"
        ENV["#{Spontaneous::SPOT_ROOT}"] = "#{path}"

        # Change to the absolute path of our application and load the Rack config
        root = "#{path}"
        Dir.chdir(root)
        eval(::File.read("#{rackup}"), binding, ::File.join(root, "#{rackup}"), __LINE__)
      RACKUP
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/publishing/steps/generate_rackup_file.rb
spontaneous-0.2.0.beta9 lib/spontaneous/publishing/steps/generate_rackup_file.rb
spontaneous-0.2.0.beta8 lib/spontaneous/publishing/steps/generate_rackup_file.rb
spontaneous-0.2.0.beta7 lib/spontaneous/publishing/steps/generate_rackup_file.rb
spontaneous-0.2.0.beta6 lib/spontaneous/publishing/steps/generate_rackup_file.rb