awesome_print 1.8.0 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/Appraisals +43 -44
  4. data/CHANGELOG.md +20 -2
  5. data/CONTRIBUTING.md +1 -0
  6. data/LICENSE +16 -19
  7. data/README.md +43 -8
  8. data/awesome_print.gemspec +33 -0
  9. data/init.rb +1 -0
  10. data/lib/awesome_print/custom_defaults.rb +1 -1
  11. data/lib/awesome_print/ext/active_record.rb +26 -1
  12. data/lib/awesome_print/formatter.rb +20 -12
  13. data/lib/awesome_print/formatters/array_formatter.rb +2 -2
  14. data/lib/awesome_print/formatters/base_formatter.rb +3 -3
  15. data/lib/awesome_print/formatters/hash_formatter.rb +2 -2
  16. data/lib/awesome_print/formatters/object_formatter.rb +5 -2
  17. data/lib/awesome_print/inspector.rb +6 -3
  18. data/lib/awesome_print/version.rb +1 -1
  19. data/spec/ext/action_view_spec.rb +5 -2
  20. data/spec/ext/active_record_spec.rb +57 -49
  21. data/spec/ext/active_support_spec.rb +5 -1
  22. data/spec/ext/mongoid_spec.rb +2 -39
  23. data/spec/formats_spec.rb +4 -4
  24. data/spec/methods_spec.rb +10 -2
  25. data/spec/misc_spec.rb +25 -18
  26. data/spec/objects_spec.rb +49 -0
  27. data/spec/spec_helper.rb +4 -2
  28. data/spec/support/active_record_data/5_1_diana.txt +104 -0
  29. data/spec/support/active_record_data/5_1_multi.txt +210 -0
  30. data/spec/support/active_record_data/5_2_diana.txt +104 -0
  31. data/spec/support/active_record_data/5_2_multi.txt +210 -0
  32. data/spec/support/active_record_data/6_0_diana.txt +104 -0
  33. data/spec/support/active_record_data/6_0_multi.txt +210 -0
  34. data/spec/support/active_record_data/6_1_diana.txt +109 -0
  35. data/spec/support/active_record_data/6_1_multi.txt +220 -0
  36. data/spec/support/mongoid_versions.rb +10 -6
  37. data/spec/support/rails_versions.rb +20 -0
  38. metadata +45 -56
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cda3844883c76081eb1cbaf6e6188492b51d741d
4
- data.tar.gz: be404804711ff00ce4f3720153bf84ba10d012ef
2
+ SHA256:
3
+ metadata.gz: bc6d20d854c529b902cfe961bd8271b30f1aa9f82c4db11bfdcaa6ecb6b1f469
4
+ data.tar.gz: c4f69e0cf2663cb4889b27414bd9f242789fea28790c3252dc5b2788da70bca2
5
5
  SHA512:
6
- metadata.gz: 3a83fe61488d2df035585c6d54f9e93dfa5c950bef2a7e05707fdb334090bf91db46921d88f2fac136edf13904ee0c76393e5a7c4d4d5f53cf9b460a0f724696
7
- data.tar.gz: 87d8c72172448c0897c668cbefcfe4713802effa219469297ce8b242307998c70f82a087feeb7f0b485ee34941bd833aa5eb14c322143242f09b8f3e7418bc5c
6
+ metadata.gz: c34cd0b7347ecf6e98afc4ef0647f940a02a5d125c955748917c821e6bbf231830604fcbe0fb524c6bfdaa049d6f945bad658d30433bf878841b30a6d79ad765
7
+ data.tar.gz: 9cfae5c9646b5194a52c87b1ea38ba3d711cb616a713e66ce0ab83f255293a4b75f4016f349f047aa43d775d14b9f024fc0edccdf40b9f489e46626908162b00
data/.gitignore CHANGED
@@ -26,6 +26,7 @@ Gemfile.lock
26
26
  /tmp
27
27
  /.bundle
28
28
  /gemfiles/.bundle
29
+ /gemfiles/vendor/bundle
29
30
 
30
31
  ## PROJECT::RVM
31
32
  .rvmrc
