marked 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'test-unit'
5
+ gem 'shoulda'
6
+ gem 'mocha'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jack Danger Canty
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,61 @@
1
+ Marked
2
+ =
3
+
4
+ [http://github.com/JackDanger/marked](http://github.com/JackDanger/marked)
5
+
6
+ DESCRIPTION
7
+ ==
8
+
9
+ Ruby debugging often consists of printing out objects at various points in your code to inspect their current values. Do it fast and easy with Marked. the `mark()` method exists in global scope and always returns the values you pass into it, allowing your code to run as normal but giving you intermediate feedback.
10
+
11
+ USAGE
12
+ ==
13
+
14
+ Before:
15
+
16
+ class User < ActiveRecord::Base
17
+ def some_method
18
+ complex_result
19
+ end
20
+ end
21
+
22
+ How do you tell what the value of `complex_result` is inside this method?
23
+ How do you tell if this method even ran?
24
+ You write tests. Okay, but after that, if you're tracking down a bug?
25
+
26
+ class User < ActiveRecord::Base
27
+ def some_method
28
+ mark complex_result
29
+ end
30
+ end
31
+
32
+ And you'll get the value of `complex_result` printed to your console and to the Rails log (if it exists)
33
+
34
+ Can take multiple arguments, always returning the last:
35
+
36
+
37
+ class User < ActiveRecord::Base
38
+ def some_method
39
+ mark self, 'complex result: ', complex_result
40
+ end
41
+ end
42
+
43
+ Also handles blocks smoothly, returning the block's result as if there were no block.
44
+
45
+ class User < ActiveRecord::Base
46
+ def some_method
47
+ mark self, 'complex result: ' do
48
+ complex_result
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+
55
+ INSTALL
56
+ ==
57
+
58
+ * gem install marked
59
+
60
+
61
+ Copyright 2011 Jack Danger Canty. Patches welcome, forks celebrated
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "marked"
5
+ gem.summary = %Q{Fast debugging for Ruby. Output any objects or blocks to both Rails log and console output simultaneously}
6
+ gem.description = %Q{Quick Ruby debugger. Easily print any object or string to the console and to your logs while you're working.}
7
+ gem.email = "rubygems@6brand.com"
8
+ gem.homepage = "http://github.com/JackDanger/marked"
9
+ gem.authors = ["Jack Danger Canty"]
10
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
11
+ end
12
+ Jeweler::GemcutterTasks.new
13
+ rescue LoadError
14
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
15
+ end
16
+
17
+
18
+
19
+ task :default => :test
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << '.'
24
+ test.pattern = 'test/*_test.rb'
25
+ test.verbose = true
26
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/lib/marked.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Marked
2
+ def mark *objects
3
+
4
+ returnable = block_given? ? yield : objects.last
5
+
6
+ Marked.log "<MARK>"
7
+
8
+ if block_given?
9
+ Marked.print returnable
10
+ Marked.log returnable
11
+ end
12
+
13
+ objects.each do |object|
14
+ Marked.print object
15
+ Marked.log object
16
+ end
17
+
18
+ Marked.log "</MARK>"
19
+
20
+ returnable
21
+ end
22
+
23
+ def self.log object
24
+ if defined?(Rails)
25
+ Rails.logger.debug object.is_a?(String) ? object : object.inspect
26
+ end
27
+ end
28
+
29
+ def self.print object
30
+ STDOUT.puts object.is_a?(String) ? object : object.inspect
31
+ end
32
+ end
33
+
34
+ class Object
35
+ include Marked
36
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class MarkedTest < Test::Unit::TestCase
4
+ context "printing and logging a single argument" do
5
+ setup {
6
+ Rails.logger.expects(:debug).with("<MARK>")
7
+ Rails.logger.expects(:debug).with("this should be printed")
8
+ Rails.logger.expects(:debug).with("</MARK>")
9
+ Marked.expects(:print).with("this should be printed")
10
+ }
11
+ should "return its argument" do
12
+ assert_equal "this should be printed", mark("this should be printed")
13
+ end
14
+ end
15
+ context "printing and logging multiple arguments" do
16
+ setup {
17
+ Rails.logger.expects(:debug).with("<MARK>")
18
+ Rails.logger.expects(:debug).with("this should be printed")
19
+ Rails.logger.expects(:debug).with("this too")
20
+ Rails.logger.expects(:debug).with("</MARK>")
21
+ Marked.expects(:print).with("this should be printed")
22
+ Marked.expects(:print).with("this too")
23
+ }
24
+ should "return its last argument" do
25
+ assert_equal "this too", mark("this should be printed", "this too")
26
+ end
27
+ end
28
+ context "printing and logging non-strings" do
29
+ setup {
30
+ Marked.expects(:log).with("<MARK>")
31
+ Marked.expects(:log).with({:a =>'a'})
32
+ Marked.expects(:log).with([1, 2, 3])
33
+ Marked.expects(:log).with("</MARK>")
34
+ Marked.expects(:print).with({:a => 'a'})
35
+ Marked.expects(:print).with([1, 2, 3])
36
+ }
37
+ should "return its last argument as object" do
38
+ assert_equal [1,2,3], mark({:a => 'a'}, [1,2,3])
39
+ end
40
+ end
41
+ context "printing and logging blocks" do
42
+ setup {
43
+ @obj = {}
44
+ @obj.expects(:called!).returns('returned!').once
45
+ Rails.logger.expects(:debug).with("<MARK>")
46
+ Rails.logger.expects(:debug).with("first arg")
47
+ Rails.logger.expects(:debug).with("returned!")
48
+ Rails.logger.expects(:debug).with("</MARK>")
49
+ Marked.expects(:print).with("first arg")
50
+ Marked.expects(:print).with("returned!")
51
+ }
52
+ should "return its last argument as object" do
53
+ assert_equal 'returned!', mark('first arg') { @obj.called! }
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+ require File.expand_path File.join(File.dirname(__FILE__), '..', 'lib', 'marked')
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+
7
+ module Rails
8
+ Logger = {}
9
+ def self.logger
10
+ Logger
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marked
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Jack Danger Canty
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-07 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Quick Ruby debugger. Easily print any object or string to the console and to your logs while you're working.
18
+ email: rubygems@6brand.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.markdown
26
+ files:
27
+ - Gemfile
28
+ - LICENSE
29
+ - README.markdown
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/marked.rb
33
+ - test/marked_test.rb
34
+ - test/test_helper.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/JackDanger/marked
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.6.2
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Fast debugging for Ruby. Output any objects or blocks to both Rails log and console output simultaneously
63
+ test_files: []
64
+