Sha256: a9f5d0047e6af2d3a5aff821abbfa3d3c01a740663e6fa2f3a33b8f4b716b02b

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8
module CSD
  class UI
    
    include Gem::UserInteraction
    
    # These are all possible user interactions provided by the UI
    #
    INTERACTIONS = %w{ separator debug info warn error ask ask_yes_no die }
    
    def separator
      say
    end
    
    def debug(message)
      say "DEBUG: #{message}".magenta if Options.debug and !Options.silent
    end
    
    def info(message)
      say message if !Options.silent
    end
    
    def warn(message)
      say 'NOTE: '.red + message.red if !Options.silent
    end

    def error(message)
      say('ERROR: '.red.blink + message.red) if !Options.silent
    end
    
    def die(message)
      say('ERROR: '.red.blink + message.red) if !Options.silent
      abort
    end
    
    protected
    
    # This is just a convenience wrapper so that +UI.myinteraction+ will map to +CSD.ui.myinteraction+
    #
    def self.method_missing(meth, *args, &block)
      INTERACTIONS.include?(meth.to_s) ? CSD.ui.send(meth.to_sym, *args, &block) : super
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csd-0.1.5 lib/csd/ui/ui.rb