has_scope icon indicating copy to clipboard operation
has_scope copied to clipboard

Feature/enhance readme to support standalone mode

Open pinzonjulian opened this issue 4 years ago • 8 comments

This update enhances the docs a little bit and documents support for HasScope outside of Controllers. I've taken the liberty to rewrite some parts of the docs to make them a little bit clearer by expanding the examples.

pinzonjulian avatar Sep 01 '20 21:09 pinzonjulian

@carlosantoniodasilva There was one thing I wasn't able to document entirely and it's support for the current_scopes method. The only way I found to expose the method inside of a PORO is to call super because it's a protected method but this didn't feel very nice to me. Expanding on the example in this PR's readme:

class GraduationsSearchQuery
  include HasScope

  has_scope :featured, type: :boolean
  has_scope :by_degree
  has_scope :by_period, using: %i[started_at ended_at], type: :hash
  
  def initialize; end

  def perform(collection:, params: {})
    apply_scopes(collection, params)
  end

  def current_scopes
    super
  end
end

This allows me to call current scopes on the query object (and maybe I can find a way to expose it as helper to the view):

class GraduationsController < ApplicationController

  def index
    graduations_query = GraduationsSearchQuery.new
    @graduations = graduations_query.perform(collection: Graduation, params: params)
    graduations_query.current_scopes
  end
end

Do you know of another way to do it?

pinzonjulian avatar Sep 01 '20 21:09 pinzonjulian

@pinzonjulian cool, thanks! I'll take a better look in the next few days.

As for your question, another way of doing it is to explicitly change the method visibility, making the method public:

public :current_scopes

carlosantoniodasilva avatar Sep 02 '20 22:09 carlosantoniodasilva

Hey @carlosantoniodasilva ! Just a little bump to get this merged in.

Cheers!

pinzonjulian avatar Nov 13 '20 03:11 pinzonjulian

@pinzonjulian oops, my bad, this one slipped through the cracks. I've added it to my to-do here to circle back and review it. Thanks a bunch!

carlosantoniodasilva avatar Jan 22 '21 21:01 carlosantoniodasilva

Friendly bump again :)

pinzonjulian avatar May 19 '21 00:05 pinzonjulian

Hi, just passing here to say that this PR helped me to setup standalone scopes, thanks!

gvn182 avatar Sep 20 '21 22:09 gvn182

Hey! Circling back to ask if you've had time to have a look @carlosantoniodasilva

Is there anything I can do to help you out? I'd be thrilled to become a maintainer if you need a hand on this one!

pinzonjulian avatar Oct 10 '21 11:10 pinzonjulian

One last effort to get this looked at!

pinzonjulian avatar Sep 13 '22 23:09 pinzonjulian

All done @carlosantoniodasilva

pinzonjulian avatar Nov 18 '22 22:11 pinzonjulian

Bumping! All the changes you requested have been added.

pinzonjulian avatar Dec 08 '22 10:12 pinzonjulian

@pinzonjulian thanks so much!

carlosantoniodasilva avatar Jan 16 '23 21:01 carlosantoniodasilva