Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awesome print 2.0 #350

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2105efb
New approach for awesomeprint -- this uses a factory pattern to regis…
imajes Jan 22, 2019
3738676
splits spec, formalizes output for string/symbol
imajes Jan 22, 2019
bb5e751
Further fix tests, set some formatters as core (too generic) and clea…
imajes Jan 22, 2019
7eaf2ca
remove extraneous formatters we don't want to continue supporting (ri…
imajes Jan 22, 2019
102d254
Remove extraneous/superflous copyright duplicates
imajes Jan 22, 2019
32e7efd
Remove rails 2.x plugin style accessor
imajes Jan 22, 2019
856f8c4
Remove the require 'ap' mechanic.
imajes Jan 22, 2019
e2bc9c2
not going to support 1.x ruby anymore
imajes Jan 22, 2019
f0ed2e2
Make external formatters (Rails, etc) format as expected)
imajes Jan 22, 2019
7f7c0bf
Fix unbound methods
imajes Jan 22, 2019
bf1ff13
Fix more tests
imajes Jan 22, 2019
1e5c6c9
Fix nokogiri errors
imajes Jan 22, 2019
751d6c9
fix load order...
imajes Jan 22, 2019
e2acfab
Remove extra puts in spec.
imajes Jan 23, 2019
a45b2ac
Fix typo, and formally include date as a type here
imajes Jan 23, 2019
5eb57ad
Remove no longer required active record stubs
imajes Jan 23, 2019
dbe414d
make debug reporting clearer, though this needs extracting
imajes Jan 23, 2019
7ace70b
Include other obvious formatters
imajes Jan 23, 2019
da29f74
hack to support finding AR::B classes
imajes Jan 23, 2019
52933a1
remove references to older rubies
imajes Jan 23, 2019
1ff1206
Fix mongoid concerns
imajes Jan 23, 2019
fe0786d
Remove mongomapper support.
imajes Jan 23, 2019
976e4a5
Make this into a 2.0.0-pre gem
imajes Jan 23, 2019
87850a2
express the version correctly
imajes Jan 23, 2019
8242bdf
Fix loadpath issues that became apparent outside of the spec suite
imajes Jan 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ Gemfile.lock
# PROJECT::RBENV
.ruby-gemset
.awesome-print/
.byebug_history
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--format Fuubar
--color
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ matrix:
include:
- rvm: ruby-head
env: RUBYOPT="--enable-frozen-string-literal"
# allow_failures:
# - rvm: ruby-head
allow_failures:
- rvm: ruby-head

addons:
code_climate:
Expand Down
17 changes: 0 additions & 17 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,3 @@ end
appraise 'mongoid-6.0' do
gem 'mongoid', '~> 6.0.0'
end

# appraise 'mongo_mapper' do
# gem 'mongo_mapper'
# end
#
# appraise 'ripple' do
# gem 'tzinfo'
# gem 'ripple'
# end
#
# appraise 'nobrainer' do
# gem 'nobrainer'
#
# # When activesupport 5 was released, it required ruby 2.2.2 as a minimum.
# # Locking this down to 4.2.6 allows our Ruby 1.9 tests to keep working.
# gem 'activesupport', '4.2.6', :platforms => :ruby_19
# end
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## master (unreleased)

