lib/dbf/schema.rb in dbf-2.0.13 vs lib/dbf/schema.rb in dbf-3.0.0
- old
+ new
@@ -19,17 +19,31 @@
# t.column :is_active, :boolean
# t.column :age, :integer
# t.column :notes, :text
# end
#
+ # @param [Symbol] format Valid options are :activerecord and :json
# @return [String]
- def schema
+ def schema(format = :activerecord)
+ supported_formats = [:activerecord, :json]
+ if supported_formats.include?(format)
+ send "#{format}_schema"
+ else
+ raise ArgumentError
+ end
+ end
+
+ def activerecord_schema
s = "ActiveRecord::Schema.define do\n"
- s << " create_table \"#{File.basename(@data.path, ".*")}\" do |t|\n"
+ s << " create_table \"#{File.basename(@data.path, '.*')}\" do |t|\n"
columns.each do |column|
s << " t.column #{column.schema_definition}"
end
s << " end\nend"
s
+ end
+
+ def json_schema
+ columns.map(&:to_hash).to_json
end
end
end