Class: Jets::Controller::Stage

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/controller/stage.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, url) ⇒ Stage

Returns a new instance of Stage.



3
4
5
# File 'lib/jets/controller/stage.rb', line 3

def initialize(host, url)
  @host, @url = host, url
end

Class Method Details

.add(host, url) ⇒ Object



25
26
27
# File 'lib/jets/controller/stage.rb', line 25

def add(host, url)
  new(host, url).add
end

.on_cloud9?(host) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/jets/controller/stage.rb', line 29

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

Instance Method Details

#addObject



7
8
9
10
11
12
13
# File 'lib/jets/controller/stage.rb', line 7

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

#add_stage?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/jets/controller/stage.rb', line 15

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

#on_cloud9?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/jets/controller/stage.rb', line 20

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