get 0.1.4.2 → 0.1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90569f3f39dc605cd44d3e12143b16cdb02abaca
4
- data.tar.gz: 1c9711f68ad0c458c143375ee8ce56188ad3f189
3
+ metadata.gz: 35ab11daa222833ce2a9b27474271d07df489689
4
+ data.tar.gz: 8ef6fe8751908e33a133bc5d99765c3859b77e59
5
5
  SHA512:
6
- metadata.gz: d4c4a8030eabe0f73821f248f085432ef64807cde9667a5ea7b1655194a751fa8c55ccb4744f520a4d82bbd24b8967c60f7693a30de4981ebaf17156ec37f2d0
7
- data.tar.gz: 7ac8e20c9c7c00f1b6380e6ec523406469970b53e3dd4424783c333f0c2dd91bd78271f8977520989d440c3e21d531e83215b1b3b0803914772880caed478be3
6
+ metadata.gz: 4048efdf151cd664d1c6006dd3ea2d10ec901f2c6d08a8b9bb6556f704c9c45b8bc64dd747549ebe0469e7ade6d851b57f78269d146277677271ad36a8a1bf0c
7
+ data.tar.gz: 2cc06292d2434ae9587187952779ebc8a4861ea2cf3f78be0c028c24c1717d730e92a0943dde2fbd76ee16ee551d1ee55a35eff501f628d3469a2099d1094624
data/README.md CHANGED
@@ -226,6 +226,17 @@ You can reset the config at any time using `Get.reset`.
226
226
 
227
227
  Get currently works with ActiveRecord.
228
228
 
229
+ ## Edge Cases
230
+
231
+ Some attributes contain the word 'by', ie. `Customer.invited_by`.
232
+ Because of the way Get parses classnames, you won't be able to use the attribute-specific format.
233
+ Use the more general form instead.
234
+
235
+ ```
236
+ Get::CustomerByInvitedBy.run('John') #=> throws Get::Errors::InvalidClassName
237
+ Get::CustomerBy.run(invited_by: 'John') #=> will work
238
+ ```
239
+
229
240
  ## Benchmarking
230
241
 
231
242
  Get requests generally run < 1ms slower than ActiveRecord requests.
data/lib/get/errors.rb CHANGED
@@ -11,5 +11,8 @@ module Get
11
11
 
12
12
  class RecordNotFound < StandardError
13
13
  end
14
+
15
+ class InvalidClassName < StandardError
16
+ end
14
17
  end
15
18
  end
data/lib/get/parser.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  module Get
2
2
  class Parser
3
3
  CLASS_REGEX = /^(.*)(By|From)(.*)/
4
+ CLASS_NAME_BY_ERROR = 'You have multiple instances of "By" in your class. Please use open-ended form ie. Get::UserBy.run(params)'
4
5
  attr_accessor :class_name, :result_entity, :method
5
6
 
6
7
  def initialize(class_name)
8
+ raise Get::Errors::InvalidClassName.new(CLASS_NAME_BY_ERROR) if class_name.to_s.split('By').length > 2
9
+
7
10
  @class_name = class_name
8
11
  @match = class_name.to_s.match(CLASS_REGEX)
9
12
  @result_entity, @method, @key_string = @match.values_at(1, 2, 3) if @match
data/spec/get_spec.rb CHANGED
@@ -312,6 +312,8 @@ describe Get::Parser do
312
312
  let(:query_name) { 'UserFromEmployer' }
313
313
 
314
314
  subject { Get::Parser }
315
+ before { Get.configure { |config| config.set_adapter(:active_record) } }
316
+ after { Get.reset }
315
317
 
316
318
  describe '#match?' do
317
319
  context 'when name is of ancestry type' do
@@ -331,6 +333,11 @@ describe Get::Parser do
331
333
  expect(subject.new('Blablabla').match?).to be false
332
334
  end
333
335
  end
336
+ end
334
337
 
338
+ context 'two instances of "By" in class name' do
339
+ it 'throws error' do
340
+ expect { subject.new('UserByInvitedByType') }.to raise_error Get::Errors::InvalidClassName
341
+ end
335
342
  end
336
343
  end
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.1.4.2
4
+ version: 0.1.5.0
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-05-28 00:00:00.000000000 Z
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: horza