Sha256: f8ee26e0fe4b6c76dc22a2ccd75980e3522bd127183e3dba9d9b6ed6e0859b77

Contents?: true

Size: 797 Bytes

Versions: 32

Compression:

Stored size: 797 Bytes

Contents

module RailsConnector

  # @api public
  class LinkList < Array

    def initialize(link_definitions)
      if link_definitions.blank?
        super([])
      else
        super(build_links(link_definitions.map(&:symbolize_keys)))
      end
    end

    # @api public
    def destination_objects
      self.map {|link| link.destination_object}.compact
    end

    private

    def build_links(link_definitions)
      object_ids = link_definitions.map { |link_data| link_data[:destination] }.compact.uniq
      objects = object_ids.empty? ? [] : Obj.find(object_ids)
      link_definitions.each_with_object([]) do |link_data, links|
        link = Link.new(link_data, objects.detect { |o| o && o.id == link_data[:destination] })
        links << link if link.active?
      end
    end

  end

end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
infopark_rails_connector-6.8.0.539.93842523 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.529.114081979 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.518.30999728 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.515.34928522 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.498.46559598 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.480.261594408 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.444.171626367 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.406.131718077 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.356.19698103 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.348.160665197 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.328.4a753fc app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.322.c003f11 app/models/rails_connector/link_list.rb