/usr/lib/ruby/vendor_ruby/awesome_print/ext/ripple.rb is in ruby-awesome-print 1.6.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | # Copyright (c) 2010-2013 Michael Dvorkin
#
# 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)
data = object.properties.inject(::ActiveSupport::OrderedHash.new) do |hash, (name, defn)|
hash[name.to_sym] = defn.type.to_s.downcase.to_sym
hash
end
"class #{object} < #{object.superclass} " << awesome_hash(data)
end
end
end
AwesomePrint::Formatter.send(:include, AwesomePrint::Ripple)
|