Sha256: eabecd65ed7bad3fbf6301a15fab1360aadd66f0d80cf0abf1128945fab5badf

Contents?: true

Size: 826 Bytes

Versions: 87

Compression:

Stored size: 826 Bytes

Contents

class Jets::Controller
  class Stage
    def initialize(host, url)
      @host, @url = host, url
    end

    def add
      return @url unless add_stage?

      stage_name = Jets::Resource::ApiGateway::Deployment.stage_name
      stage_name_with_slashes = "/#{stage_name}/" # use to prevent stage name being added twice if url_for is called twice on the same string
      @url.include?(stage_name_with_slashes) ? @url : "/#{stage_name}#{@url}"
    end

    def add_stage?
      return false if on_cloud9?
      @host.include?("amazonaws.com") && @url.starts_with?('/')
    end

    def on_cloud9?
      self.class.on_cloud9?(@host)
    end

    class << self
      def add(host, url)
        new(host, url).add
      end

      def on_cloud9?(host)
        !!(host =~ /cloud9\..*\.amazonaws\.com/)
      end
    end
  end
end

Version data entries

87 entries across 87 versions & 2 rubygems

Version Path
jets-2.1.0 lib/jets/controller/stage.rb
jets-2.0.6 lib/jets/controller/stage.rb
jets-2.0.5 lib/jets/controller/stage.rb
jets-2.0.4 lib/jets/controller/stage.rb
jets-2.0.3 lib/jets/controller/stage.rb
jets-2.0.1 lib/jets/controller/stage.rb
jets-2.0.0 lib/jets/controller/stage.rb