Class: FReCon::DumpController

Inherits:
Object
  • Object
show all
Defined in:
lib/frecon/controllers/dump_controller.rb

Overview

Public: The Dump controller.

Class Method Summary collapse

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.



47
48
49
# File 'lib/frecon/controllers/dump_controller.rb', line 47

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
36
37
# File 'lib/frecon/controllers/dump_controller.rb', line 19

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