lib/meta_db/dump.rb in meta_db-0.1.1 vs lib/meta_db/dump.rb in meta_db-0.2.0
- old
+ new
@@ -1,31 +1,54 @@
require 'indented_io'
+require 'meta_db/db_object'
+
module MetaDb
- class DbObject
- def dump
+ class DbObject
+ def dump(short = false)
puts self.class.to_s
- dump_attrs
+ dump_attrs(short)
end
- def dump_attrs(*attrs)
+ def dump_attrs(short, *attrs)
attrs = Array(attrs)
attrs = self.class.attrs if attrs.empty?
indent {
for attr in Array(attrs)
value = self.send(attr)
case value
when Array
- puts "#{attr}:"
- indent { value.each { |v| v.dump } }
+ if value.first.is_a?(Symbol)
+ puts "#{attr}: #{value.inspect}"
+ else
+ if short
+ puts "#{attr}: [#{value.map(&:name).join(", ")}]"
+ else
+ puts "#{attr}: "
+ indent { value.each { |v| v.dump } }
+ end
+ end
+ when Hash
+ if short
+ puts "#{attr}: [#{value.values.map(&:name).join(", ")}]"
+ else
+ puts "#{attr}: "
+ indent { value.values.each { |v| v.dump } }
+ end
when DbObject
puts "#{attr}: #{value.name} (#{value.class})"
else
puts "#{attr}: #{self.send(attr).inspect}"
end
end
}
+ end
+ end
+
+ class Constraint < DbObject
+ def dump(short = true)
+ super(short)
end
end
end