Class: SibuApidae::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/sibu_apidae.rb

Class Method Summary collapse

Class Method Details

.import_pages(site_id) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sibu_apidae.rb', line 33

def self.import_pages(site_id)
  conf = Rails.application.config.sibu_apidae
  if conf && conf.key?(:obj_path) && conf.key?(:obj_sections) && conf.key?(:supported_types)
    Apidae::Obj.all.each do |obj|
      if conf[:supported_types].include?(obj.apidae_type)
        obj_path = Rails.application.config.sibu_apidae[:obj_path].call(obj)
        obj_page = Sibu::Page.where(site_id: site_id, path: obj_path).first
        unless obj_page
          p = Sibu::Page.new(name: obj.title, site_id: site_id, path: obj_path, title: obj.title,
                             description: obj.short_desc)
          p.sections = Rails.application.config.sibu_apidae[:obj_sections].call(obj)
          p.save!
        end
      end
    end
  else
    puts "Please provide a valid configuration for the sibu_apidae gem (obj_path and obj_sections procs are required)"
  end
end