lhs 12.1.0 → 12.2.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: 3a3fd78d0dd9d0ee88751c3b0ba15652bd4a15d9
4
- data.tar.gz: 0629f8dfc7068fa195ce3fc5d556313b59c0a713
3
+ metadata.gz: 73ccff4b48445ae9b548d688af83448b607dd635
4
+ data.tar.gz: d786114a63d3d8d8eeb87495d84e1823c0cfcd50
5
5
  SHA512:
6
- metadata.gz: 9042c4d3e3d7b70be32018087fef6c1b472de591048b19866aad7f2fa9098e223490f318b5527a3e53708a0e591419bb0f77f47650df5c1c1f26f5ffd5b38b1e
7
- data.tar.gz: 8c0571a35bcacaa09ccd58fa729b083e84d1613cee295cfec64208c1d130d9615c1e9b32cc92ab36978e8e82722316d063baf4baa806c8c5b8e0df6d6b6b018e
6
+ metadata.gz: a2320ec4f39b5255536ab3d5a1819aac8919b4199e852b8968e3866d5a7144edb53c3a64ccdce11b4627de8bd990b360b5a5069f7ac4ac95624235e7aa5b5d38
7
+ data.tar.gz: 03af49fcdce27f7000e3446429f532b2d005dcc1de19cc17e1de177da534cb859e8dfba6ea29c9cfe49b32007e338a82c975c0304ce8b0686e0a179a56407396
data/README.md CHANGED
@@ -670,6 +670,28 @@ record = Record.find('1z-5r1fkaj')
670
670
  record.update(recommended: false)
671
671
  ```
672
672
 
673
+ ## Becomes
674
+
675
+ Based on [ActiveRecord's implementation](http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-becomes), LHS implements `becomes`, too.
676
+ It's a way to convert records of a certain type A to another certain type B.
677
+
678
+ _NOTE: RPC-style actions, that are discouraged in REST anyway, are utilizable with this functionality, too. See the following example:_
679
+
680
+ ```ruby
681
+ class Location < LHS::Record
682
+ endpoint 'http://sync/locations'
683
+ endpoint 'http://sync/locations/:id'
684
+ end
685
+
686
+ class Synchronization < LHS::Record
687
+ endpoint 'http://sync/locations/:id/sync'
688
+ end
689
+
690
+ location = Location.find(1)
691
+ synchronization = location.becomes(Synchronization)
692
+ synchronization.save!
693
+ ```
694
+
673
695
  ## Destroy
674
696
 
675
697
  You can delete records remotely by calling `destroy` on an LHS::Record.
@@ -0,0 +1,12 @@
1
+ require 'active_support'
2
+
3
+ class LHS::Item < LHS::Proxy
4
+
5
+ module Becomes
6
+ extend ActiveSupport::Concern
7
+
8
+ def becomes(klass)
9
+ klass.new(_raw)
10
+ end
11
+ end
12
+ end
data/lib/lhs/item.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # An item is a concrete record.
2
2
  # It can be part of another proxy like collection.
3
3
  class LHS::Item < LHS::Proxy
4
+ autoload :Becomes,
5
+ 'lhs/concerns/item/becomes'
4
6
  autoload :Destroy,
5
7
  'lhs/concerns/item/destroy'
6
8
  autoload :Save,
@@ -10,6 +12,7 @@ class LHS::Item < LHS::Proxy
10
12
  autoload :Validation,
11
13
  'lhs/concerns/item/validation'
12
14
 
15
+ include Becomes
13
16
  include Create
14
17
  include Destroy
15
18
  include Save
data/lib/lhs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "12.1.0"
2
+ VERSION = "12.2.0"
3
3
  end
@@ -0,0 +1,36 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHS::Item do
4
+ before(:each) do
5
+ class Location < LHS::Record
6
+ endpoint 'http://sync/locations'
7
+ endpoint 'http://sync/locations/:id'
8
+ end
9
+
10
+ class Synchronization < LHS::Record
11
+ endpoint 'http://sync/locations/:id/sync'
12
+ end
13
+
14
+ stub_request(:get, "http://sync/locations/1")
15
+ .to_return(body: {
16
+ id: 1,
17
+ name: 'localsearch'
18
+ }.to_json)
19
+
20
+ stub_request(:post, "http://sync/locations/1/sync")
21
+ .with(body: {
22
+ name: 'localsearch'
23
+ }.to_json)
24
+ .to_return(status: 201)
25
+ end
26
+
27
+ context 'convert records from class A to class B' do
28
+ it "becomes a record of another class" do
29
+ location = Location.find(1)
30
+ synchronization = location.becomes(Synchronization)
31
+ expect(synchronization).to be_kind_of(Synchronization)
32
+ synchronization.save!
33
+ expect(synchronization).to be_kind_of(Synchronization)
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.1.0
4
+ version: 12.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
@@ -205,6 +205,7 @@ files:
205
205
  - lib/lhs/concerns/data/json.rb
206
206
  - lib/lhs/concerns/data/to_hash.rb
207
207
  - lib/lhs/concerns/inspect.rb
208
+ - lib/lhs/concerns/item/becomes.rb
208
209
  - lib/lhs/concerns/item/destroy.rb
209
210
  - lib/lhs/concerns/item/save.rb
210
211
  - lib/lhs/concerns/item/update.rb
@@ -316,6 +317,7 @@ files:
316
317
  - spec/endpoint/for_url_spec.rb
317
318
  - spec/item/accessors_spec.rb
318
319
  - spec/item/add_error_spec.rb
320
+ - spec/item/becomes_spec.rb
319
321
  - spec/item/delegate_spec.rb
320
322
  - spec/item/destroy_spec.rb
321
323
  - spec/item/dig_spec.rb
@@ -485,6 +487,7 @@ test_files:
485
487
  - spec/endpoint/for_url_spec.rb
486
488
  - spec/item/accessors_spec.rb
487
489
  - spec/item/add_error_spec.rb
490
+ - spec/item/becomes_spec.rb
488
491
  - spec/item/delegate_spec.rb
489
492
  - spec/item/destroy_spec.rb
490
493
  - spec/item/dig_spec.rb