awesome_print 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/LICENSE +2 -1
- data/README.md +6 -4
- data/VERSION +1 -1
- data/lib/ap.rb +8 -5
- data/lib/ap/awesome_print.rb +4 -2
- data/lib/ap/core_ext/array.rb +2 -2
- data/lib/ap/core_ext/class.rb +5 -3
- data/lib/ap/core_ext/kernel.rb +1 -1
- data/lib/ap/core_ext/logger.rb +1 -1
- data/lib/ap/core_ext/method.rb +1 -1
- data/lib/ap/core_ext/object.rb +6 -6
- data/lib/ap/core_ext/string.rb +1 -1
- data/lib/ap/mixin/action_view.rb +2 -2
- data/lib/ap/mixin/active_record.rb +11 -10
- data/lib/ap/mixin/active_support.rb +3 -1
- data/lib/awesome_print.rb +8 -5
- data/rails/init.rb +1 -1
- data/spec/awesome_print_spec.rb +48 -0
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
0.3.2
|
2
|
+
- Make sure Rails mixins get loaded in Rails console when required from .irbrc
|
3
|
+
- Fixed an issue with classes that define their own #send method (ex: Socket)
|
4
|
+
- Fixed compatibility issue with Liquid gem that defines Module#liquid_methods
|
5
|
+
- Fixed hash spec for Ruby < 1.9 where order of hash keys is not guaranteed
|
6
|
+
- Added :sorted_hash_keys option to sort hash keys (Ed Ruder)
|
7
|
+
|
1
8
|
0.3.1 RubyConf X edition
|
2
9
|
- Fixed Ruby 1.8.6 compatibility issues (thanks, Tim!)
|
3
10
|
- Fixed stack overflow issue with Rails 2.3.x console
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -20,9 +20,11 @@ objects and usage within Rails templates are supported via included mixins.
|
|
20
20
|
|
21
21
|
Default options:
|
22
22
|
|
23
|
-
:multiline => true,
|
24
|
-
:plain => false,
|
25
|
-
:indent => 4,
|
23
|
+
:multiline => true, # Display in multipe lines.
|
24
|
+
:plain => false, # Use colors.
|
25
|
+
:indent => 4, # Indent using 4 spaces.
|
26
|
+
:index => true, # Display array indices.
|
27
|
+
:sorted_hash_keys => false, # Do not sort hash keys.
|
26
28
|
:color => {
|
27
29
|
:array => :white,
|
28
30
|
:bignum => :blue,
|
@@ -263,7 +265,7 @@ For example:
|
|
263
265
|
* Tobias Crawley -- http://github.com/tobias
|
264
266
|
|
265
267
|
### License ###
|
266
|
-
Copyright (c) 2010 Michael Dvorkin
|
268
|
+
Copyright (c) 2010-2011 Michael Dvorkin
|
267
269
|
twitter.com/mid
|
268
270
|
%w(mike dvorkin.net) * "@" || %w(mike fatfreecrm.com) * "@"
|
269
271
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/ap.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -8,7 +8,10 @@
|
|
8
8
|
end
|
9
9
|
|
10
10
|
require File.dirname(__FILE__) + "/ap/awesome_print"
|
11
|
-
require File.dirname(__FILE__) + "/ap/core_ext/logger"
|
12
|
-
require File.dirname(__FILE__) + "/ap/mixin/action_view"
|
13
|
-
|
14
|
-
|
11
|
+
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(Logger)
|
12
|
+
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(ActionView)
|
13
|
+
|
14
|
+
# Load the following under normal circumstatnces as well as in Rails
|
15
|
+
# console when required from ~/.irbrc.
|
16
|
+
require File.dirname(__FILE__) + "/ap/mixin/active_record" if defined?(ActiveRecord) || (defined?(IRB) && ENV['RAILS_ENV'])
|
17
|
+
require File.dirname(__FILE__) + "/ap/mixin/active_support" if defined?(ActiveSupport) || (defined?(IRB) && ENV['RAILS_ENV'])
|
data/lib/ap/awesome_print.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -15,6 +15,7 @@ class AwesomePrint
|
|
15
15
|
:plain => false,
|
16
16
|
:indent => 4,
|
17
17
|
:index => true,
|
18
|
+
:sorted_hash_keys => false,
|
18
19
|
:color => {
|
19
20
|
:array => :white,
|
20
21
|
:bigdecimal => :blue,
|
@@ -75,7 +76,8 @@ class AwesomePrint
|
|
75
76
|
def awesome_hash(h)
|
76
77
|
return "{}" if h == {}
|
77
78
|
|
78
|
-
|
79
|
+
keys = @options[:sorted_hash_keys] ? h.keys.sort { |a, b| a.to_s <=> b.to_s } : h.keys
|
80
|
+
data = keys.map do |key|
|
79
81
|
plain_single_line do
|
80
82
|
[ awesome(key), h[key] ]
|
81
83
|
end
|
data/lib/ap/core_ext/array.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -16,7 +16,7 @@ class Array #:nodoc:
|
|
16
16
|
[ :-, :& ].each do |operator|
|
17
17
|
alias :"original_#{operator.object_id}" :"#{operator}"
|
18
18
|
define_method operator do |*args|
|
19
|
-
arr = self.
|
19
|
+
arr = self.__send__(:"original_#{operator.object_id}", *args)
|
20
20
|
if self.instance_variable_defined?('@__awesome_methods__')
|
21
21
|
arr.instance_variable_set('@__awesome_methods__', self.instance_variable_get('@__awesome_methods__'))
|
22
22
|
arr.sort!
|
data/lib/ap/core_ext/class.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
5
5
|
#------------------------------------------------------------------------------
|
6
6
|
class Class #:nodoc:
|
7
|
-
|
7
|
+
# Remaining public/private etc. '_methods' are handled in core_ext/object.rb.
|
8
|
+
%w(instance_methods private_instance_methods protected_instance_methods public_instance_methods).each do |name|
|
8
9
|
alias :"original_#{name}" :"#{name}"
|
10
|
+
|
9
11
|
define_method name do |*args|
|
10
|
-
methods = self.
|
12
|
+
methods = self.__send__(:"original_#{name}", *args)
|
11
13
|
methods.instance_variable_set('@__awesome_methods__', self) # Evil?!
|
12
14
|
methods.sort!
|
13
15
|
end
|
data/lib/ap/core_ext/kernel.rb
CHANGED
data/lib/ap/core_ext/logger.rb
CHANGED
data/lib/ap/core_ext/method.rb
CHANGED
data/lib/ap/core_ext/object.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
5
5
|
#------------------------------------------------------------------------------
|
6
6
|
class Object #:nodoc:
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# Remaining instance '_methods' are handled in core_ext/class.rb.
|
8
|
+
%w(methods private_methods protected_methods public_methods singleton_methods).each do |name|
|
10
9
|
alias :"original_#{name}" :"#{name}"
|
10
|
+
|
11
11
|
define_method name do |*args|
|
12
|
-
methods = self.
|
12
|
+
methods = self.__send__(:"original_#{name}", *args)
|
13
13
|
methods.instance_variable_set('@__awesome_methods__', self) # Evil?!
|
14
14
|
methods.sort!
|
15
15
|
end
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
data/lib/ap/core_ext/string.rb
CHANGED
data/lib/ap/mixin/action_view.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -35,4 +35,4 @@ module AwesomePrintActionView
|
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
-
ActionView::Base.send(:include, AwesomePrintActionView) if defined?(
|
38
|
+
ActionView::Base.send(:include, AwesomePrintActionView) if defined?(ActionView)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -14,6 +14,8 @@ module AwesomePrintActiveRecord
|
|
14
14
|
#------------------------------------------------------------------------------
|
15
15
|
def printable_with_active_record(object)
|
16
16
|
printable = printable_without_active_record(object)
|
17
|
+
return printable if !defined?(ActiveRecord::Base)
|
18
|
+
|
17
19
|
if printable == :self
|
18
20
|
if object.is_a?(ActiveRecord::Base)
|
19
21
|
printable = :active_record_instance
|
@@ -27,6 +29,8 @@ module AwesomePrintActiveRecord
|
|
27
29
|
# Format ActiveRecord instance object.
|
28
30
|
#------------------------------------------------------------------------------
|
29
31
|
def awesome_active_record_instance(object)
|
32
|
+
return object.inspect if !defined?(ActiveSupport::OrderedHash)
|
33
|
+
|
30
34
|
data = object.class.column_names.inject(ActiveSupport::OrderedHash.new) do |hash, name|
|
31
35
|
hash[name.to_sym] = object.send(name) if object.has_attribute?(name) || object.new_record?
|
32
36
|
hash
|
@@ -37,17 +41,14 @@ module AwesomePrintActiveRecord
|
|
37
41
|
# Format ActiveRecord class object.
|
38
42
|
#------------------------------------------------------------------------------
|
39
43
|
def awesome_active_record_class(object)
|
40
|
-
if object.respond_to?(:columns)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
"class #{object} < #{object.superclass} " << awesome_hash(data)
|
46
|
-
else
|
47
|
-
object.inspect
|
44
|
+
return object.inspect if !defined?(ActiveSupport::OrderedHash) || !object.respond_to?(:columns)
|
45
|
+
|
46
|
+
data = object.columns.inject(ActiveSupport::OrderedHash.new) do |hash, c|
|
47
|
+
hash[c.name.to_sym] = c.type
|
48
|
+
hash
|
48
49
|
end
|
50
|
+
"class #{object} < #{object.superclass} " << awesome_hash(data)
|
49
51
|
end
|
50
|
-
|
51
52
|
end
|
52
53
|
|
53
54
|
AwesomePrint.send(:include, AwesomePrintActiveRecord)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -14,6 +14,8 @@ module AwesomePrintActiveSupport
|
|
14
14
|
#------------------------------------------------------------------------------
|
15
15
|
def printable_with_active_support(object)
|
16
16
|
printable = printable_without_active_support(object)
|
17
|
+
return printable if !defined?(ActiveSupport::TimeWithZone) || !defined?(HashWithIndifferentAccess)
|
18
|
+
|
17
19
|
if printable == :self
|
18
20
|
if object.is_a?(ActiveSupport::TimeWithZone)
|
19
21
|
printable = :active_support_time
|
data/lib/awesome_print.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
@@ -15,7 +15,10 @@
|
|
15
15
|
end
|
16
16
|
|
17
17
|
require File.dirname(__FILE__) + "/ap/awesome_print"
|
18
|
-
require File.dirname(__FILE__) + "/ap/core_ext/logger"
|
19
|
-
require File.dirname(__FILE__) + "/ap/mixin/action_view"
|
20
|
-
|
21
|
-
|
18
|
+
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(Logger)
|
19
|
+
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(ActionView)
|
20
|
+
|
21
|
+
# Load the following under normal circumstatnces as well as in Rails
|
22
|
+
# console when required from ~/.irbrc.
|
23
|
+
require File.dirname(__FILE__) + "/ap/mixin/active_record" if defined?(ActiveRecord) || (defined?(IRB) && ENV['RAILS_ENV'])
|
24
|
+
require File.dirname(__FILE__) + "/ap/mixin/active_support" if defined?(ActiveSupport) || (defined?(IRB) && ENV['RAILS_ENV'])
|
data/rails/init.rb
CHANGED
data/spec/awesome_print_spec.rb
CHANGED
@@ -263,6 +263,45 @@ EOS
|
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
266
|
+
#------------------------------------------------------------------------------
|
267
|
+
describe "Hash with several keys" do
|
268
|
+
before(:each) do
|
269
|
+
@hash = {"b" => "b", :a => "a", :z => "z", "alpha" => "alpha"}
|
270
|
+
end
|
271
|
+
|
272
|
+
it "plain multiline" do
|
273
|
+
out = @hash.ai(:plain => true)
|
274
|
+
if RUBY_VERSION.to_f < 1.9 # Order of @hash keys is not guaranteed.
|
275
|
+
out.should =~ /^\{[^\}]+\}/m
|
276
|
+
out.should =~ / "b" => "b",?/
|
277
|
+
out.should =~ / :a => "a",?/
|
278
|
+
out.should =~ / :z => "z",?/
|
279
|
+
out.should =~ / "alpha" => "alpha",?$/
|
280
|
+
else
|
281
|
+
out.should == <<-EOS.strip
|
282
|
+
{
|
283
|
+
"b" => "b",
|
284
|
+
:a => "a",
|
285
|
+
:z => "z",
|
286
|
+
"alpha" => "alpha"
|
287
|
+
}
|
288
|
+
EOS
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
it "plain multiline with sorted keys" do
|
293
|
+
@hash.ai(:plain => true, :sorted_hash_keys => true).should == <<-EOS.strip
|
294
|
+
{
|
295
|
+
:a => "a",
|
296
|
+
"alpha" => "alpha",
|
297
|
+
"b" => "b",
|
298
|
+
:z => "z"
|
299
|
+
}
|
300
|
+
EOS
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
|
266
305
|
#------------------------------------------------------------------------------
|
267
306
|
describe "Negative options[:indent]" do
|
268
307
|
before(:each) do
|
@@ -475,5 +514,14 @@ EOS
|
|
475
514
|
my = My.new('/tmp')
|
476
515
|
my.ai(:plain => true).should == "#{my.inspect}\n" << `ls -alF #{my.path}`.chop
|
477
516
|
end
|
517
|
+
|
518
|
+
it "should handle a class that defines its own #send method" do
|
519
|
+
class My
|
520
|
+
def send(arg1, arg2, arg3); end
|
521
|
+
end
|
522
|
+
|
523
|
+
my = My.new
|
524
|
+
my.methods.ai(:plain => true).should_not raise_error(ArgumentError)
|
525
|
+
end
|
478
526
|
end
|
479
527
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Dvorkin
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-02-02 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|