Skip to content
Browse files

add a clear method on ListParameter to clear the elements inside

  • Loading branch information...
1 parent 57be245 commit a4054d765397cfb04e4c353babecf05eb9286f28 Patrick Roby committed May 17, 2012
Showing with 9 additions and 0 deletions.
  1. +4 −0 lib/legato/list_parameter.rb
  2. +5 −0 spec/lib/legato/list_parameter_spec.rb
View
4 lib/legato/list_parameter.rb
@@ -17,6 +17,10 @@ def <<(element)
self
end
+ def clear
+ @elements = []
+ end
+
def to_params
value = elements.map{|element| Legato.to_ga_string(element)}.join(',')
value.empty? ? {} : {name => value}
View
5 spec/lib/legato/list_parameter_spec.rb
@@ -31,5 +31,10 @@
@list_parameter << :pageviews
@list_parameter.to_params.should == {"metrics" => "ga:exits,ga:pageviews"}
end
+
+ it 'clears the list' do
+ @list_parameter.clear
+ @list_parameter.elements.should == []
+ end
end
end

5 comments on commit a4054d7

@tpitale
Owner

How do you imagine this being used?

@tpitale
Owner

To be more specific, I'm fine with it, I'm just curious how you're using it. Cheers!

@proby
Collaborator
proby commented on a4054d7 May 18, 2012

The short answer is I have a Legato::Model class that under some circumstances requires only one metrics (visits) and under other circumstances requires a set of metrics (visits, visits, pageviews, timeOnSite, bounces). I'll write up a longer description later today. Cheers.

@tpitale
Owner

Hrm. I wonder if there's a better pattern for this. Maybe passing in metrics when building a query, arel-style? We could add that ability.

I guess I'd always hoped that the class used would be a model with a fixed set of metrics/dimensions. Is it possible what you're describing could be two classes?

Regardless, you can go ahead and add this in to master.

@proby
Collaborator
proby commented on a4054d7 May 18, 2012

I think you're right. The more I look at the implication of this idea the less I like it. It could get quite messy to maintain and debug down the road. Combine that with your hope that the class would be used with a fixed set of metrics & dimension, I'm going to retract this pull request.

Thanks for the good discussion

Please sign in to comment.
Something went wrong with that request. Please try again.