lhs 19.4.1 → 19.5.0.pre.wherehref.1

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
  SHA256:
3
- metadata.gz: 0a07eb02cb34aed5f562ed302246c31eacf746e786ffaf74d61420897662c5f3
4
- data.tar.gz: 2d74239dda28e2d769a43d238c77b1594285283c3b676265f76643ce17649965
3
+ metadata.gz: a88315dc4d085a6e2721ff9b3c64099474c255fb7b38a359347f6b970bce0b8d
4
+ data.tar.gz: 520edfda6e3f56e415e94433e18e2c0f8dd2f30f88aeb997a054b63c0ffa4fd5
5
5
  SHA512:
6
- metadata.gz: 8dabe6d68096aaba06f5c397aafd9b67d48c73209b42604b8c3579d5000c3a380bb7d58377d2bae373f45dd8d3d3fb8d834293b39e233e5259f354c50d956435
7
- data.tar.gz: 3389c1ddcbc753e23d4d73b4d93ab28da0d837df602b096b274041c671db1bd2252b2374439268e11c5b6e7d4577a8d2a745c20f290d489ac7f2c5ca6f0ba2d7
6
+ metadata.gz: '0069a65afd0775a0b672a5ec9d2ac859141e8d04c52c575fd217f6062ddfb9b6190ddda551d386baa1159f8b397bd75c36792be5fb8e4609d3c7b8a40af6b885'
7
+ data.tar.gz: 8f7e6060bbd95b062f827fa25ef1c6a57d8cbef128bf9fab4152b467adc680e1b773d250cc9b896dab5f71d3959c8ef0eecd951a8ffd68c11d12d16eaa12b382
data/lib/lhs.rb CHANGED
@@ -19,6 +19,8 @@ module LHS
19
19
  'lhs/endpoint'
20
20
  autoload :Inspect,
21
21
  'lhs/concerns/inspect'
22
+ autoload :IsHref,
23
+ 'lhs/concerns/is_href'
22
24
  autoload :Item,
23
25
  'lhs/item'
24
26
  autoload :Pagination,
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ module LHS
6
+ module IsHref
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+
11
+ def href?(input)
12
+ input.is_a?(String) && %r{^https?://}.match(input).present?
13
+ end
14
+ end
15
+ end
16
+ end
@@ -14,8 +14,12 @@ class LHS::Record
14
14
  end
15
15
 
16
16
  module ClassMethods
17
- def where(hash = nil)
18
- Chain.new(self, Parameter.new(hash))
17
+ def where(args = nil)
18
+ if href?(args)
19
+ Chain.new(self, Option.new(url: args))
20
+ else
21
+ Chain.new(self, Parameter.new(args))
22
+ end
19
23
  end
20
24
 
21
25
  def fetch
@@ -200,8 +204,12 @@ class LHS::Record
200
204
  end
201
205
  alias validate valid?
202
206
 
203
- def where(hash = nil)
204
- push(Parameter.new(hash))
207
+ def where(args = nil)
208
+ if LHS::Record.href?(args)
209
+ push(Option.new(url: args))
210
+ else
211
+ push(Parameter.new(args))
212
+ end
205
213
  end
206
214
 
207
215
  def all(hash = nil)
@@ -81,10 +81,6 @@ class LHS::Record
81
81
  options
82
82
  end
83
83
  end
84
-
85
- def href?(str)
86
- str.is_a?(String) && %r{^https?://}.match(str)
87
- end
88
84
  end
89
85
  end
90
86
  end
data/lib/lhs/record.rb CHANGED
@@ -62,6 +62,7 @@ class LHS::Record
62
62
  include Find
63
63
  include FindBy
64
64
  include First
65
+ include LHS::IsHref
65
66
  include Last
66
67
  include LHS::Inspect
67
68
  include Mapping
data/lib/lhs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '19.4.1'
4
+ VERSION = '19.5.0.pre.wherehref.1'
5
5
  end
@@ -30,5 +30,33 @@ describe LHS::Record do
30
30
  stub_request(:get, "#{datastore}/content-ads/123/feedbacks?campaign_id=456").to_return(status: 200, body: [].to_json)
31
31
  Record.where(campaign_id: '123', params: { campaign_id: '456' })
32
32
  end
33
+
34
+ context 'where with href' do
35
+ let(:return_body) { [ email: 'steve@local.ch' ].to_json }
36
+
37
+ context 'chain initialization' do
38
+ before do
39
+ stub_request(:get, "https://localch-accounts/?from_user_id=123")
40
+ .to_return(body: return_body)
41
+ end
42
+
43
+ it 'queries api with provided href' do
44
+ records = Record.where('https://localch-accounts?from_user_id=123').fetch
45
+ expect(records.first.email).to eq 'steve@local.ch'
46
+ end
47
+ end
48
+
49
+ context 'after chain initialization' do
50
+ before do
51
+ stub_request(:get, "https://localch-accounts/?color=blue&from_user_id=123")
52
+ .to_return(body: return_body)
53
+ end
54
+
55
+ it 'queries api with provided href also when passed after chain is initialized' do
56
+ records = Record.where(color: 'blue').where('https://localch-accounts?from_user_id=123').fetch
57
+ expect(records.first.email).to eq 'steve@local.ch'
58
+ end
59
+ end
60
+ end
33
61
  end
34
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 19.4.1
4
+ version: 19.5.0.pre.wherehref.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-05 00:00:00.000000000 Z
11
+ date: 2019-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -228,6 +228,7 @@ files:
228
228
  - lib/lhs/concerns/data/json.rb
229
229
  - lib/lhs/concerns/data/to_hash.rb
230
230
  - lib/lhs/concerns/inspect.rb
231
+ - lib/lhs/concerns/is_href.rb
231
232
  - lib/lhs/concerns/item/destroy.rb
232
233
  - lib/lhs/concerns/item/endpoint_lookup.rb
233
234
  - lib/lhs/concerns/item/save.rb
@@ -474,13 +475,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
474
475
  version: 2.3.0
475
476
  required_rubygems_version: !ruby/object:Gem::Requirement
476
477
  requirements:
477
- - - ">="
478
+ - - ">"
478
479
  - !ruby/object:Gem::Version
479
- version: '0'
480
+ version: 1.3.1
480
481
  requirements:
481
482
  - Ruby >= 2.3.0
482
483
  rubyforge_project:
483
- rubygems_version: 2.7.6
484
+ rubygems_version: 2.7.8
484
485
  signing_key:
485
486
  specification_version: 4
486
487
  summary: 'REST services accelerator: Rails gem providing an easy, active-record-like