Format NoBrainer class object.
# File lib/awesome_print/ext/no_brainer.rb, line 30 def awesome_no_brainer_class(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:fields) # We want id first data = object.fields.sort_by { |key| key[0] == :id ? '_id' : key[0].to_s }.inject(::ActiveSupport::OrderedHash.new) do |hash, c| hash[c[0]] = :object hash end "class #{object} < #{object.superclass} " << awesome_hash(data) end
Format NoBrainer Document object.
# File lib/awesome_print/ext/no_brainer.rb, line 43 def awesome_no_brainer_document(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) data = object.attributes.sort_by { |key| key }.inject(::ActiveSupport::OrderedHash.new) do |hash, c| hash[c[0].to_sym] = c[1] hash end if !object.errors.empty? data = {:errors => object.errors, :attributes => data} end "#{object} #{awesome_hash(data)}" end
Add NoBrainer class names to the dispatcher pipeline.
# File lib/awesome_print/ext/no_brainer.rb, line 16 def cast_with_no_brainer(object, type) cast = cast_without_no_brainer(object, type) if defined?(::NoBrainer::Document) if object.is_a?(Class) && object.ancestors.include?(::NoBrainer::Document) cast = :no_brainer_class elsif object.class.ancestors.include?(::NoBrainer::Document) cast = :no_brainer_document end end cast end
Generated with the Darkfish Rdoc Generator 2.