get 0.3.2 → 0.3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b23af9cacb8d8ab5e7b6a0c76718256e097cc9b
4
- data.tar.gz: b63d6b2ff1e40933b6ee736d5ac1232c1f0cf4d0
3
+ metadata.gz: 75d26babe2ad02eb00f3235b9de2c9891266e3da
4
+ data.tar.gz: 2cef8bd681cc576bccf3727129753f156644b34f
5
5
  SHA512:
6
- metadata.gz: b79408b6285e49b8fe5e80441ef312424f0d6b635ce04d6963f26afbe612d4f7ddefa0709b94328ccf7d92e57c9b234f695d4a566d7865579eb68486b111d7e8
7
- data.tar.gz: 1f98da1ff49978617fbd2049ee8a9b5b97fc27a86f9534f1e974c2d480332bc0a0b58cfe298d5d703aac50b14676250dcf1226a7701c56f01a4b4e0064e8a6f3
6
+ metadata.gz: 33958398abb0fac7092d923355a5c2e9d4634ed0c34ae200266d9eb88a41c830c9cac9d397447ff17da331439a4ff01cfe91f4bca2aab7d9f181f93c2f2d21bf
7
+ data.tar.gz: 95b7c4b1f1576516d6c539ef260697b910e0194fb93da749d2fb79372a630d2c269ff6bba08fe22348ca653ee5d1b58104b4b2cf8895dd6c2f1a3f1077b631a2
@@ -22,7 +22,7 @@ module Get
22
22
 
23
23
  @field, @entity, @collection, @store = args[:key], args[:result_entity], args[:collection], args[:store]
24
24
 
25
- def initialize(params, options = {})
25
+ def initialize(params = nil, options = {})
26
26
  @params, @options = params, options
27
27
  super(query_params)
28
28
  end
data/lib/get/builders.rb CHANGED
@@ -7,7 +7,7 @@ module Get
7
7
 
8
8
  def builder_for_method(method)
9
9
  case method
10
- when 'By'
10
+ when 'By', 'All'
11
11
  QueryBuilder
12
12
  when 'From'
13
13
  AncestryBuilder
data/lib/get/errors.rb CHANGED
@@ -14,5 +14,8 @@ module Get
14
14
 
15
15
  class InvalidClassName < StandardError
16
16
  end
17
+
18
+ class OptionsNotPermitted < StandardError
19
+ end
17
20
  end
18
21
  end
data/lib/get/parser.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Get
2
2
  class Parser
3
3
  CLASS_REGEX = /^(.*)(By|From|JoinedWith)(.*)/
4
+ ALL_CLASS_REGEX = /^(All)(.*)/
4
5
  CLASS_NAME_BY_ERROR = 'You have multiple instances of "By" in your class. Please use open-ended form ie. Get::UserBy.run(params)'
5
6
  attr_accessor :class_name, :result_entity, :method
6
7
 
@@ -8,8 +9,7 @@ module Get
8
9
  raise Get::Errors::InvalidClassName.new(CLASS_NAME_BY_ERROR) if class_name.to_s.split('By').length > 2
9
10
 
10
11
  @class_name = class_name
11
- @match = class_name.to_s.match(CLASS_REGEX)
12
- @result_entity, @method, @key_string = @match.values_at(1, 2, 3) if @match
12
+ @match = match_result
13
13
  end
14
14
 
15
15
  def match?
@@ -19,5 +19,16 @@ module Get
19
19
  def key
20
20
  @key_string.present? ? @key_string.symbolize : nil
21
21
  end
22
+
23
+ def match_result
24
+ @match = class_name.to_s.match(ALL_CLASS_REGEX)
25
+ if @match
26
+ @method, @result_entity = @match.values_at(1, 2)
27
+ else
28
+ @match = class_name.to_s.match(CLASS_REGEX)
29
+ @result_entity, @method, @key_string = @match.values_at(1, 2, 3) if @match
30
+ end
31
+ @match
32
+ end
22
33
  end
23
34
  end
@@ -1,11 +1,18 @@
1
1
  module Get
2
2
  module RunMethods
3
+ ALL_CLASS_REGEX = /(All)(.*)/
3
4
  def run(*context)
5
+ options_allowed if context.present?
4
6
  new(*context).run
5
7
  end
6
8
 
7
9
  def run!(*context)
10
+ options_allowed if context
8
11
  new(*context).run!
9
12
  end
13
+
14
+ def options_allowed
15
+ raise ::Get::Errors::OptionsNotPermitted.new("Options not supported with 'All' queries") if self.to_s.match(ALL_CLASS_REGEX)
16
+ end
10
17
  end
11
18
  end
data/spec/get_spec.rb CHANGED
@@ -224,6 +224,17 @@ describe Get do
224
224
  expect(Get::UsersBy.run(last_name: last_name).is_a?(Horza::Entities::Collection)).to be true
225
225
  end
226
226
  end
227
+
228
+ context 'when All' do
229
+ it 'gets all records' do
230
+ result = Get::AllUsers.run
231
+ expect(result.length).to eq match_count + miss_count
232
+ end
233
+
234
+ it 'throws an exception if options passed' do
235
+ expect{ Get::AllUsers.run(last_name: last_name) }.to raise_error Get::Errors::OptionsNotPermitted
236
+ end
237
+ end
227
238
  end
228
239
 
229
240
  context 'with options' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Turner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-24 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: horza
@@ -155,6 +155,6 @@ specification_version: 4
155
155
  summary: Get is a library designed to encapsulate Rails database queries and prevent
156
156
  query pollution in the view layer.
157
157
  test_files:
158
- - spec/get_spec.rb
159
158
  - spec/spec_helper.rb
159
+ - spec/get_spec.rb
160
160
  has_rdoc: