Sha256: 349aaf353bfed3bfd2240281886da23cfea23ac8d10fe1d0f7c3cb13d0ae5098

Contents?: true

Size: 772 Bytes

Versions: 21

Compression:

Stored size: 772 Bytes

Contents

module RailsConnector

  class LinkList < Array

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

    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

21 entries across 21 versions & 1 rubygems

Version Path
infopark_rails_connector-6.8.0.210.ed204b0 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.110.6570b45 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.72.d18d096 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.23.da7f96b app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.16.def5e85 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.15.a24f5ff app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.891.647580e app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.889.d503e42 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.883.f5f063b app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.884.4bd86e6 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.869.9609b39 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.856.8c0fec5 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.809.bdfa8c3 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.785.05d4af9 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.744.99f67fc app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.720.44fbabd app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.713.e5c3150 app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.681.7c84f4a app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.663.ceecdee app/models/rails_connector/link_list.rb
infopark_rails_connector-6.8.0.beta.200.650.7c93155 app/models/rails_connector/link_list.rb