Sha256: aa5ca7e6df395536a979305da2edc1a5c92e7ad3947daf02d8d0f92b09b7a34b

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

require "bard/server"

module Bard
  class Config
    def initialize project_name, path: nil, source: nil
      @project_name = project_name
      @servers = {
        local: Server.new(
          project_name,
          :local,
          false,
          "./",
          ["#{project_name}.local"],
        ),
        gubs: Server.new(
          project_name,
          :gubs,
          "botandrose@cloud.hackett.world:22022",
          "Sites/#{project_name}",
          false,
        ),
        ci: Server.new(
          project_name,
          :ci,
          "jenkins@staging.botandrose.com:22022",
          "jobs/#{project_name}/workspace",
          false,
        ),
        staging: Server.new(
          project_name,
          :staging,
          "www@staging.botandrose.com:22022",
          project_name,
          ["#{project_name}.botandrose.com"],
        ),
      }
      if path && File.exist?(path)
        source = File.read(path)
      end
      if source
        instance_eval source
      end
    end

    attr_reader :project_name, :servers

    def server key, &block
      key = key.to_sym
      @servers[key] = Server.define(project_name, key, &block)
    end

    def [] key
      key = key.to_sym
      if @servers[key].nil? && key == :production
        key = :staging
      end
      @servers[key]
    end

    def data *paths
      if paths.length == 0
        Array(@data)
      else
        @data = paths
      end
    end

    def backup *args
      if args.length == 1
        @backup = args.first
      elsif args.length == 0
        return @backup if defined?(@backup)
        @backup = true
      else
        raise ArgumentError
      end
    end

    # short-hand for michael

    def github_pages url=nil
      server :production do
        github_pages true
        ssh false
        ping url
      end

      backup false
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bard-1.3.3 lib/bard/config.rb
bard-1.3.2 lib/bard/config.rb
bard-1.3.1 lib/bard/config.rb
bard-1.3.0 lib/bard/config.rb