Class: Adminpanel::DumpGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/adminpanel/dump/dump_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_json_fileObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/adminpanel/dump/dump_generator.rb', line 13

def create_json_file
  resource = name.demodulize.camelize.singularize
  resource = "Adminpanel::#{resource}".classify.constantize
  file_name = resource.to_s.pluralize.demodulize.downcase + '.json'
  puts "dumping #{resource.display_name.pluralize(I18n.default_locale)} into db/#{file_name}"

  create_file "db/#{file_name}" do
    resource.all.to_a.map{|o| o.attributes}.to_json
  end
  inject_into_seeds(resource, file_name)
end