Sha256: f93012d7a05062e3fd70b5a1ff6588bb4087379bc4bbc266c4e830125985ca06

Contents?: true

Size: 1.42 KB

Versions: 18

Compression:

Stored size: 1.42 KB

Contents

module Pageflow
  module Admin
    module MembershipsHelper
      def membership_entries_collection_for_parent(parent)
        CollectionForParent.new(parent,
                                collection_method: :entries,
                                display_method: :title,
                                order: 'title ASC').pairs
      end

      def membership_users_collection_for_parent(parent)
        CollectionForParent.new(parent,
                                collection_method: :users,
                                display_method: :formal_name,
                                order: 'last_name ASC, first_name ASC').pairs
      end

      class CollectionForParent
        attr_reader :parent, :options

        def initialize(parent, options)
          @parent = parent
          @options = options
        end

        def pairs
          items.each_with_object([]) do |item, result|
            result << [display(item), item.id]
          end
        end

        private

        def items
          items_in_account - items_in_parent
        end

        def display(item)
          item.send(options[:display_method])
        end

        def items_in_account
          parent.account.send(options[:collection_method]).order(options[:order])
        end

        def items_in_parent
          parent.respond_to?(options[:collection_method]) ? parent.send(options[:collection_method]) : []
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pageflow-0.11.4 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.11.3 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.11.2 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.11.1 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.11.0 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.10.0 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.9.2 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.9.1 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.9.0 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.8.2 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.8.1 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.8.0 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.7.2 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.7.1 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.7.0 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.6.0 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.5.0 app/helpers/pageflow/admin/memberships_helper.rb
pageflow-0.4.0 app/helpers/pageflow/admin/memberships_helper.rb