data/Appraisals CHANGED
@@ -1,63 +1,62 @@
1
- appraise 'rails-3.2' do
2
- gem 'rails', '~> 3.2.0'
3
- end
4
-
5
- appraise 'rails-4.0' do
6
- gem 'rails', '~> 4.0.0'
7
- gem 'json', '~> 1.8', :platforms => :ruby_19 # Json 2.0 requires Ruby >= 2.0
1
+ # appraise 'rails-4.2' do
2
+ # gem 'rails', '~> 4.2.0'
3
+ #
4
+ # # The last version that doesn't need Ruby 2.0 and works with version 4.2 of
5
+ # # Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
6
+ # gem 'mime-types', '2.6.2', :platforms => :ruby_19
7
+ # end
8
8
 
9
- # The last version that doesn't need Ruby 2.0 and works with version 4.0 of
10
- # Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
11
- gem 'mime-types', '2.6.2', :platforms => :ruby_19
9
+ appraise 'rails-5.0' do
10
+ gem 'rails', '>= 5.0.0', '< 5.1'
11
+ gem 'sqlite3', '~> 1.3.6'
12
12
  end
13
13
 
14
- appraise 'rails-4.1' do
15
- gem 'rails', '~> 4.1.0'
16
-
17
- # The last version that doesn't need Ruby 2.0 and works with version 4.1 of
18
- # Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
19
- gem 'mime-types', '2.6.2', :platforms => :ruby_19
14
+ appraise 'rails-5.1' do
15
+ gem 'rails', '>= 5.1.0', '< 5.2'
20
16
  end
21
17
 
22
- appraise 'rails-4.2' do
23
- gem 'rails', '~> 4.2.0'
24
-
25
- # The last version that doesn't need Ruby 2.0 and works with version 4.2 of
26
- # Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
27
- gem 'mime-types', '2.6.2', :platforms => :ruby_19
18
+ appraise 'rails-5.2' do
19
+ gem 'rails', '>= 5.2.0', '< 5.3'
28
20
  end
29
21
 
30
- appraise 'rails-5.0' do
31
- # Only works with Ruby >= 2.2
32
- gem 'rails', '>= 5.0.0.racecar1', '< 5.1'
22
+ appraise 'rails-6.0' do
23
+ gem 'rails', '>= 6.0.0', '< 6.1'
33
24
  end
34
25
 
35
- appraise 'mongoid-3.0' do
36
- gem 'mongoid', '~> 3.0.0'
26
+ appraise 'rails-6.1' do
27
+ gem 'rails', '>= 6.1.0', '< 6.2'
37
28
  end
38
29
 
39
- appraise 'mongoid-3.1' do
40
- gem 'mongoid', '~> 3.1.0'
41
- gem 'json', '~> 1.8', :platforms => :ruby_19 # Json 2.0 requires Ruby >= 2.0
30
+ appraise 'mongoid-5.0' do
31
+ gem 'mongoid', '~> 5.0.0'
32
+ gem 'bigdecimal', '~> 1.3.5'
42
33
  end
43
34
 
44
- appraise 'mongoid-4.0' do
45
- gem 'mongoid', '~> 4.0.0'
35
+ appraise 'mongoid-6.0' do
36
+ gem 'mongoid', '~> 6.0.0'
46
37
  end
47
38
 
48
- appraise 'mongo_mapper' do
49
- gem 'mongo_mapper'
39
+ appraise 'mongoid-7.0' do
40
+ gem 'mongoid', '~> 7.0.0'
50
41
  end
51
42
 
52
- appraise 'ripple' do
53
- gem 'tzinfo'
54
- gem 'ripple'
43
+ appraise 'mongoid-7.1' do
44
+ gem 'mongoid', '~> 7.1.0'
55
45
  end
56
46
 
57
- appraise 'nobrainer' do
58
- gem 'nobrainer'
59
-
60
- # When activesupport 5 was released, it required ruby 2.2.2 as a minimum.
61
- # Locking this down to 4.2.6 allows our Ruby 1.9 tests to keep working.
62
- gem 'activesupport', '4.2.6', :platforms => :ruby_19
63
- end
47
+ # appraise 'mongo_mapper' do
48
+ # gem 'mongo_mapper'
49
+ # end
50
+ #
51
+ # appraise 'ripple' do
52
+ # gem 'tzinfo'
53
+ # gem 'ripple'
54
+ # end
55
+ #
56
+ # appraise 'nobrainer' do
57
+ # gem 'nobrainer'
58
+ #
59
+ # # When activesupport 5 was released, it required ruby 2.2.2 as a minimum.
60
+ # # Locking this down to 4.2.6 allows our Ruby 1.9 tests to keep working.
61
+ # gem 'activesupport', '4.2.6', :platforms => :ruby_19
62
+ # end
data/CHANGELOG.md CHANGED
@@ -1,11 +1,29 @@
1
1
  ## master (unreleased)
