]> git.r.bdr.sh - rbdr/cologne/commitdiff
initial
authorkazuyoshi tlacaelel <redacted>
Fri, 2 Mar 2012 21:11:54 +0000 (15:11 -0600)
committerkazuyoshi tlacaelel <redacted>
Fri, 2 Mar 2012 21:11:54 +0000 (15:11 -0600)
Rakefile
VERSION
lib/cobalt.rb

index fc460681942e6be5b9a6e3c86bf82a02580316db..bfac7380879c0b01ddf26cc6285282c4976b2f1c 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -4,18 +4,18 @@ require 'rake'
 begin
   require 'jeweler'
   Jeweler::Tasks.new do |gem|
-    gem.name = "cobalt"
-    gem.summary = %Q{TODO: one-line summary of your gem}
-    gem.description = %Q{TODO: longer description of your gem}
-    gem.email = "kazu.dev@gmail.com"
-    gem.homepage = "http://github.com/ktlacaelel/cobalt"
-    gem.authors = ["kazuyoshi tlacaelel"]
-    gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
-    # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+    gem.name = 'cobalt'
+    gem.summary = %Q{Console for ruby.}
+    gem.description = %Q{Colored, Nesting, Multiple logging management.}
+    gem.email = 'kazu.dev@gmail.com'
+    gem.homepage = 'http://github.com/ktlacaelel/cobalt'
+    gem.authors = ['Fernando TrasviƱa', 'Pablo Antonio Gonzalez Cervantes', 'kazuyoshi tlacaelel']
+    gem.add_development_dependency 'thoughtbot-shoulda', '>= 0'
+    gem.add_development_dependency 'isna', '>= 0'
   end
   Jeweler::GemcutterTasks.new
 rescue LoadError
-  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+  puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
 end
 
 require 'rake/testtask'
@@ -34,7 +34,7 @@ begin
   end
 rescue LoadError
   task :rcov do
-    abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
+    abort 'RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov'
   end
 end
 
@@ -44,7 +44,7 @@ task :default => :test
 
 require 'rake/rdoctask'
 Rake::RDocTask.new do |rdoc|
-  version = File.exist?('VERSION') ? File.read('VERSION') : ""
+  version = File.exist?('VERSION') ? File.read('VERSION') : ''
 
   rdoc.rdoc_dir = 'rdoc'
   rdoc.title = "cobalt #{version}"
diff --git a/VERSION b/VERSION
index 77d6f4ca23711533e724789a0a0045eab28c5ea6..8acdd82b765e8e0b8cd8787f7f18c7fe2ec52493 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.0.0
+0.0.1
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a85409f8e0e1c5e72c5a5041bdedcb448f95d4bd 100644 (file)
@@ -0,0 +1,117 @@
+require 'rubygems'
+require 'isna'
+require 'logger'
+
+module Cobalt
+
+  class Console
+
+    attr_accessor :keep_in_buffer, :separator_length
+
+    def initialize( options = {} )
+      @indent           = 0
+      @loggers          = options[:loggers] || [::Logger.new(STDOUT)]
+      @keep_in_buffer   = false
+      @temporal_buffer  = []
+      @separator_length = 120
+      @color            = :white
+    end
+
+    def add_logger logger
+      @loggers << logger
+    end
+
+    def remove_logger logger
+      @loggers = @loggers - [logger]
+    end
+
+    def release_buffer
+      @keep_in_buffer = false
+      @temporal_buffer.each do |line|
+        @loggers.each { |logger| logger.info(line) }
+      end
+      @temporal_buffer = []
+      nil
+    end
+
+    def log(*objects)
+      objects.each do |object|
+
+        the_string = object.to_s
+        the_string = the_string.to_ansi.send(@color).to_s
+        the_string = the_string.gsub(/^/, ' ' * @indent)
+
+        @loggers.each do |logger|
+          if @keep_in_buffer
+            @temporal_buffer << the_string
+            next
+          end
+          logger.info the_string
+        end
+
+      end
+      self
+    end
+
+    def pp(*objects)
+      dump = ""
+      if objects.size > 1
+        PP.pp(objects, dump)
+      else
+        PP.pp(objects.first, dump)
+      end
+      log(dump)
+    end
+
+    def notice(*objects)
+      color(:cyan) { log(*objects) }
+    end
+
+    def warn(*objects)
+      color(:yellow) { log(*objects) }
+    end
+
+    def error(*objects)
+      color(:red) { log(*objects) }
+    end
+
+    def separator(type = '-')
+      log((type * (@separator_length - @indent)))
+    end
+
+    def space(lines = 1)
+      lines.times { self.log('') }
+      self
+    end
+
+    def indent
+      if block_given?
+        @indent = @indent + 2
+        yield
+        @indent = @indent - 2
+      else
+        @indent = @indent + 2
+      end
+      self
+    end
+
+    def outdent
+      @indent = @indent - 2
+      self
+    end
+
+    def color(symbol)
+      if block_given?
+        old = @color
+        @color = symbol
+        yield
+        @color = old
+      else
+        @color = symbol
+      end
+      self
+    end
+
+  end
+
+end