Class: FReCon::DumpController

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

Class Method Summary collapse

Class Method Details

.dump_compliant_name(model) ⇒ Object



33
34
35
# File 'lib/frecon/controllers/dump_controller.rb', line 33

def self.dump_compliant_name(model)
  model.name.gsub(/FReCon::/, "").downcase.pluralize
end

.full(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/frecon/controllers/dump_controller.rb', line 15

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