2
- - new things!
2
+
3
+
4
+ ## 1.9.2
5
+ - Tests work with Ruby 2.6.6, 2.7.2 and 3.0.0
6
+ - Update awsome_print.gemspec nokogiri dependency to resolve CVEs [@gvwirth]
7
+
8
+ ## 1.9.1
9
+ - Updated code so it can be released to rubygems.
10
+ - Updated nokogiri to resolve vulnerability scan
11
+
12
+ ## 1.9.0
13
+ - Update method signature after change in IRB [@febeling]
14
+ - Fixes block and proc definition to work with Ruby 3.0.0 [@csalvato] - [#392]
15
+ - Removed check for Ruby 2.4 and earlier [@bryanh]
16
+ - Rails 5.0 builds are failing, because the sqlite3 version being installed is wrong version [#366]
17
+ - Fixes spec suite to properly work via travis, gets a clean build [@imajes, others]
18
+ - Adds support for ActiveModel::Errors [@dshinzie] - [#301]
19
+ - removes use of `strip_heredoc` from specs as it's a rails dep [@kstephens] - [#303]
20
+ - ArrayFormatter now returns arrays for has_many :through associations [@chadh13] - [#332]
3
21
 
4
22
  ## 1.8.0
5
23
  - stat("$HOME/.aprc") once [@kstephens] - [#304]
6
24
  - ActiveRecord: #joins now show the columns #select'ed [@adrianomitre] - [#211]
7
25
  - Handles NoMethodError for IRB implicit `ai` [@jtnegrotto] - [#212]
8
- - Replaced Fixnum reference with Integer
26
+ - Replaced Fixnum reference with Integer
9
27
  - Colorize ORM class names [@ixti]
10
28
 
11
29
  ## 1.7.0
data/CONTRIBUTING.md CHANGED
@@ -51,6 +51,7 @@ Special thanks goes to awesome team of contributors, namely:
51
51
  * Barry Allard -- https://github.com/steakknife
52
52
  * Benoit Daloze -- http://github.com/eregon
53
53
  * Brandon Zylstra -- https://github.com/brandondrew
54
+ * Bryan Hanks, PMP -- https://github.com/bryanh
54
55
  * Dan Lynn -- https://github.com/danlynn
55
56
  * Daniel Johnson -- https://github.com/adhd360
56
57
  * Daniel Bretoi -- http://github.com/danielb2
data/LICENSE CHANGED
@@ -1,22 +1,19 @@
1
- Copyright (c) 2010-2013 Michael Dvorkin
2
- http://www.dvorkin.net
3
- %w(mike dvorkin.net) * "@" || "twitter.com/mid"
1
+ Copyright (c) 2010-2019 Michael Dvorkin
4
2
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
12
9
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
15
12
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md CHANGED
@@ -12,9 +12,8 @@ Awesome Print is a Ruby library that pretty prints Ruby objects in full color
12
12
  exposing their internal structure with proper indentation. Rails ActiveRecord
13
13
  objects and usage within Rails templates are supported via included mixins.
14
14
 
15
- __NOTE__: awesome_print v1.2.0 is the last release supporting Ruby versions
16
- prior to v1.9.3 and Rails versions prior to v3.0. The upcoming awesome_print
17
- v2.0 will *require* Ruby v1.9.3 or later and Rails v3.0 or later.
15
+ __NOTE__: awesome_print v1.9.0 may not work on Ruby versions 2.4 or older or Rails versions 4.2 or older.
16
+ The upcoming awesome_print v2.0 will *require* Ruby v1.9.3 or later and Rails v3.0 or later.
18
17
 
19
18
  ### Installation ###
20
19
  # Installing as Ruby gem
@@ -43,6 +42,8 @@ sort_keys: false, # Do not sort hash keys.
43
42
  sort_vars: true, # Sort instance variables.
44
43
  limit: false, # Limit arrays & hashes. Accepts bool or int.
45
44
  ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
45
+ class_name: :class, # Method called to report the instance class name. (e.g. :to_s)
46
+ object_id: true, # Show object id.
46
47
  color: {
47
48
  args: :pale,
48
49
  array: :white,
@@ -50,7 +51,7 @@ color: {
50
51
  class: :yellow,
51
52
  date: :greenish,
52
53
  falseclass: :red,
53
- fixnum: :blue,
54
+ integer: :blue,
54
55
  float: :blue,
55
56
  hash: :pale,
56
57
  keyword: :cyan,
@@ -82,6 +83,8 @@ irb> "awesome print".ai
82
83
 
83
84
  ### Examples ###
84
85
 
86
+ #### Array
87
+
85
88
  ```ruby
86
89
  $ cat > 1.rb
87
90
  require "awesome_print"
@@ -102,7 +105,10 @@ $ ruby 1.rb
102
105
  :distance => 4.2e+43
103
106
  }
104
107
  ]
108
+ ```
109
+ #### Hash
105
110
 
111
+ ```ruby
106
112
  $ cat > 2.rb
107
113
  require "awesome_print"
108
114
  data = { :now => Time.now, :class => Time.now.class, :distance => 42e42 }
@@ -114,7 +120,11 @@ $ ruby 2.rb
114
120
  :now => Fri Apr 02 19:55:53 -0700 2010,
115
121
  :distance => 4.2e+43
116
122
  }
123
+ ```
117
124
 
125
+ #### Nested array
126
+
127
+ ```ruby
118
128
  $ cat > 3.rb
119
129
  require "awesome_print"
120
130
  data = [ false, 42, %w(forty two) ]
@@ -124,6 +134,11 @@ ap data, :multiline => false
124
134
  $ ruby 3.rb
125
135
  [ false, 42, [ "forty", "two" ], [...] ]
126
136
 
137
+ ```
138
+
139
+ #### Class methods
140
+
141
+ ```ruby
127
142
  $ cat > 4.rb
128
143
  require "awesome_print"
129
144
  class Hello
@@ -137,6 +152,11 @@ $ ruby 4.rb
137
152
  [0] world(x, y, *z, &blk) Hello
138
153
  ]
139
154
 
155
+ ```
156
+
157
+ #### Object methods
158
+
159
+ ```ruby
140
160
  $ cat > 5.rb
141
161
  require "awesome_print"
142
162
  ap (''.methods - Object.methods).grep(/!/)
@@ -165,6 +185,11 @@ $ ruby 5.rb
165
185
  [19] upcase!() String
166
186
  ]
167
187
 
188
+ ```
189
+
190
+ #### Compare output to value
191
+
192
+ ```ruby
168
193
  $ cat > 6.rb
169
194
  require "awesome_print"
170
195
  ap 42 == ap(42)
@@ -172,7 +197,13 @@ ap 42 == ap(42)
172
197
  $ ruby 6.rb
173
198
  42
174
199
  true
175
- $ cat 7.rb
200
+
201
+ ```
202
+
203
+ #### Array with default output limit
204
+
205
+ ```ruby
206
+ $ cat > 7.rb
176
207
  require "awesome_print"
177
208
  some_array = (1..1000).to_a
178
209
  ap some_array, :limit => true
@@ -187,8 +218,12 @@ $ ruby 7.rb
187
218
  [998] 999,
188
219
  [999] 1000
189
220
  ]
221
+ ```
190
222
 
191
- $ cat 8.rb
223
+ #### Array with specific output limit
224
+
225
+ ```ruby
226
+ $ cat > 8.rb
192
227
  require "awesome_print"
193
228
  some_array = (1..1000).to_a
194
229
  ap some_array, :limit => 5
@@ -203,7 +238,7 @@ $ ruby 8.rb
203
238
  ]
204
239
  ```
205
240
 
206
- ### Example (Rails console) ###
241
+ #### Rails console
207
242
  ```ruby
208
243
  $ rails console
209
244
  rails> require "awesome_print"
@@ -305,7 +340,7 @@ With other web frameworks (ex: in Sinatra templates) you can explicitly request
305
340
  formatting:
306
341
 
307
342
  <%= ap @accounts.first, :html => true %>
308
-
343
+
309
344
  ### String Convenience Methods ###
310
345
  Use methods such as `.red` to set string color:
311
346
 
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
+ #
3
+ # Awesome Print is freely distributable under the terms of MIT license.
4
+ # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
+ #------------------------------------------------------------------------------
6
+
7
+ $:.push File.expand_path('../lib', __FILE__)
8
+ require 'awesome_print/version'
9
+
10
+ Gem::Specification.new do |s|
11
+ s.name = 'awesome_print'
12
+ s.version = AwesomePrint.version
13
+ s.authors = 'Michael Dvorkin'
14
+ s.date = Time.now.strftime('%Y-%m-%d')
15
+ s.email = 'mike@dvorkin.net'
16
+ s.homepage = 'https://github.com/awesome-print/awesome_print'
17
+ s.summary = 'Pretty print Ruby objects with proper indentation and colors'
18
+ s.description = 'Great Ruby debugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins'
19
+ s.license = 'MIT'
20
+
21
+ s.files = Dir['[A-Z]*[^~]'] + Dir['lib/**/*.rb'] + Dir['spec/**/*'] + ['.gitignore']
22
+ s.test_files = Dir['spec/**/*']
23
+ s.executables = []
24
+ s.require_paths = ['lib']
25
+
26
+ s.add_development_dependency 'rspec', '>= 3.0.0'
27
+ s.add_development_dependency 'appraisal'
28
+ s.add_development_dependency 'fakefs', '>= 0.2.1'
29
+ s.add_development_dependency 'sqlite3'
30
+ s.add_development_dependency 'nokogiri', '>= 1.11.0'
31
+ # s.add_development_dependency 'simplecov'
32
+ # s.add_development_dependency 'codeclimate-test-reporter'
33
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'awesome_print')
@@ -27,7 +27,7 @@ module AwesomePrint
27
27
 
28
28
  def usual_rb
29
29
  IRB::Irb.class_eval do
30
- def output_value
30
+ def output_value(*args)
31
31
  ap @context.last_value
32
32
  rescue NoMethodError
33
33
  puts "(Object doesn't support #ai)"
@@ -19,6 +19,8 @@ module AwesomePrint
19
19
 
20
20
  if object.is_a?(::ActiveRecord::Base)
21
21
  cast = :active_record_instance
22
+ elsif object.is_a?(::ActiveModel::Errors)
23
+ cast = :active_model_error
22
24
  elsif object.is_a?(Class) && object.ancestors.include?(::ActiveRecord::Base)
23
25
  cast = :active_record_class
24
26
  elsif type == :activerecord_relation || object.class.ancestors.include?(::ActiveRecord::Relation)
@@ -53,7 +55,7 @@ module AwesomePrint
53
55
  hash
54
56
  end
55
57
  end
56
- "#{object} " << awesome_hash(data)
58
+ "#{object} #{awesome_hash(data)}"
57
59
  end
58
60
 
59
61
  # Format ActiveRecord class object.
@@ -72,6 +74,29 @@ module AwesomePrint
72
74
 
73
75
  [name, base, awesome_hash(data)].join(' ')
74
76
  end
77
+
78
+ # Format ActiveModel error object.
79
+ #------------------------------------------------------------------------------
80
+ def awesome_active_model_error(object)
81
+ return object.inspect if !defined?(::ActiveSupport::OrderedHash)
82
+ return awesome_object(object) if @options[:raw]
83
+
84
+ object_dump = object.marshal_dump.first
85
+ data = if object_dump.class.column_names != object_dump.attributes.keys
86
+ object_dump.attributes
87
+ else
88
+ object_dump.class.column_names.inject(::ActiveSupport::OrderedHash.new) do |hash, name|
89
+ if object_dump.has_attribute?(name) || object_dump.new_record?
90
+ value = object_dump.respond_to?(name) ? object_dump.send(name) : object_dump.read_attribute(name)
91
+ hash[name.to_sym] = value
92
+ end
93
+ hash
94
+ end
95
+ end
96
+
97
+ data.merge!({details: object.details, messages: object.messages})
98
+ "#{object} #{awesome_hash(data)}"
99
+ end
75
100
  end
76
101
  end
77
102