amazing_print 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 806491a973073e36b330fad7b64e69dbc283647d2509609c5aa79d24269ee17b
4
- data.tar.gz: 96ec9502e108582a6f54f01950d52b5de151928af721bcb8c4696f4a10baa14a
3
+ metadata.gz: c49ac51983ec5dc57570bb8e77591c4aa837da01afec64fe9d62139f296ac42b
4
+ data.tar.gz: c1145227423a78c989a8d9a49f8e3ab33b8a39c33b3a197e16a3353300ed20dd
5
5
  SHA512:
6
- metadata.gz: 33030793c2ebf21436b3633a5316e961ad73e5caed621509a36447146ba452634ff5a5ab791002382e07fccf43e3f06b4fbea594e17cf057ae7839629ca2864e
7
- data.tar.gz: d401f7bb5f85f052a6155864dfbbdb73c257f2b0e982226ecf203b6a024f05b8f3e30413d82ae2c02a983363fdd46a44c4ed7f6cfbe57395727d1eb69f0785c8
6
+ metadata.gz: b0039aa9251d996bb7fa516b33ebfd354861caee637c3f5d48dcbd0200739a362159ecad59aa83ba90ec1b607d39ce919ea0b1cee746535b7da05fb9785acfd1
7
+ data.tar.gz: fc2fe38dab3c905483c1f946c6239d479bb827de954cc6504a2046d02762cdbdd3435e411837e7bfa3d319bcff99cdba502eba66c32c688c61b05733e2758c1e
data/.gitignore CHANGED
@@ -32,4 +32,4 @@ Gemfile.lock
32
32
 
33
33
  # PROJECT::RBENV
34
34
  .ruby-gemset
35
- .awesome-print/
35
+ *.gem
data/Appraisals CHANGED
@@ -42,6 +42,12 @@ appraise 'mongoid-6.0' do
42
42
  gem 'mongoid', '~> 6.0.0'
43
43
  end
44
44
 
45
+ appraise 'sequel-5.0' do
46
+ gem 'jdbc-sqlite3', platform: :jruby
47
+ gem 'sequel', '~> 5.0'
48
+ gem 'sqlite3', platform: :mri
49
+ end
50
+
45
51
  # appraise 'mongo_mapper' do
46
52
  # gem 'mongo_mapper'
47
53
  # end
data/README.md CHANGED
@@ -1,13 +1,17 @@
1
1
  ## Amazing Print ##
2
2
 
3
3
  [![RubyGems][gem_version_badge]][ruby_gems]
4
- [![Travis CI][travis_ci_badge]][travis_ci]
5
- [![Code Climate][code_climate_badge]][code_climate]
6
- [![Code Climate Coverage][code_climate_coverage_badge]][code_climate]
7
4
  [![RubyGems][gem_downloads_badge]][ruby_gems]
