Sha256: c98fbe5333b55ae83f59b639d90bbba9378c3965ca0bd3a848599db85e70ec51

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

module Generators
  module HoboSupport
    module ThorShell

      PREFIX = '  => '

      private

      def ask(statement, default='', color=Thor::Shell::Color::MAGENTA)
        result = super(statement, color)
        result = default if result.blank?
        say PREFIX + result.inspect
        result
      end

      def yes_no?(statement, color=Thor::Shell::Color::MAGENTA)
        result = choose(statement + ' [y|n]', /^(y|n)$/i)
        result == 'y' ? true : false
      end

      def choose(prompt, format, default=nil)
        choice = ask prompt, default
        case
        when choice =~ format
          choice
        when choice.blank? && !default.blank?
          default
        else
          say 'Unknown choice! ', Thor::Shell::Color::RED
          choose(prompt, format)
        end
      end

      def say_title(title)
        say "\n #{title} \n", "\e[37;44m"
      end

      def multi_ask(statement)
        result = []
        while (r = ask(statement)) && !r.blank?
          result << r
        end
        result
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hobo_support-1.3.0.pre23 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre22 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre21 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre20 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre19 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre18 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre16 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre15 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre14 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre13 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre12 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre11 lib/generators/hobo_support/thor_shell.rb
hobo_support-1.3.0.pre10 lib/generators/hobo_support/thor_shell.rb