Sha256: f58b0f51eee3b5bf73ec27909e1b1fb7fa19f74bb04cc66798e7cbf53b4422e3

Contents?: true

Size: 1001 Bytes

Versions: 35

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true

module LinkedRails
  module Model
    module Indexable
      extend ActiveSupport::Concern

      module ClassMethods
        def collection_from_parent(params)
          parent = parent_from_params(params, params[:user_context])
          return if parent.blank?

          collection_name = collection_from_parent_name(parent, params)

          parent.send(collection_name, params) if collection_name
        end

        def root_collection(**params)
          return unless root_collection?

          default_collection_option(:collection_class).collection_or_view(
            default_collection_options,
            params
          )
        end

        private

        def collection_from_parent_name(parent, _params)
          collection_name = "#{name.demodulize.underscore}_collection"

          collection_name if parent.respond_to?(collection_name, true)
        end

        def root_collection?
          true
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
linked_rails-0.0.4.pre.g4c8e21c9f lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g76dedd8ba lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g7123943aa lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g72bb595fe lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.gd8464437f lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g661cde413 lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.ge09501794 lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.gc3dfc6914 lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g92825d924 lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g14b377f91 lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g2c53724b3 lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g83aa52ab3 lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.gaa82a222d lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.g9b7bc9073 lib/linked_rails/model/indexable.rb
linked_rails-0.0.4.pre.ge1306665a lib/linked_rails/model/indexable.rb