## 2.0.0-pre
- Massive overhaul in the way formatters work. Now they are registered with a factory pattern, which includes
a simple method to determine if that formatter can handle the content. [@imajes]
- Remove support for mongo mapper, and ruby pre 2.x [@imajes]
- It's probably faster? :)
- Fixes spec suite to properly work via travis, gets a clean build [@imajes, others]
- Adds support for ActiveModel::Errors [@dshinzie] - [#301]
- removes use of `strip_heredoc` from specs as it's a rails dep [@kstephens] - [#303]
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,11 @@ AwesomePrint.defaults = {
```

## Versioning

AwesomePrint follows the [Semantic Versioning](http://semver.org/) standard.

### Contributing ###
See [CONTRIBUTING.md](CONTRIBUTING.md) for information.

### License ###
Copyright (c) 2010-2016 Michael Dvorkin and contributors

http://www.dvorkin.net

%w(mike dvorkin.net) * "@" || "twitter.com/mid"

Released under the MIT license. See LICENSE file for details.

[gem_version_badge]: https://img.shields.io/gem/v/awesome_print.svg?style=flat
[gem_downloads_badge]: http://img.shields.io/gem/dt/awesome_print.svg?style=flat
Expand Down
11 changes: 3 additions & 8 deletions awesome_print.gemspec
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------

$:.push File.expand_path('../lib', __FILE__)
require 'awesome_print/version'

Gem::Specification.new do |s|
s.name = 'awesome_print'
s.version = AwesomePrint.version
s.authors = 'Michael Dvorkin'
s.authors = 'Michael Dvorkin, James Cox & contributors'
s.date = Time.now.strftime('%Y-%m-%d')
s.email = 'mike@dvorkin.net'
s.homepage = 'https://github.com/awesome-print/awesome_print'
s.summary = 'Pretty print Ruby objects with proper indentation and colors'
s.description = 'Great Ruby debugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins'
Expand All @@ -24,7 +17,9 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']

s.add_development_dependency 'rspec', '>= 3.0.0'
s.add_development_dependency 'fuubar'
s.add_development_dependency 'appraisal'
s.add_development_dependency 'byebug'
s.add_development_dependency 'fakefs', '>= 0.2.1'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'nokogiri', '>= 1.6.5'
Expand Down
1 change: 0 additions & 1 deletion init.rb

This file was deleted.

6 changes: 1 addition & 5 deletions lib/ap.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
#
# Keeping this for backwards compatibility to allow
# require "ap"
#
require File.dirname(__FILE__) + '/awesome_print'

59 changes: 22 additions & 37 deletions lib/awesome_print.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
#
# AwesomePrint might be loaded implicitly through ~/.irbrc or ~/.pryrc
# so do nothing for subsequent requires.
#
unless defined?(AwesomePrint::Inspector)
%w(awesome_method_array string method object class kernel).each do |file|
require "awesome_print/core_ext/#{file}"
end
require 'awesome_print/formatters'
require 'awesome_print/inspector'
require 'awesome_print/formatter'
require 'awesome_print/version'

module AwesomePrint
class << self

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use extend self here instead of the singleton class trick.

attr_accessor :defaults, :force_colors

require 'awesome_print/custom_defaults'
require 'awesome_print/inspector'
require 'awesome_print/formatter'
require 'awesome_print/version'
require 'awesome_print/core_ext/logger' if defined?(Logger)
#
# Load the following under normal circumstances as well as in Rails
# console when required from ~/.irbrc or ~/.pryrc.
#
require 'awesome_print/ext/active_record' if defined?(ActiveRecord) || AwesomePrint.rails_console?
require 'awesome_print/ext/active_support' if defined?(ActiveSupport) || AwesomePrint.rails_console?
#
# Load remaining extensions.
#
if defined?(ActiveSupport.on_load)
ActiveSupport.on_load(:action_view) do
require 'awesome_print/ext/action_view'
# Class accessor to force colorized output (ex. forked subprocess where TERM
# might be dumb).
#---------------------------------------------------------------------------

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably way overkill for this PR, but may make sense to look into YARDoc later as a standard documentation framework.

def force_colors!(value = true)
@force_colors = value
end
end
require 'awesome_print/ext/mongo_mapper' if defined?(MongoMapper)
require 'awesome_print/ext/mongoid' if defined?(Mongoid)
require 'awesome_print/ext/nokogiri' if defined?(Nokogiri)
require 'awesome_print/ext/nobrainer' if defined?(NoBrainer)
require 'awesome_print/ext/ripple' if defined?(Ripple)
require 'awesome_print/ext/sequel' if defined?(Sequel)
require 'awesome_print/ext/ostruct' if defined?(OpenStruct)
end

# CORE EXTENSIONS... now that ap is loaded, inject awesome behavior into ruby
%w(awesome_method_array string object class kernel logger active_support).each do |file|
require "awesome_print/core_ext/#{file}"
end

# FIXME: not sure we need these, but..
require 'awesome_print/custom_defaults'

2 changes: 2 additions & 0 deletions lib/awesome_print/colorize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Colorize
# Pick the color and apply it to the given string as necessary.
#------------------------------------------------------------------------------
def colorize(str, type)
# puts "[COLORIZING] - using #{options[:color][type]} for #{type}" if AwesomePrint.debug

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot some commented code here?

str = CGI.escapeHTML(str) if options[:html]
if options[:plain] || !options[:color][type] || !inspector.colorize?
str
Expand Down
7 changes: 7 additions & 0 deletions lib/awesome_print/core_ext/active_support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Colorize Rails logs.
#
if defined?(ActiveSupport::LogSubscriber)
AwesomePrint.force_colors! ActiveSupport::LogSubscriber.colorize_logging
end

6 changes: 0 additions & 6 deletions lib/awesome_print/core_ext/awesome_method_array.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
#
# The following makes it possible to invoke awesome_print while performing
# operations on method arrays, ex:
#
Expand Down
5 changes: 0 additions & 5 deletions lib/awesome_print/core_ext/class.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class Class #:nodoc:
#
# Intercept methods below to inject @__awesome_print__ instance variable
Expand Down
5 changes: 0 additions & 5 deletions lib/awesome_print/core_ext/kernel.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
module Kernel

def ai(options = {})
Expand Down
7 changes: 1 addition & 6 deletions lib/awesome_print/core_ext/logger.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
module AwesomePrint
module Logger

Expand All @@ -16,5 +11,5 @@ def ap(object, level = nil)
end
end

Logger.send(:include, AwesomePrint::Logger)
Logger.send(:include, AwesomePrint::Logger) if defined?(Logger)
ActiveSupport::BufferedLogger.send(:include, AwesomePrint::Logger) if defined?(ActiveSupport::BufferedLogger)
21 changes: 0 additions & 21 deletions lib/awesome_print/core_ext/method.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/awesome_print/core_ext/object.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class Object #:nodoc:
#
# Intercept methods below to inject @__awesome_print__ instance variable
Expand Down
5 changes: 0 additions & 5 deletions lib/awesome_print/core_ext/string.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class String
#
# ANSI color codes:
Expand Down
8 changes: 0 additions & 8 deletions lib/awesome_print/custom_defaults.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module AwesomePrint
class << self
attr_accessor :defaults, :force_colors

# Class accessor to force colorized output (ex. forked subprocess where TERM
# might be dumb).
#---------------------------------------------------------------------------
def force_colors!(value = true)
@force_colors = value
end

def console?
boolean(defined?(IRB) || defined?(Pry))
Expand Down
22 changes: 0 additions & 22 deletions lib/awesome_print/ext/action_view.rb

This file was deleted.

Loading