Class: Procodile::AppDetermination

Inherits:
Object
  • Object
show all
Defined in:
lib/procodile/app_determination.rb

Overview

This class is responsible for determining which application should be sued

Instance Method Summary collapse

Constructor Details

#initialize(pwd, given_root, given_procfile, global_options = {}) ⇒ AppDetermination

Start by creating an determination ased on the root and procfile that has been provided to us by the user (from –root and/or –procfile)



10
11
12
13
14
15
16
# File 'lib/procodile/app_determination.rb', line 10

def initialize(pwd, given_root, given_procfile, global_options = {})
  @pwd = pwd
  @given_root = given_root ? File.expand_path(given_root, pwd) : nil
  @given_procfile = given_procfile
  @global_options = global_options
  calculate
end

Instance Method Details

#ambiguous?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/procodile/app_determination.rb', line 38

def ambiguous?
  !unambiguous?
end

#app_optionsObject

Return an hash of possible options to settle the ambiguity



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/procodile/app_determination.rb', line 49

def app_options
  if ambiguous?
    hash = {}
    @global_options.each_with_index do |option, i|
      hash[i] = option['name'] || option['root']
    end
    hash
  else
    {}
  end
end

#in_app_directory?Boolean

Are we in an app’s directory?

Returns:

  • (Boolean)


29
30
31
# File 'lib/procodile/app_determination.rb', line 29

def in_app_directory?
  @in_app_directory == true
end

#procfileObject

Return the procfile



24
25
26
# File 'lib/procodile/app_determination.rb', line 24

def procfile
  @procfile
end

#rootObject

Return the root directory



19
20
21
# File 'lib/procodile/app_determination.rb', line 19

def root
  @root
end

#set_app(id) ⇒ Object

Choose which of the ambiguous options we want to choose



43
44
45
46
# File 'lib/procodile/app_determination.rb', line 43

def set_app(id)
  @app_id = id
  find_root_and_procfile_from_options(@global_options)
end

#unambiguous?Boolean

If we have a root and procfile, we’re all good

Returns:

  • (Boolean)


34
35
36
# File 'lib/procodile/app_determination.rb', line 34

def unambiguous?
  !!(@root && @procfile)
end