Sha256: 6de8511112f474ccb1b8356a24827edb91dabea65163e24aec06b8962b0d136f

Contents?: true

Size: 945 Bytes

Versions: 12

Compression:

Stored size: 945 Bytes

Contents

require 'highline'

module Xing::CLI::Generators
  class NewProject
    class UserInput
      attr_accessor :code_of_conduct, :coc_contact_email

      def gather
        self.code_of_conduct = yesno("Add a Code of Conduct? (Contributor Covenant)")
        if code_of_conduct
          self.coc_contact_email = highline.ask("Enter a contact email for your Code of Conduct:") { |q| q.validate = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/ }
        end
      end

      protected

      def highline
        @highline ||= HighLine.new
      end

      def yesno(prompt = 'Continue?', default = true)
        answer = ''
        options = default ? '[Y/n]' : '[y/N]'
        def_answer = default ? 'y' : 'n'
        until %w[y n].include? answer
          answer = highline.ask("#{prompt} #{options} ") { |q| q.limit = 1; q.case = :downcase }
          answer = def_answer if answer.length == 0
        end
        answer == 'y'
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
xing-framework-1.0.0.pre.beta.1 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-1.0.0.pre.beta lib/xing/cli/generators/new_project/user_input.rb
xing-framework-1.0.0.pre.alpha lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.3.2 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.3.1 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.3.0 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.2.9 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.2.9.beta1 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.2.8 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.2.8.beta1 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.2.7 lib/xing/cli/generators/new_project/user_input.rb
xing-framework-0.2.7.pre.beta1 lib/xing/cli/generators/new_project/user_input.rb