mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Added support for awesome printing embedded assocations
This commit is contained in:
parent
66d59020c2
commit
581de0cbeb
1 changed files with 9 additions and 0 deletions
|
@ -38,11 +38,20 @@ module AwesomePrint
|
|||
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.embedded_associations.inject(data) do |hash, assoc|
|
||||
hash[assoc.name] = assoc.load_target
|
||||
hash
|
||||
end
|
||||
end
|
||||
|
||||
"##{object} " << awesome_hash(data)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue