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.
48 49 50 |
# File 'lib/frecon/controllers/dump_controller.rb', line 48 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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/frecon/controllers/dump_controller.rb', line 20 def self.full(params) dump = {} ordered_descendants = Model.descendants.select do |model_or_instance| !!model_or_instance.name end.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 |