Class: PGit::Project::InteractiveAdder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pgit/project/interactive_adder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ InteractiveAdder

Returns a new instance of InteractiveAdder.


12
13
14
# File 'lib/pgit/project/interactive_adder.rb', line 12

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.


10
11
12
# File 'lib/pgit/project/interactive_adder.rb', line 10

def project
  @project
end

Instance Method Details

#execute!Object


16
17
18
19
20
21
22
23
# File 'lib/pgit/project/interactive_adder.rb', line 16

def execute!
  if project.api_token == :no_api_token_given
    puts "What's the project api_token?"
    project.api_token = STDIN.gets.chomp
  end

  get_projects
end

#get_projectsObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pgit/project/interactive_adder.rb', line 25

def get_projects
  projects = PGit::Pivotal::Projects.new(api_token: project.api_token).get!
  question = Interactive::Question.new do |q|
    q.question = "Which project do you want to associate with the working directory?"
    q.options = [projects]
    q.columns = [:index, :name]
  end

  question.ask do |response|
    if response.whole_number?
      project.id = projects[response.to_i].id
    end
  end
end