require "sibu_apidae/version" module SibuApidae class ApidaeList attr_accessor :selection_id def initialize(init_hash) @selection_id = init_hash["selection"] end def results if selection_id.blank? Apidae::Selection.first.objects.limit(2).includes(:town) else Apidae::Selection.find_by_apidae_id(selection_id).objects.includes(:town) end end end class ApidaeResult attr_accessor :obj_id def initialize(init_hash) @obj_id = init_hash["obj_id"] end def obj Apidae::Obj.find_by_apidae_id(obj_id) || Apidae::Obj.first end end class Helper 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) 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 end end