5
+ |
6
+ [![Travis CI][travis_ci_badge]][travis_ci]
7
+ ![Specs](https://github.com/amazing-print/amazing_print/workflows/Specs/badge.svg)
8
+ ![Lint](https://github.com/amazing-print/amazing_print/workflows/Lint/badge.svg)
9
+ |
8
10
  [![Gitter](https://badges.gitter.im/amazing-print/community.svg)](https://gitter.im/amazing-print/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
9
11
 
10
- Amazing Print is a fork of [AmazingPrint](https://github.com/awesome-print/awesome_print) which became stale and should be used in it's place to avoid conflicts. It is a Ruby library that pretty prints Ruby objects in full color exposing their internal structure with proper indentation. Rails ActiveRecord objects and usage within Rails templates are supported via included mixins.
12
+ AmazingPrint is a fork of [AwesomePrint](https://github.com/awesome-print/awesome_print) which became stale and should be used in it's place to avoid conflicts. It is a Ruby library that pretty prints Ruby objects in full color exposing their internal structure with proper indentation. Rails ActiveRecord objects and usage within Rails templates are supported via included mixins.
13
+
14
+ ![GitHub API demo](github-api-demo.gif)
11
15
 
12
16
  ### Supported Versions ###
13
17
 
@@ -305,7 +309,7 @@ With other web frameworks (ex: in Sinatra templates) you can explicitly request
305
309
  formatting:
306
310
 
307
311
  <%= ap @accounts.first, :html => true %>
308
-
312
+
309
313
  ### String Convenience Methods ###
310
314
  Use methods such as `.red` to set string color:
311
315
 
@@ -351,6 +355,3 @@ Released under the MIT license. See LICENSE file for details.
351
355
  [ruby_gems]: http://rubygems.org/gems/amazing_print
352
356
  [travis_ci]: http://travis-ci.org/amazing-print/amazing_print
353
357
  [travis_ci_badge]: https://img.shields.io/travis/amazing-print/amazing_print/master.svg?style=flat
354
- [code_climate]: https://codeclimate.com/github/amazing-print/amazing_print
355
- [code_climate_badge]: http://img.shields.io/codeclimate/github/amazing-print/amazing_print.svg?style=flat
356
- [code_climate_coverage_badge]: https://codeclimate.com/github/amazing-print/amazing_print/badges/coverage.svg
data/lib/amazing_print.rb CHANGED
@@ -9,38 +9,38 @@
9
9
  #
10
10
  unless defined?(AmazingPrint::Inspector)
11
11
  %w[awesome_method_array string method object class kernel].each do |file|
12
- require "amazing_print/core_ext/#{file}"
12
+ require_relative "amazing_print/core_ext/#{file}"
13
13
  end
14
14
 
15
- require 'amazing_print/custom_defaults'
16
- require 'amazing_print/inspector'
17
- require 'amazing_print/formatter'
18
- require 'amazing_print/version'
19
- require 'amazing_print/core_ext/logger' if defined?(Logger)
15
+ require_relative 'amazing_print/custom_defaults'
16
+ require_relative 'amazing_print/inspector'
17
+ require_relative 'amazing_print/formatter'
18
+ require_relative 'amazing_print/version'
19
+ require_relative 'amazing_print/core_ext/logger' if defined?(Logger)
20
20
  #
21
21
  # Load the following under normal circumstances as well as in Rails
22
22
  # console when required from ~/.irbrc or ~/.pryrc.
23
23
  #
24
24
  if defined?(ActiveRecord) || AmazingPrint.rails_console?
25
- require 'amazing_print/ext/active_record'
25
+ require_relative 'amazing_print/ext/active_record'
26
26
  end
27
27
  if defined?(ActiveSupport) || AmazingPrint.rails_console?
28
- require 'amazing_print/ext/active_support'
28
+ require_relative 'amazing_print/ext/active_support'
29
29
  end
30
30
  #
31
31
  # Load remaining extensions.
32
32
  #
33
33
  if defined?(ActiveSupport.on_load)
34
34
  ActiveSupport.on_load(:action_view) do
35
- require 'amazing_print/ext/action_view'
35
+ require_relative 'amazing_print/ext/action_view'
36
36
  end
37
37
  end
38
- require 'amazing_print/ext/mongo_mapper' if defined?(MongoMapper)
39
- require 'amazing_print/ext/mongoid' if defined?(Mongoid)
40
- require 'amazing_print/ext/nokogiri' if defined?(Nokogiri)
41
- require 'amazing_print/ext/nobrainer' if defined?(NoBrainer)
42
- require 'amazing_print/ext/ripple' if defined?(Ripple)
43
- require 'amazing_print/ext/sequel' if defined?(Sequel)
44
- require 'amazing_print/ext/ostruct' if defined?(OpenStruct)
38
+ require_relative 'amazing_print/ext/mongo_mapper' if defined?(MongoMapper)
39
+ require_relative 'amazing_print/ext/mongoid' if defined?(Mongoid)
40
+ require_relative 'amazing_print/ext/nokogiri' if defined?(Nokogiri)
41
+ require_relative 'amazing_print/ext/nobrainer' if defined?(NoBrainer)
42
+ require_relative 'amazing_print/ext/ripple' if defined?(Ripple)
43
+ require_relative 'amazing_print/ext/sequel' if defined?(Sequel)
44
+ require_relative 'amazing_print/ext/ostruct' if defined?(OpenStruct)
45
45
  end
46
46
  # test
@@ -16,7 +16,7 @@ module AmazingPrint
16
16
  cast = cast_without_sequel(object, type)
17
17
  if defined?(::Sequel::Model) && object.is_a?(::Sequel::Model)
18
18
  cast = :sequel_document
19
- elsif defined?(::Sequel::Model) && object.is_a?(Class) && object.ancestors.include?(::Sequel::Model)
19
+ elsif defined?(::Sequel::Model) && object.is_a?(Class) && object.ancestors.include?(::Sequel::Model) && object&.name != "Sequel::Model"
20
20
  cast = :sequel_model_class
21
21
  elsif defined?(::Sequel::Mysql2::Dataset) && object.class.ancestors.include?(::Sequel::Mysql2::Dataset)
22
22
  cast = :sequel_dataset
@@ -3,7 +3,7 @@
3
3
  # AmazingPrint 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
- require 'amazing_print/formatters'
6
+ require_relative 'formatters'
7
7
 
8
8
  module AmazingPrint
9
9
  class Formatter
@@ -26,7 +26,7 @@ module AmazingPrint
26
26
  send(:"awesome_#{core_class}", object) # Core formatters.
27
27
  else
28
28
  awesome_self(object, type) # Catch all that falls back to object.inspect.
29
- end
29
+ end
30
30
  awesome
31
31
  end
32
32
 
@@ -1,14 +1,14 @@
1
1
  module AmazingPrint
2
2
  module Formatters
3
- require 'amazing_print/formatters/object_formatter'
4
- require 'amazing_print/formatters/struct_formatter'
5
- require 'amazing_print/formatters/hash_formatter'
6
- require 'amazing_print/formatters/array_formatter'
7
- require 'amazing_print/formatters/simple_formatter'
8
- require 'amazing_print/formatters/method_formatter'
9
- require 'amazing_print/formatters/class_formatter'
10
- require 'amazing_print/formatters/dir_formatter'
11
- require 'amazing_print/formatters/file_formatter'
12
- require 'amazing_print/colorize'
3
+ require_relative 'formatters/object_formatter'
4
+ require_relative 'formatters/struct_formatter'
5
+ require_relative 'formatters/hash_formatter'
6
+ require_relative 'formatters/array_formatter'
7
+ require_relative 'formatters/simple_formatter'
8
+ require_relative 'formatters/method_formatter'
9
+ require_relative 'formatters/class_formatter'
10
+ require_relative 'formatters/dir_formatter'
11
+ require_relative 'formatters/file_formatter'
12
+ require_relative 'colorize'
13
13
  end
14
14
  end
@@ -70,6 +70,8 @@ module AmazingPrint
70
70
  name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
71
71
  arr << case type
72
72
  when :req then name.to_s
73
+ when :keyreq then "#{name}:"
74
+ when :key then "*#{name}:"
73
75
  when :opt, :rest then "*#{name}"
74
76
  when :block then "&#{name}"
75
77
  else '?'
@@ -123,7 +125,6 @@ module AmazingPrint
123
125
  end
124
126
 
125
127
  def outdent
126
- ' ' * (indentation - options[:indent].abs)
127
128
  i = indentation - options[:indent].abs
128
129
 
129
130
  INDENT_CACHE[i] || ' ' * i
@@ -1,6 +1,7 @@
1
- require_relative 'base_formatter'
2
1
  require 'shellwords'
3
2
 
3
+ require_relative 'base_formatter'
4
+
4
5
  module AmazingPrint
5
6
  module Formatters
6
7
  class DirFormatter < BaseFormatter
@@ -1,6 +1,7 @@
1
- require_relative 'base_formatter'
2
1
  require 'shellwords'
3
2
 
3
+ require_relative 'base_formatter'
4
+
4
5
  module AmazingPrint
5
6
  module Formatters
6
7
  class FileFormatter < BaseFormatter
@@ -19,7 +19,7 @@ module AmazingPrint
19
19
  object.respond_to?(property) ? :accessor : :writer
20
20
  else
21
21
  object.respond_to?(property) ? :reader : nil
22
- end
22
+ end
23
23
  if accessor
24
24
  ["attr_#{accessor} :#{property}", var]
25
25
  else
@@ -19,7 +19,7 @@ module AmazingPrint
19
19
  struct.respond_to?(property) ? :accessor : :writer
20
20
  else
21
21
  struct.respond_to?(property) ? :reader : nil
22
- end
22
+ end
23
23
  if accessor
24
24
  ["attr_#{accessor} :#{property}", var]
25
25
  else
@@ -5,6 +5,6 @@
5
5
  #------------------------------------------------------------------------------
6
6
  module AmazingPrint
7
7
  def self.version
8
- '1.0.0'
8
+ '1.1.0'
9
9
  end
10
10
  end
data/lib/ap.rb CHANGED
@@ -7,4 +7,4 @@
7
7
  # Keeping this for backwards compatibility to allow
8
8
  # require "ap"
9
9
  #
10
- require File.dirname(__FILE__) + '/amazing_print'
10
+ require_relative 'amazing_print'
@@ -255,6 +255,10 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
255
255
  expect(out).to match(
256
256
  /\s+first\(\*args,\s&block\)\s+#<Class:\w+>\s+\(ActiveRecord::Querying\)/
257
257
  )
258
+ elsif RUBY_VERSION >= '2.7.0'
259
+ expect(out).to match(
260
+ /\s*first\(\*args,\s+&block\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::Querying\)/
261
+ )
258
262
  elsif RUBY_VERSION >= '2.4.4'
259
263
  expect(out).to match(/\sfirst\(\*arg.*?\)\s+User/)
260
264
  elsif RUBY_VERSION >= '1.9'
@@ -272,6 +276,10 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
272
276
  expect(out).to match(
273
277
  /\sprimary_key\(.*?\)\s+#<Class:\w+>\s\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
274
278
  )
279
+ elsif RUBY_VERSION >= '2.7.0'
280
+ expect(out).to match(
281
+ /\sprimary_key\(.*?\)\s+.+Class.+\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
282
+ )
275
283
  elsif RUBY_VERSION >= '2.4.4'
276
284
  expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
277
285
  else
@@ -286,7 +294,11 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
286
294
  else
287
295
  if RUBY_PLATFORM == 'java'
288
296
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
289
- elsif RUBY_VERSION >= '2.4.4'
297
+ elsif RUBY_VERSION >= '2.7.0'
298
+ expect(out).to match(
299
+ /\svalidate\(\*args.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveModel::Validations::ClassMethods\)/
300
+ )
301
+ elsif RUBY_VERSION >= '2.4.4'
290
302
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
291
303
  else
292
304
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'sequel_helper'
3
+
4
+ RSpec.describe 'AmazingPrint/Sequel', skip: -> { !ExtVerifier.has_sequel? }.call do
5
+ before do
6
+ @ap = AmazingPrint::Inspector.new plain: true, sort_keys: true
7
+ @user1 = SequelUser.new first_name: 'Jeremy', last_name: 'Evans'
8
+ @user2 = SequelUser.new first_name: 'Sequel', last_name: 'Five'
9
+ end
10
+
11
+ it 'display single record' do
12
+ out = @ap.awesome(@user1)
13
+ str = <<~EOS.strip
14
+ #<SequelUser:placeholder_id> {
15
+ :first_name => "Jeremy",
16
+ :last_name => "Evans"
17
+ }
18
+ EOS
19
+ expect(out).to be_similar_to(str)
20
+ end
21
+
22
+ it 'display multiple records' do
23
+ out = @ap.awesome([@user1, @user2])
24
+ str = <<~EOS.strip
25
+ [
26
+ [0] #<SequelUser:placeholder_id> {
27
+ :first_name => "Jeremy",
28
+ :last_name => "Evans"
29
+ },
30
+ [1] #<SequelUser:placeholder_id> {
31
+ :first_name => "Sequel",
32
+ :last_name => "Five"
33
+ }
34
+ ]
35
+ EOS
36
+ expect(out).to be_similar_to(str)
37
+ end
38
+
39
+ it 'does not crash if on Sequel::Model' do
40
+ out = @ap.awesome(::Sequel::Model)
41
+ expect(out).to be_similar_to("Sequel::Model < Object")
42
+ end
43
+ end
data/spec/methods_spec.rb CHANGED
@@ -33,6 +33,38 @@ RSpec.describe 'Single method' do
33
33
  expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35minclude?\e[0m\e[0;37m(arg1)\e[0m")
34
34
  end
35
35
 
36
+ it 'plain: should handle a method with one required keyword argument' do
37
+ class A
38
+ def one(foo:); end
39
+ end
40
+ method = A.new.method(:one)
41
+ expect(method.ai(plain: true)).to eq('A#one(foo:)')
42
+ end
43
+
44
+ it 'color: should handle a method with one required keyword argument' do
45
+ class A
46
+ def one(foo:); end
47
+ end
48
+ method = A.new.method(:one)
49
+ expect(method.ai).to eq("\e[1;33mA\e[0m#\e[0;35mone\e[0m\e[0;37m(foo:)\e[0m")
50
+ end
51
+
52
+ it 'plain: should handle a method with one required and one optional keyword arguments' do
53
+ class A
54
+ def one(foo:, bar: 'baz'); end
55
+ end
56
+ method = A.new.method(:one)
57
+ expect(method.ai(plain: true)).to eq('A#one(foo:, *bar:)')
58
+ end
59
+
60
+ it 'color: should handle a method with one required and one optional keyword arguments' do
61
+ class A
62
+ def one(foo:, bar: 'baz'); end
63
+ end
64
+ method = A.new.method(:one)
65
+ expect(method.ai).to eq("\e[1;33mA\e[0m#\e[0;35mone\e[0m\e[0;37m(foo:, *bar:)\e[0m")
66
+ end
67
+
36
68
  it 'plain: should handle a method with two arguments' do
37
69
  method = ''.method(:tr)
38
70
  expect(method.ai(plain: true)).to eq('String#tr(arg1, arg2)')
@@ -0,0 +1,16 @@
1
+ if ExtVerifier.has_sequel?
2
+ # Establish connection to in-memory SQLite DB
3
+ DB = RUBY_PLATFORM == 'java' ? Sequel.connect('jdbc:sqlite::memory:') : Sequel.sqlite
4
+
5
+ # Create the users table
6
+ DB.create_table :sequel_users do
7
+ primary_key :id
8
+ String :first_name
9
+ String :last_name
10
+ TrueClass :admin
11
+ DateTime :created_at
12
+ end
13
+
14
+ # Create models
15
+ class SequelUser < Sequel::Model; end
16
+ end
data/spec/spec_helper.rb CHANGED
@@ -35,6 +35,7 @@ ExtVerifier.require_dependencies!(
35
35
  mongo_mapper
36
36
  ripple nobrainer
37
37
  ostruct
38
+ sequel
38
39
  ]
39
40
  )
40
41
  require 'nokogiri'
@@ -33,6 +33,11 @@ module ExtVerifier
33
33
  defined?(NoBrainer)
34
34
  end
35
35
  module_function :has_nobrainer?
36
+
37
+ def has_sequel?
38
+ defined?(::Sequel::Model)
39
+ end
40
+ module_function :has_sequel?
36
41
  end
37
42
 
38
43
  RSpec.configure do |config|
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazing_print
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dvorkin
8
- - Kevin McCormack
8
+ - Kevin McCormackPatrik Wenger
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-03 00:00:00.000000000 Z
12
+ date: 2020-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: appraisal
@@ -146,10 +146,12 @@ files:
146
146
  - spec/ext/nokogiri_spec.rb
147
147
  - spec/ext/ostruct_spec.rb
148
148
  - spec/ext/ripple_spec.rb
149
+ - spec/ext/sequel_spec.rb
149
150
  - spec/formats_spec.rb
150
151
  - spec/methods_spec.rb
151
152
  - spec/misc_spec.rb
152
153
  - spec/objects_spec.rb
154
+ - spec/sequel_helper.rb
153
155
  - spec/spec_helper.rb
154
156
  - spec/support/active_record_data.rb
155
157
  - spec/support/active_record_data/3_2_diana.txt
@@ -210,6 +212,7 @@ test_files:
210
212
  - spec/ext/ostruct_spec.rb
211
213
  - spec/ext/mongoid_spec.rb
212
214
  - spec/ext/ripple_spec.rb
215
+ - spec/ext/sequel_spec.rb
213
216
  - spec/ext/active_support_spec.rb
214
217
  - spec/ext/nokogiri_spec.rb
215
218
  - spec/ext/mongo_mapper_spec.rb
@@ -240,4 +243,5 @@ test_files:
240
243
  - spec/support/rails_versions.rb
241
244
  - spec/support/active_record_data.rb
242
245
  - spec/support/ext_verifier.rb
246
+ - spec/sequel_helper.rb
243
247
  - spec/misc_spec.rb