Sha256: 649982baf58f51b770a99cdae414a7d02f9690e8def277af6e05634250954114

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

module Shoe
  module Tasks

    class Abstract
      attr_reader :spec

      def initialize(spec)
        @spec = if spec.respond_to?(:rubygems_version)
                  spec
                else
                  Gem::Specification.load(spec)
                end

        @spec.extend(LocalGemspecExtensions)

        if active?
          define
        end
      end

      private

      module LocalGemspecExtensions #:nodoc:
        def full_gem_path
          Dir.pwd
        end
      end

      def warn(subject, *paragraphs)
        $stderr.extend(Colored).
                extend(Formatted).
                message(subject, paragraphs)
      end

      module Colored #:nodoc:
        YELLOW = "\e[33m"
        CLEAR  = "\e[0m"

        def write(string)
          super(YELLOW) if tty?
          super
          super(CLEAR) if tty?
        end
      end

      module Formatted #:nodoc:
        WIDTH = 72
        WRAP  = /(.{1,#{WIDTH}})( +|$\n?)|(.{1,#{WIDTH}})/

        def message(subject, paragraphs)
          border
          heading(subject)
          body(paragraphs)
          border
        end

        private

        def border
          puts '-' * WIDTH
        end

        def heading(string)
          puts "#{string} warning from shoe".upcase
        end

        def body(paragraphs)
          paragraphs.each do |paragraph|
            puts
            puts wrap(paragraph)
          end
        end

        def wrap(string)
          string.gsub(WRAP, "\\1\\3\n")
        end
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shoe-0.5.1 lib/shoe/tasks/abstract.rb
shoe-0.5.0 lib/shoe/tasks/abstract.rb