New methods to retrieve 1 or more guards from the list of running guards #121

Closed
rymai opened this Issue Aug 14, 2011 · 7 comments

2 participants

@rymai
Guard member

As discussed in #118, we could "add a little helper method to Guard that allows you to get a guard like Guard.get_guard(:less)" (@netzpirat).

I agree with @ches on "using a hash instead of keyword arguments", as it seems to be the best choice. We could even have 2 methods:

Guard.get_guards(filters={}) (return an array of guards)

and

Guard.get_guard(filters={}) (return the first guard that matches).

with filters a hash like this: { :name => :less, :group => :foobar } (this would return only the guard-less that is present in the "foobar" group).

Thoughts welcome!

@ches

Another idea comes to mind: don't even use a separately named helper, just implement Guard.guards as a richer reader method instead of using attr_accessor for it. This can still return an array as it does in the established API, but accept the filter hash as a parameter.

@rymai
Guard member
@rymai rymai was assigned Sep 22, 2011
@rymai
Guard member

Ok, I've now implemented a first version of your suggestion.

Guard.guards('less') will find the first Guard::Less instance, Guard.guards(:group => 'frontend') will return all Guards in the 'frontend' group, Guard.guards(:group => 'frontend', :name => 'less') will return all Guard::Less instances in the 'frontend' group.

Thanks again @ches!

@rymai rymai closed this Sep 22, 2011
@ches

Awesome! Hope I can find a chance to play with it soon. Thanks for hearing suggestions and implementing them :-)

@rymai
Guard member

No problem, it's always a pleasure. And you're acknowledged in the CHANGELOG! ;)

@ches

An awfully generous credit, thanks :-)

@rymai
Guard member

Aha, everyone should be thanked, regardless of the contribution's impact (and it's free so... :D)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment