awesome_print 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ## Awesome Print ##
2
- Awesome Print is Ruby library that pretty prints Ruby objects in full color
3
- exposing their internal structure with proper indentation. Rails ActiveRecord
4
- objects are supported via included mixin.
2
+ Awesome Print is Ruby library that pretty prints Ruby objects in full color
3
+ exposing their internal structure with proper indentation. Rails ActiveRecord
4
+ objects are supported via included mixin.
5
5
 
6
6
  ### Installation ###
7
7
  $ # Installing as Ruby gem
@@ -20,6 +20,7 @@
20
20
  Default options:
21
21
  :miltiline => true,
22
22
  :plain => false,
23
+ :indent => 4,
23
24
  :colors => {
24
25
  :array => :white,
25
26
  :bignum => :blue,
@@ -58,6 +59,12 @@
58
59
  :distance => 4.2e+43
59
60
  }
60
61
  ]
62
+ irb> ap data[3], :indent => -2 # Left align hash keys.
63
+ {
64
+ :class => Time < Object,
65
+ :now => Fri Apr 02 19:55:53 -0700 2010,
66
+ :distance => 4.2e+43
67
+ }
61
68
  irb> ap data, :multiline => false
62
69
  [ false, 42, [ "fourty", "two" ], { :class => Time < Object, :distance => 4.2e+43, :now => Fri Apr 02 19:44:52 -0700 2010 } ]
63
70
  irb>
@@ -120,15 +127,19 @@
120
127
  }
121
128
  rails>
122
129
 
130
+ ### Known Issues ###
131
+
132
+ * Windows...
133
+
123
134
  ### Note on Patches/Pull Requests ###
124
- * Fork the project on Github.
125
- * Make your feature addition or bug fix.
126
- * Add specs for it, making sure $ rake spec is all green.
127
- * Commit, do not mess with rakefile, version, or history.
128
- * Send me a pull request.
135
+ * Fork the project on Github.
136
+ * Make your feature addition or bug fix.
137
+ * Add specs for it, making sure $ rake spec is all green.
138
+ * Commit, do not mess with rakefile, version, or history.
139
+ * Send me a pull request.
129
140
 
130
141
  ### License ###
131
- Copyright (c) 2010 Michael Dvorkin
132
- %w(mike dvorkin.net) * "@" || %w(mike fatfreecrm.com) * "@"
142
+ Copyright (c) 2010 Michael Dvorkin
143
+ %w(mike dvorkin.net) * "@" || %w(mike fatfreecrm.com) * "@"
133
144
 
134
- Released under the MIT license. See LICENSE file for details.
145
+ Released under the MIT license. See LICENSE file for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -29,7 +29,7 @@ class AwesomePrint
29
29
  }.merge(options.delete(:color) || {})
30
30
  }.merge(options)
31
31
 
32
- @indentation = @options[:indent]
32
+ @indentation = @options[:indent].abs
33
33
  Thread.current[AP] ||= []
34
34
  end
35
35
 
@@ -58,7 +58,7 @@ class AwesomePrint
58
58
  end
59
59
  end
60
60
 
61
- # Format a hash.
61
+ # Format a hash. If @options[:indent] if negative left align hash keys.
62
62
  #------------------------------------------------------------------------------
63
63
  def awesome_hash(h)
64
64
  data = h.keys.inject([]) do |arr, key|
@@ -67,12 +67,17 @@ class AwesomePrint
67
67
  end
68
68
  end
69
69
 
70
- width = data.map { |key, | key.size }.max + @indentation
70
+ width = data.map { |key, | key.size }.max
71
+ width += @indentation if @options[:indent] > 0
71
72
 
72
73
  data = data.inject([]) do |arr, (key, value)|
73
- formatted_key = (@options[:multiline] ? key.rjust(width) : key) << colorize(" => ", :hash)
74
+ if @options[:multiline]
75
+ formatted_key = (@options[:indent] >= 0 ? key.rjust(width) : indent + key.ljust(width))
76
+ else
77
+ formatted_key = key
78
+ end
74
79
  indented do
75
- arr << (formatted_key << awesome(value))
80
+ arr << (formatted_key << colorize(" => ", :hash) << awesome(value))
76
81
  end
77
82
  end
78
83
  if @options[:multiline]
@@ -175,20 +180,20 @@ class AwesomePrint
175
180
 
176
181
  #------------------------------------------------------------------------------
177
182
  def indented
178
- @indentation += @options[:indent]
183
+ @indentation += @options[:indent].abs
179
184
  yield
180
185
  ensure
181
- @indentation -= @options[:indent]
186
+ @indentation -= @options[:indent].abs
182
187
  end
183
188
 
184
189
  #------------------------------------------------------------------------------
185
190
  def indent
186
- ' ' * @indentation
191
+ @indent = ' ' * @indentation
187
192
  end
188
193
 
189
194
  #------------------------------------------------------------------------------
190
195
  def outdent
191
- ' ' * (@indentation - @options[:indent])
196
+ @outdent = ' ' * (@indentation - @options[:indent].abs)
192
197
  end
193
198
 
194
199
  end
@@ -38,7 +38,7 @@ module AwesomePrintRails
38
38
  # Format ActiveRecord class object.
39
39
  #------------------------------------------------------------------------------
40
40
  def awesome_active_record_class(object)
41
- if object.table_exists?
41
+ if object.respond_to?(:columns)
42
42
  data = object.columns.inject(ActiveSupport::OrderedHash.new) do |hash, c|
43
43
  hash[c.name.to_sym] = c.type
44
44
  hash
@@ -227,6 +227,23 @@ EOS
227
227
  end
228
228
  end
229
229
 
230
+ #------------------------------------------------------------------------------
231
+ describe "Negative options[:indent]" do
232
+ before(:each) do
233
+ @hash = { [0, 0, 255] => :yellow, :red => "rgb(255, 0, 0)", "magenta" => "rgb(255, 0, 255)" }
234
+ end
235
+
236
+ it "hash keys must be left aligned" do
237
+ ap = AwesomePrint.new(:plain => true, :indent => -4)
238
+ out = ap.send(:awesome, @hash)
239
+ out.start_with?("{\n").should == true
240
+ out.include?(' :red => "rgb(255, 0, 0)"').should == true
241
+ out.include?(' "magenta" => "rgb(255, 0, 255)"').should == true
242
+ out.include?(' [ 0, 0, 255 ] => :yellow').should == true
243
+ out.end_with?("\n}").should == true
244
+ end
245
+ end
246
+
230
247
  #------------------------------------------------------------------------------
231
248
  describe "Class" do
232
249
  it "shoud show superclass (plain)" do
@@ -13,10 +13,6 @@ if defined?(::Rails)
13
13
  columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
14
14
  end
15
15
 
16
- def self.table_exists?
17
- true
18
- end
19
-
20
16
  column :id, :integer
21
17
  column :name, :string
22
18
  column :rank, :integer
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
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: 2010-04-02 00:00:00 -07:00
17
+ date: 2010-04-04 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency