Sha256: 0af941e8e3426b056691dc96f15e5e7b5b163152cc3d5eb474df3ca94597983b

Contents?: true

Size: 974 Bytes

Versions: 1

Compression:

Stored size: 974 Bytes

Contents

require 'pgit'
require 'forwardable'

module PGit
  class Project
    class InteractiveAdder
      extend Forwardable

      def_delegators :@project, :save!
      attr_reader :project

      def initialize(project)
        @project = project
      end

      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

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pgit-1.0.0 lib/pgit/project/interactive_adder.rb