Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

convert :order key to :sort

  • Loading branch information...
commit f83388bf151df316ed56871fffcd216811393b36 1 parent b006881
Patrick Roby authored
Showing with 27 additions and 27 deletions.
  1. +1 −1  README.md
  2. +6 −6 lib/legato/query.rb
  3. +20 −20 spec/lib/legato/query_spec.rb
2  README.md
View
@@ -143,7 +143,7 @@ Operators on dimensions:
* :end_date - The date to end, inclusive
* :limit - The maximum number of results to be returned
* :offset - The starting index
- * :order - metric/dimension to order by
+ * :sort - metric/dimension to sort by
## License ##
12 lib/legato/query.rb
View
@@ -22,7 +22,7 @@ def #{method}(field, value, join_character=nil)
attr_reader :parent_klass
attr_accessor :profile, :start_date, :end_date
- attr_accessor :order, :limit, :offset#, :segment # individual, overwritten
+ attr_accessor :sort, :limit, :offset#, :segment # individual, overwritten
attr_accessor :filters # appended to, may add :segments later for dynamic segments
def initialize(klass)
@@ -60,7 +60,7 @@ def apply_filter(*args, &block)
def apply_options(options)
if options.has_key?(:sort)
# warn
- options[:order] = options.delete(:sort)
+ options[:sort] = options.delete(:sort)
end
apply_basic_options(options)
@@ -70,7 +70,7 @@ def apply_options(options)
end
def apply_basic_options(options)
- [:order, :limit, :offset, :start_date, :end_date].each do |key| #:segment
+ [:sort, :limit, :offset, :start_date, :end_date].each do |key| #:segment
self.send("#{key}=".to_sym, options[key]) if options.has_key?(key)
end
end
@@ -147,8 +147,8 @@ def dimensions
parent_klass.dimensions
end
- def order=(arr)
- @order = Legato::ListParameter.new(:order, arr)
+ def sort=(arr)
+ @sort = Legato::ListParameter.new(:sort, arr)
end
# def segment_id
@@ -170,7 +170,7 @@ def to_params
'filters' => filters.to_params # defaults to AND filtering
}
- [metrics, dimensions, order].each do |list|
+ [metrics, dimensions, sort].each do |list|
params.merge!(list.to_params) unless list.nil?
end
40 spec/lib/legato/query_spec.rb
View
@@ -104,10 +104,10 @@ def self.it_defines_operators(*operators)
@query.stubs(:profile=)
@query.stubs(:apply_options)
- @query.results({:order => [:city]}).should == @query
+ @query.results({:sort => [:city]}).should == @query
@query.should have_received(:profile=).never
- @query.should have_received(:apply_options).with({:order => [:city]})
+ @query.should have_received(:apply_options).with({:sort => [:city]})
end
context 'when applying filters' do
@@ -172,26 +172,26 @@ def self.it_defines_operators(*operators)
@query.apply_options({}).should == @query
end
- it "stores the order" do
- @query.apply_options({:order => [:page_path]})
- @query.order.should == Legato::ListParameter.new(:order, [:page_path])
+ it "stores the sort" do
+ @query.apply_options({:sort => [:page_path]})
+ @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
end
- it 'replaces the order' do
- @query.order = [:pageviews]
- @query.apply_options({:order => [:page_path]})
- @query.order.should == Legato::ListParameter.new(:order, [:page_path])
+ it 'replaces the sort' do
+ @query.sort = [:pageviews]
+ @query.apply_options({:sort => [:page_path]})
+ @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
end
- it "does not replace order if option is omitted" do
- @query.order = [:pageviews]
+ it "does not replace sort if option is omitted" do
+ @query.sort = [:pageviews]
@query.apply_options({})
- @query.order.should == Legato::ListParameter.new(:order, [:pageviews])
+ @query.sort.should == Legato::ListParameter.new(:sort, [:pageviews])
end
- it "moves :sort option into order" do
+ it "moves :sort option into sort" do
@query.apply_options({:sort => [:page_path]})
- @query.order.should == Legato::ListParameter.new(:order, [:page_path])
+ @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
end
it "sets the limit" do
@@ -321,13 +321,13 @@ def self.it_defines_operators(*operators)
@query.to_params['dimensions'].should == 'browser,country'
end
- it 'includes order' do
- order = Legato::ListParameter.new(:order)
- order.stubs(:to_params).returns({'order' => 'pageviews'})
- order.stubs(:empty?).returns(false)
- @query.stubs(:order).returns(order)
+ it 'includes sort' do
+ sort = Legato::ListParameter.new(:sort)
+ sort.stubs(:to_params).returns({'sort' => 'pageviews'})
+ sort.stubs(:empty?).returns(false)
+ @query.stubs(:sort).returns(sort)
- @query.to_params['order'].should == 'pageviews'
+ @query.to_params['sort'].should == 'pageviews'
end
end
end

1 comment on commit f83388b

Tony Pitale

What's the motivation behind this name change?

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