diff --git a/Appraisals b/Appraisals index 82d15ad..e67c4b0 100644 --- a/Appraisals +++ b/Appraisals @@ -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 diff --git a/lib/awesome_print/formatters/ext/mongo_mapper_association_formatter.rb b/lib/awesome_print/formatters/ext/mongo_mapper_association_formatter.rb deleted file mode 100644 index ff0915f..0000000 --- a/lib/awesome_print/formatters/ext/mongo_mapper_association_formatter.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../base_formatter' - -module AwesomePrint - module Formatters - class MongoMapperClassFormatter < BaseFormatter - - formatter_for :mongo_mapper_association - - def self.formattable?(object) - defined?(::MongoMapper) && object.is_a?(::MongoMapper::Plugins::Associations::Base) - end - - def format(object) - if @options[:raw] - return Formatters::ObjectFormatter.new(@inspector).format(object) - end - - if !defined?(::ActiveSupport::OrderedHash) - return Formatters::SimpleFormatter.new(@inspector).format(object.inspect.to_s) - end - - association = object.class.name.split('::').last.titleize.downcase.sub(/ association$/, '') - association = "embeds #{association}" if object.embeddable? - class_name = object.class_name - - "#{colorize(association, :assoc)} #{colorize(class_name, :class)}" - end - - end - end -end diff --git a/lib/awesome_print/formatters/ext/mongo_mapper_class_formatter.rb b/lib/awesome_print/formatters/ext/mongo_mapper_class_formatter.rb deleted file mode 100644 index 7e2b398..0000000 --- a/lib/awesome_print/formatters/ext/mongo_mapper_class_formatter.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../base_formatter' - -module AwesomePrint - module Formatters - class MongoMapperClassFormatter < BaseFormatter - - formatter_for :mongo_mapper_class - - def self.formattable?(object) - defined?(::MongoMapper) && - object.is_a?(Class) && - (object.ancestors & [::MongoMapper::Document, ::MongoMapper::EmbeddedDocument]).size > 0 - end - - def format(object) - unless defined?(::ActiveSupport::OrderedHash) && object.respond_to?(:keys) - return Formatters::SimpleFormatter.new(@inspector).format(object.inspect.to_s) - end - - data = object.keys.sort.inject(::ActiveSupport::OrderedHash.new) do |hash, c| - hash[c.first] = (c.last.type || 'undefined').to_s.underscore.to_sym - hash - end - - # Add in associations - if @options[:mongo_mapper][:show_associations] - object.associations.each { |name, assoc| data[name.to_s] = assoc } - end - - sf = Formatters::SimpleFormatter.new(@inspector) - - [ - "class #{sf.format(object.to_s, :class)}", - "< #{sf.format(object.superclass.to_s, :class)}", - Formatters::HashFormatter.new(@inspector).format(data) - ].join(' ') - end - - end - end -end diff --git a/lib/awesome_print/formatters/ext/mongo_mapper_instance_formatter.rb b/lib/awesome_print/formatters/ext/mongo_mapper_instance_formatter.rb deleted file mode 100644 index fc208d2..0000000 --- a/lib/awesome_print/formatters/ext/mongo_mapper_instance_formatter.rb +++ /dev/null @@ -1,67 +0,0 @@ -require_relative '../base_formatter' - -module AwesomePrint - module Formatters - class MongoMapperInstanceFormatter < BaseFormatter - - formatter_for :mongo_mapper_instance - - def self.formattable?(object) - defined?(::MongoMapper) && - (object.is_a?(::MongoMapper::Document) || - object.is_a?(::MongoMapper::EmbeddedDocument)) - end - - def initialize(inspector) - super(inspector) - - @options[:color][:assoc] ||= :greenish - @options[:mongo_mapper] ||= { - show_associations: false, # Display association data for MongoMapper documents and classes. - inline_embedded: false # Display embedded associations inline with MongoMapper documents. - } - end - - # Format MongoMapper instance object. - # - # NOTE: by default only instance attributes (i.e. keys) are shown. To format - # MongoMapper instance as regular object showing its instance variables and - # accessors use :raw => true option: - # - # ap record, :raw => true - # - #------------------------------------------------------------------------------ - def format(object) - if @options[:raw] - return Formatters::ObjectFormatter.new(@inspector).format(object) - end - - if !defined?(::ActiveSupport::OrderedHash) - return Formatters::SimpleFormatter.new(@inspector).format(object.inspect.to_s) - end - - data = object.keys.keys.sort_by { |k| k }.inject(::ActiveSupport::OrderedHash.new) do |hash, name| - hash[name] = object[name] - hash - end - - # Add in associations - if @options[:mongo_mapper][:show_associations] - object.associations.each do |name, assoc| - data[name.to_s] = if @options[:mongo_mapper][:inline_embedded] and assoc.embeddable? - object.send(name) - else - assoc - end - end - end - - label = object.to_s - label = "#{colorize('embedded', :assoc)} #{label}" if object.is_a?(::MongoMapper::EmbeddedDocument) - - "#{label} " << Formatters::HashFormatter.new(@inspector).format(data) - end - - end - end -end diff --git a/spec/formatters/ext/mongo_mapper_spec.rb b/spec/formatters/ext/mongo_mapper_spec.rb deleted file mode 100644 index 55cb4eb..0000000 --- a/spec/formatters/ext/mongo_mapper_spec.rb +++ /dev/null @@ -1,261 +0,0 @@ -require 'spec_helper' - -RSpec.describe 'AwesomePrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_mapper? }.call do - if ExtVerifier.has_mongo_mapper? - before :all do - class MongoUser - include MongoMapper::Document - - key :first_name, String - key :last_name, String - end - end - - after :all do - Object.instance_eval { remove_const :MongoUser } - Object.instance_eval { remove_const :Chamelion } - end - end - - before do - @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true) - end - - describe 'with the raw option set to true' do - # before { @ap.options[:raw] = true } - before { @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true, raw: true) } - - it 'should print class instance' do - user = MongoUser.new(first_name: 'Al', last_name: 'Capone') - - out = @ap.send(:awesome, user) - out.gsub!(/#\/, 'AWESOME_PRINT_PROC_STUB') - out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')") - - str = if MongoMapper::Version >= '0.13' - <<-EOS.strip -# AWESOME_PRINT_PROC_STUB - }, - attr_accessor :type = ObjectId < Object - > - ], - @__mm_keys = { - "_id" => # AWESOME_PRINT_PROC_STUB - }, - attr_accessor :type = ObjectId < Object - >, - "first_name" => #, - "last_name" => # - }, - @__mm_pre_cast = { - "first_name" => "Al", - "last_name" => "Capone" - }, - @_dynamic_attributes = {}, - @_new = true, - attr_accessor :_id = BSON::ObjectId('123456789'), - attr_accessor :attributes = nil, - attr_accessor :first_name = "Al", - attr_accessor :last_name = "Capone", - attr_reader :changed_attributes = { - "first_name" => nil, - "last_name" => nil - } -> - EOS - else - <<-EOS.strip -# nil, - "last_name" => nil - }, - attr_reader :first_name_before_type_cast = "Al", - attr_reader :last_name_before_type_cast = "Capone" -> - EOS - end - expect(out).to be_similar_to(str) - end - - it 'should print the class' do - expect(@ap.send(:awesome, MongoUser)).to eq <<-EOS.strip -class MongoUser < Object { - "_id" => :object_id, - "first_name" => :string, - "last_name" => :string -} - EOS - end - - it 'should print the class when type is undefined' do - class Chamelion - include MongoMapper::Document - key :last_attribute - end - - expect(@ap.send(:awesome, Chamelion)).to eq <<-EOS.strip -class Chamelion < Object { - "_id" => :object_id, - "last_attribute" => :undefined -} - EOS - end - end - - describe 'with associations' do - - if ExtVerifier.has_mongo_mapper? - before :all do - class Child - include MongoMapper::EmbeddedDocument - key :data - end - - class Sibling - include MongoMapper::Document - key :title - end - - class Parent - include MongoMapper::Document - key :name - - one :child - one :sibling - end - end - end - - describe 'with show associations turned off (default)' do - it 'should render the class as normal' do - expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip -class Parent < Object { - "_id" => :object_id, - "name" => :undefined -} - EOS - end - - it 'should render an instance as normal' do - parent = Parent.new(name: 'test') - out = @ap.send(:awesome, parent) - str = <<-EOS.strip -# { - "_id" => placeholder_bson_id, - "name" => "test" -} - EOS - expect(out).to be_similar_to(str) - end - end - - describe 'with show associations turned on and inline embedded turned off' do - before :each do - @ap = AwesomePrint::Inspector.new(plain: true, mongo_mapper: { show_associations: true }) - end - - it 'should render the class with associations shown' do - expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip -class Parent < Object { - "_id" => :object_id, - "name" => :undefined, - "child" => embeds one Child, - "sibling" => one Sibling -} - EOS - end - - it 'should render an instance with associations shown' do - parent = Parent.new(name: 'test') - out = @ap.send(:awesome, parent) - str = <<-EOS.strip -# { - "_id" => placeholder_bson_id, - "name" => "test", - "child" => embeds one Child, - "sibling" => one Sibling -} - EOS - expect(out).to be_similar_to(str) - end - end - - describe 'with show associations turned on and inline embedded turned on' do - before :each do - @ap = AwesomePrint::Inspector.new(plain: true, - mongo_mapper: { - show_associations: true, - inline_embedded: true - } - ) - end - - it 'should render an instance with associations shown and embeds there' do - parent = Parent.new(name: 'test', child: Child.new(data: 5)) - out = @ap.send(:awesome, parent) - str = <<-EOS.strip -# { - "_id" => placeholder_bson_id, - "name" => "test", - "child" => embedded # { - "_id" => placeholder_bson_id, - "data" => 5 - }, - "sibling" => one Sibling -} - EOS - expect(out).to be_similar_to(str) - end - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e806a03..cd83c53 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,8 +28,6 @@ ExtVerifier.require_dependencies!( action_view active_support/all mongoid - mongo_mapper - ripple nobrainer ) ) require 'nokogiri' diff --git a/spec/support/ext_verifier.rb b/spec/support/ext_verifier.rb index 36597ca..adc2237 100644 --- a/spec/support/ext_verifier.rb +++ b/spec/support/ext_verifier.rb @@ -19,21 +19,6 @@ module ExtVerifier defined?(Mongoid) end module_function :has_mongoid? - - def has_mongo_mapper? - defined?(MongoMapper) - end - module_function :has_mongo_mapper? - - def has_ripple? - defined?(Ripple) - end - module_function :has_ripple? - - def has_nobrainer? - defined?(NoBrainer) - end - module_function :has_nobrainer? end RSpec.configure do |config| diff --git a/spec/support/rails_versions.rb b/spec/support/rails_versions.rb index c75a591..f1f1172 100644 --- a/spec/support/rails_versions.rb +++ b/spec/support/rails_versions.rb @@ -1,6 +1,6 @@ module RailsVersions def rails_version - Gem::Version.new(Rails::VERSION::STRING) + Gem::Version.new(::Rails::VERSION::STRING) end def rails_5_2?