Class: FReCon::DumpController
- Defined in:
- lib/frecon/controllers/dump_controller.rb
Overview
Public: The Dump controller.
Class Method Summary collapse
-
.dump_compliant_name(model) ⇒ Object
Public: Converts a Model’s name to a dump-compliant name.
-
.full(params) ⇒ Object
Public: Creates a dump.
Class Method Details
.dump_compliant_name(model) ⇒ Object
Public: Converts a Model’s name to a dump-compliant name.
Examples
DumpController.dump_compliant_name(FReCon::Team)
# => "teams"
Returns a dump-compliant string.
45 46 47 |
# File 'lib/frecon/controllers/dump_controller.rb', line 45 def self.dump_compliant_name(model) model.name.gsub(/FReCon::/, "").downcase.pluralize end |
.full(params) ⇒ Object
Public: Creates a dump.
Returns a String containing a dump of the database.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/frecon/controllers/dump_controller.rb', line 19 def self.full(params) dump = {} ordered_descendants = Model.descendants.sort_by do |model| id_fields = model.fields.keys.select do |attribute| attribute.ends_with?("_id") && attribute != "_id" end [id_fields.count, dump_compliant_name(model)] end ordered_descendants.each do |child| dump[dump_compliant_name(child)] = child.all end dump.to_json end |