Class: DeisInteractive::Rails::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/deis-interactive/rails/base.rb

Direct Known Subclasses

Console, Exec, Logs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, process) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
# File 'lib/deis-interactive/rails/base.rb', line 6

def initialize(app, process)
  @app = app || inferred_app
  @process = process
  if @app.nil?
    puts "App name can't be inferred. Please pass the app name with -a APP"
    exit 1
  end
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



4
5
6
# File 'lib/deis-interactive/rails/base.rb', line 4

def app
  @app
end

#processObject (readonly)

Returns the value of attribute process.



4
5
6
# File 'lib/deis-interactive/rails/base.rb', line 4

def process
  @process
end

Instance Method Details

#deis_remoteObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/deis-interactive/rails/base.rb', line 35

def deis_remote
  remotes = git_remote_response.split("\n")
  remotes.each do |remote|
    name, url, type = remote.split(" ")
    if name == "deis"
      return url
    end
  end

  nil
end

#git_remote_responseObject



31
32
33
# File 'lib/deis-interactive/rails/base.rb', line 31

def git_remote_response
  `git remote -v`
end

#inferred_appObject



47
48
49
50
51
# File 'lib/deis-interactive/rails/base.rb', line 47

def inferred_app
  url = deis_remote
  return nil if url.nil?
  url.split("/").last.gsub(".git", "")
end

#pod_idsObject



21
22
23
24
25
26
27
28
29
# File 'lib/deis-interactive/rails/base.rb', line 21

def pod_ids
  @pod_ids ||= (
    puts "Fetching pod ids..."
    output= `kubectl get pods --namespace #{app} -o name | grep #{processes_pattern}`
    output.split("\n").reject(&:empty?).map do |str|
      str.split("/").last
    end
  )
end

#processes_patternObject



15
16
17
18
19
# File 'lib/deis-interactive/rails/base.rb', line 15

def processes_pattern
  patterns = [app]
  patterns << process if process
  patterns.join("-")
end