Sha256: 6d60d7aad6095dcb64c32b300b0345b9c5394e2fa9ff967335d9fed493aaaaa7

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

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, 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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sibu_apidae-0.2.0 lib/sibu_apidae.rb