Permalink
Browse files

add a clear method on ListParameter to clear the elements inside

  • Loading branch information...
Patrick Roby
Patrick Roby committed May 17, 2012
1 parent 57be245 commit a4054d765397cfb04e4c353babecf05eb9286f28
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
@@ -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}
@@ -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

This comment has been minimized.

Show comment
Hide comment
@tpitale

tpitale May 18, 2012

Owner

How do you imagine this being used?

Owner

tpitale replied May 18, 2012

How do you imagine this being used?

@tpitale

This comment has been minimized.

Show comment
Hide comment
@tpitale

tpitale May 18, 2012

Owner

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

Owner

tpitale replied May 18, 2012

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

@proby

This comment has been minimized.

Show comment
Hide comment
@proby

proby May 18, 2012

Collaborator

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.

Collaborator

proby replied 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

This comment has been minimized.

Show comment
Hide comment
@tpitale

tpitale May 18, 2012

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.

Owner

tpitale replied May 18, 2012

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

This comment has been minimized.

Show comment
Hide comment
@proby

proby May 18, 2012

Collaborator

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

Collaborator

proby replied 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.