Sha256: 9e6ce5732486bab7811cdecab0ef9cb6bf286e91ab984c521a14355b15635c3f

Contents?: true

Size: 907 Bytes

Versions: 4

Compression:

Stored size: 907 Bytes

Contents

module Curate::FieldsForAddToCollection
  extend ActiveSupport::Concern

  included do
    helper_method :available_profiles
    helper_method :available_collections
    helper_method :current_users_profile_sections
  end

protected

  def collection_options
    @collection_options ||= current_users_collections
  end

  def current_users_collections
    current_user ? current_user.collections.to_a : []
  end

  def available_collections(item = nil)
    if item.present?
      collection_options.reject {|n| n == item}
    else
      collection_options
    end
  end

  def available_profiles
    return [] unless current_user
    return [] unless current_user.profile
    [current_user.profile]
  end

  def current_users_profile_sections
    return [] unless current_user
    return [] unless current_user.profile
    current_user.profile.members.select {|item| item.respond_to?(:members) }
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
curate-0.6.6 app/controllers/concerns/curate/fields_for_add_to_collection.rb
curate-0.6.5 app/controllers/concerns/curate/fields_for_add_to_collection.rb
curate-0.6.4 app/controllers/concerns/curate/fields_for_add_to_collection.rb
curate-0.6.3 app/controllers/concerns/curate/fields_for_add_to_collection.rb