Copyright (c) 2010 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
Format ActiveRecord class object.
# File lib/ap/mixin/active_record.rb, line 39 39: def awesome_active_record_class(object) 40: if object.respond_to?(:columns) 41: data = object.columns.inject(ActiveSupport::OrderedHash.new) do |hash, c| 42: hash[c.name.to_sym] = c.type 43: hash 44: end 45: "class #{object} < #{object.superclass} " << awesome_hash(data) 46: else 47: object.inspect 48: end 49: end
Format ActiveRecord instance object.
# File lib/ap/mixin/active_record.rb, line 29 29: def awesome_active_record_instance(object) 30: data = object.class.column_names.inject(ActiveSupport::OrderedHash.new) do |hash, name| 31: hash[name.to_sym] = object.send(name) if object.has_attribute?(name) || object.new_record? 32: hash 33: end 34: "#{object} " + awesome_hash(data) 35: end
Add ActiveRecord class names to the dispatcher pipeline.
# File lib/ap/mixin/active_record.rb, line 15 15: def printable_with_active_record(object) 16: printable = printable_without_active_record(object) 17: if printable == :self 18: if object.is_a?(ActiveRecord::Base) 19: printable = :active_record_instance 20: end 21: elsif printable == :class and object.ancestors.include?(ActiveRecord::Base) 22: printable = :active_record_class 23: end 24: printable 25: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.