get 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/get/builders/query_builder.rb +1 -1
- data/lib/get/builders.rb +1 -1
- data/lib/get/errors.rb +3 -0
- data/lib/get/parser.rb +13 -2
- data/lib/get/run_methods.rb +7 -0
- data/spec/get_spec.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75d26babe2ad02eb00f3235b9de2c9891266e3da
|
4
|
+
data.tar.gz: 2cef8bd681cc576bccf3727129753f156644b34f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/get/errors.rb
CHANGED
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 =
|
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
|
data/lib/get/run_methods.rb
CHANGED
@@ -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.
|
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-
|
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:
|