Sha256: c437abdc777ad501c968000b16b0379e17a8640f1fb357338ca2e1e5a02b4cbb

Contents?: true

Size: 741 Bytes

Versions: 2

Compression:

Stored size: 741 Bytes

Contents

# Add support for type metadata to arrays

require 'will_paginate/array'

class Array

  attr_accessor :member_class, :origin, :origin_attribute

  def to_url_path
    base_path = origin.try.to_url_path
    "#{base_path}/#{origin_attribute}" unless base_path.blank?
  end

  def typed_id
    origin and origin_id = origin.try.typed_id and "#{origin_id}:#{origin_attribute}"
  end

  def paginate_with_hobo_metadata(*args, &block)
    collection = paginate_without_hobo_metadata(*args, &block)
    collection.member_class     = member_class
    collection.origin           = try.proxy_owner
    collection.origin_attribute = try.proxy_association._?.reflection._?.name
    collection
  end
  alias_method_chain :paginate, :hobo_metadata

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hobo-2.0.0.pre1 lib/hobo/extensions/array.rb
hobo-1.4.0.pre8 lib/hobo/extensions/array.rb