diff --git a/lib/awesome_print/ext/nobrainer.rb b/lib/awesome_print/ext/nobrainer.rb deleted file mode 100644 index 109a656..0000000 --- a/lib/awesome_print/ext/nobrainer.rb +++ /dev/null @@ -1,52 +0,0 @@ -# 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 NoBrainer - - def self.included(base) - base.send :alias_method, :cast_without_nobrainer, :cast - base.send :alias_method, :cast, :cast_with_nobrainer - end - - # Add NoBrainer class names to the dispatcher pipeline. - #------------------------------------------------------------------------------ - def cast_with_nobrainer(object, type) - cast = cast_without_nobrainer(object, type) - if defined?(::NoBrainer::Document) - if object.is_a?(Class) && object < ::NoBrainer::Document - cast = :nobrainer_class - elsif object.is_a?(::NoBrainer::Document) - cast = :nobrainer_document - end - end - cast - end - - # Format NoBrainer class object. - #------------------------------------------------------------------------------ - def awesome_nobrainer_class(object) - name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}" - data = Hash[object.fields.map do |field, options| - [field, (options[:type] || Object).to_s.underscore.to_sym] - end] - - name = "class #{awesome_simple(object.to_s, :class)}" - base = "< #{awesome_simple(object.superclass.to_s, :class)}" - - [name, base, awesome_hash(data)].join(' ') - end - - # Format NoBrainer Document object. - #------------------------------------------------------------------------------ - def awesome_nobrainer_document(object) - data = object.inspectable_attributes.symbolize_keys - data = { errors: object.errors, attributes: data } if object.errors.present? - "#{object} #{awesome_hash(data)}" - end - end -end - -AwesomePrint::Formatter.send(:include, AwesomePrint::NoBrainer) diff --git a/lib/awesome_print/ext/ripple.rb b/lib/awesome_print/ext/ripple.rb deleted file mode 100644 index e2d243f..0000000 --- a/lib/awesome_print/ext/ripple.rb +++ /dev/null @@ -1,71 +0,0 @@ -# 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 Ripple - - def self.included(base) - base.send :alias_method, :cast_without_ripple, :cast - base.send :alias_method, :cast, :cast_with_ripple - end - - # Add Ripple class names to the dispatcher pipeline. - #------------------------------------------------------------------------------ - def cast_with_ripple(object, type) - cast = cast_without_ripple(object, type) - return cast if !defined?(::Ripple) - - if object.is_a?(::Ripple::AttributeMethods) # Module used to access attributes across documents and embedded documents - cast = :ripple_document_instance - elsif object.is_a?(::Ripple::Properties) # Used to access property metadata on Ripple classes - cast = :ripple_document_class - end - cast - end - - private - - # Format Ripple instance object. - # - # NOTE: by default only instance attributes are shown. To format a Ripple document instance - # as a regular object showing its instance variables and accessors use :raw => true option: - # - # ap document, :raw => true - # - #------------------------------------------------------------------------------ - def awesome_ripple_document_instance(object) - return object.inspect if !defined?(::ActiveSupport::OrderedHash) - return awesome_object(object) if @options[:raw] - exclude_assoc = @options[:exclude_assoc] or @options[:exclude_associations] - - data = object.attributes.inject(::ActiveSupport::OrderedHash.new) do |hash, (name, value)| - hash[name.to_sym] = object.send(name) - hash - end - - unless exclude_assoc - data = object.class.embedded_associations.inject(data) do |hash, assoc| - hash[assoc.name] = object.get_proxy(assoc) # Should always be array or Ripple::EmbeddedDocument for embedded associations - hash - end - end - - "#{object} " << awesome_hash(data) - end - - # Format Ripple class object. - #------------------------------------------------------------------------------ - def awesome_ripple_document_class(object) - return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties) - - name = "class #{awesome_simple(object.to_s, :class)}" - base = "< #{awesome_simple(object.superclass.to_s, :class)}" - - [name, base, awesome_hash(data)].join(' ') - end - end -end - -AwesomePrint::Formatter.send(:include, AwesomePrint::Ripple) diff --git a/lib/awesome_print/ext/action_view.rb b/lib/awesome_print/formatters/ext/action_view.rb similarity index 100% rename from lib/awesome_print/ext/action_view.rb rename to lib/awesome_print/formatters/ext/action_view.rb diff --git a/lib/awesome_print/ext/active_record.rb b/lib/awesome_print/formatters/ext/active_record.rb similarity index 100% rename from lib/awesome_print/ext/active_record.rb rename to lib/awesome_print/formatters/ext/active_record.rb diff --git a/lib/awesome_print/ext/active_support.rb b/lib/awesome_print/formatters/ext/active_support.rb similarity index 100% rename from lib/awesome_print/ext/active_support.rb rename to lib/awesome_print/formatters/ext/active_support.rb diff --git a/lib/awesome_print/ext/mongo_mapper.rb b/lib/awesome_print/formatters/ext/mongo_mapper.rb similarity index 100% rename from lib/awesome_print/ext/mongo_mapper.rb rename to lib/awesome_print/formatters/ext/mongo_mapper.rb diff --git a/lib/awesome_print/ext/mongoid.rb b/lib/awesome_print/formatters/ext/mongoid.rb similarity index 100% rename from lib/awesome_print/ext/mongoid.rb rename to lib/awesome_print/formatters/ext/mongoid.rb diff --git a/lib/awesome_print/ext/nokogiri.rb b/lib/awesome_print/formatters/ext/nokogiri.rb similarity index 100% rename from lib/awesome_print/ext/nokogiri.rb rename to lib/awesome_print/formatters/ext/nokogiri.rb diff --git a/lib/awesome_print/ext/sequel.rb b/lib/awesome_print/formatters/ext/sequel.rb similarity index 100% rename from lib/awesome_print/ext/sequel.rb rename to lib/awesome_print/formatters/ext/sequel.rb diff --git a/spec/methods_spec.rb b/spec/formatters/methods_spec.rb similarity index 100% rename from spec/methods_spec.rb rename to spec/formatters/methods_spec.rb diff --git a/spec/objects_spec.rb b/spec/formatters/objects_spec.rb similarity index 100% rename from spec/objects_spec.rb rename to spec/formatters/objects_spec.rb