muster 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Authors CHANGED
@@ -1,2 +1,2 @@
1
- - Chris Laco <claco@chrislaco.com?
2
- - Nikica Jokić (neektza@gmail.com)
1
+ - Chris Laco <claco@chrislaco.com>
2
+ - Nikica Jokić <neektza@gmail.com>
data/Changes CHANGED
@@ -1,6 +1,10 @@
1
+ = 0.0.8
2
+
3
+ * Added JoinsExpressions to ActiveRecord Strategy (includes) (neektza)
4
+
1
5
  = 0.0.7
2
6
 
3
- * Added JoinsExpressions to ActiveRecord Strategy (neektza)
7
+ * Added JoinsExpressions to ActiveRecord Strategy (joins) (neektza)
4
8
 
5
9
  = 0.0.6
6
10
 
@@ -42,7 +42,8 @@ module Muster
42
42
  :limit => pagination[:limit],
43
43
  :offset => pagination[:offset],
44
44
  :where => self.parse_where(query_string),
45
- :joins => self.parse_joins(query_string)
45
+ :joins => self.parse_joins(query_string),
46
+ :includes => self.parse_includes(query_string)
46
47
  )
47
48
 
48
49
  parameters.regular_writer('pagination', pagination[:pagination].symbolize_keys)
@@ -131,6 +132,22 @@ module Muster
131
132
 
132
133
  return results[:joins] || {}
133
134
  end
135
+
136
+ # Returns includes clauses for AR queries
137
+ #
138
+ # @param query_string [String] the original query string to parse join statements from
139
+ #
140
+ # @return [Hash]
141
+ #
142
+ # @example
143
+ #
144
+ # value = self.parse_joins('includes=authors') #=> {'includes' => 'authors'}
145
+ def parse_includes( query_string )
146
+ strategy = Muster::Strategies::JoinsExpression.new(:field => :includes)
147
+ results = strategy.parse(query_string)
148
+
149
+ return results[:includes] || {}
150
+ end
134
151
 
135
152
  end
136
153
  end
@@ -1,4 +1,4 @@
1
1
  module Muster
2
2
  # Current version of Muster
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
@@ -6,7 +6,7 @@ describe Muster::Strategies::ActiveRecord do
6
6
 
7
7
  describe '#parse' do
8
8
  it 'returns a Muster::Results instance' do
9
- subject.parse('').should == {"select"=>[], "order"=>[], "limit"=>30, "offset"=>nil, "where"=>{}, "joins"=>{}, "pagination"=>{:page=>1, :per_page=>30}}
9
+ subject.parse('').should == {"select"=>[], "order"=>[], "limit"=>30, "offset"=>nil, "where"=>{}, "joins"=>{}, "includes"=>{}, "pagination"=>{:page=>1, :per_page=>30}}
10
10
  subject.parse('').should be_an_instance_of(Muster::Results)
11
11
  end
12
12
 
@@ -67,6 +67,24 @@ describe Muster::Strategies::ActiveRecord do
67
67
  end
68
68
  end
69
69
 
70
+ context 'includes' do
71
+ it 'returns single value in Array' do
72
+ subject.parse('includes=author')[:includes].should eq ['author']
73
+ end
74
+
75
+ it 'returns multiple values in Array' do
76
+ subject.parse('includes=author,voter')[:includes].should eq ['author', 'voter']
77
+ end
78
+
79
+ it 'returns a nested hash of separated values' do
80
+ subject.parse('includes=author.country.name')[:includes].should eq [{'author' => { 'country' => 'name'}}]
81
+ end
82
+
83
+ it 'returns an array of nested hashes' do
84
+ subject.parse('includes=author.country.name,activity.rule')[:includes].should eq [{'author' => { 'country' => 'name'}}, {'activity' => 'rule'}]
85
+ end
86
+ end
87
+
70
88
  context 'pagination' do
71
89
  it 'returns default will paginate compatible pagination' do
72
90
  subject.parse('')[:pagination].should == {:page => 1, :per_page => 30}
@@ -132,24 +150,28 @@ describe Muster::Strategies::ActiveRecord do
132
150
 
133
151
  context 'the full monty' do
134
152
  it 'returns a hash of all options' do
135
- query_string = 'select=id,guid,name&where=name:foop&order=id:desc&order=name&page=3&page_size=5'
153
+ query_string = 'select=id,guid,name&where=name:foop&order=id:desc&order=name&page=3&page_size=5&includes=author.country,comments&joins=activity'
136
154
  results = subject.parse(query_string)
137
155
 
138
156
  results[:select].should == ['id', 'guid', 'name']
139
157
  results[:where].should == {'name' => 'foop'}
140
158
  results[:order].should == ['id desc', 'name asc']
159
+ results[:includes].should == [{'author' => 'country'}, 'comments']
160
+ results[:joins].should == ['activity']
141
161
  results[:pagination].should == {:page => 3, :per_page => 5}
142
162
  results[:offset].should == 10
143
163
  results[:limit].should == 5
144
164
  end
145
165
 
146
166
  it 'supports indifferent access' do
147
- query_string = 'select=id,guid,name&where=name:foop&order=id:desc&order=name&page=3&page_size=5'
167
+ query_string = 'select=id,guid,name&where=name:foop&order=id:desc&order=name&page=3&page_size=5&includes=author.country,comments&joins=activity'
148
168
  results = subject.parse(query_string)
149
169
 
150
170
  results['select'].should == ['id', 'guid', 'name']
151
171
  results['where'].should == {'name' => 'foop'}
152
172
  results['order'].should == ['id desc', 'name asc']
173
+ results['includes'].should == [{'author' => 'country'}, 'comments']
174
+ results['joins'].should == ['activity']
153
175
  results['pagination'].should == {:page => 3, :per_page => 5}
154
176
  results['offset'].should == 10
155
177
  results['limit'].should == 5
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-13 00:00:00.000000000 Z
12
+ date: 2013-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport