lhs 6.6.2 → 6.7.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: 28bbd84604d97fb4b2832870a1af4e19c8a4dd7b
4
- data.tar.gz: cee59479f3b13012abaca1454f2bb5a09c884768
3
+ metadata.gz: 325e7b214a89c1e31cee0be6ed5958cd9e134430
4
+ data.tar.gz: cd8d528f00f08d40b445e49856f0f617287dd8b6
5
5
  SHA512:
6
- metadata.gz: 2d42b4b4fe655bb825b3877e19f13f6f431207daa6cadd4484de828516de2b4b546314a363ec0c08b0896e6dc4d437fd3966c8898143f128077f92d906f4da26
7
- data.tar.gz: f85c70878edb8a4d13d7915e261c71bcf1c3601679615cb9972e1279898fd9aaa315014893a8493b94ee81e7157c0d30a93a898fe5d01adc906cd5568bceb11f
6
+ metadata.gz: 0c11af41a6074ef3cf601a6dd0b5136bf558befae1b9d0a6ca8db7e25c23351dbaa746683162de20206c3f00c3b3af40ebdc5344d2d700a2c96c4681452e572b
7
+ data.tar.gz: 3fc266b541674def93c38e535f924c1185fe34d9a4c6f91b581f49ffb8788c09c112ea6cb0d4aac47aa34a9fd4db79734991234f331e66feebc0b723a27d3201
data/README.md CHANGED
@@ -522,6 +522,18 @@ You can delete records remotely by calling `destroy` on an LHS::Record.
522
522
  record.destroy
523
523
  ```
524
524
 
525
+ You can also destroy records directly without fetching them first:
526
+
527
+ ```ruby
528
+ destroyed_record = Record.destroy('1z-5r1fkaj')
529
+ ```
530
+
531
+ or with parameters:
532
+
533
+ ```ruby
534
+ destroyed_records = Record.destroy(name: 'Steve')
535
+ ```
536
+
525
537
  ## Validation
526
538
 
527
539
  In order to validate LHS::Records before persisting them, you can use the `valid?` (`validate` alias) method.
@@ -117,7 +117,12 @@ class LHS::Record
117
117
 
118
118
  def destroy(options = nil)
119
119
  options ||= {}
120
- @record.destroy(chain_options.merge(options))
120
+ options = options.respond_to?(:to_h) ? options : { id: options }
121
+ if @record
122
+ @record.destroy(chain_options.merge(options))
123
+ else
124
+ @record_class.destroy(options, chain_options)
125
+ end
121
126
  end
122
127
 
123
128
  def update(data = {}, options = nil)
@@ -0,0 +1,16 @@
1
+ require 'active_support'
2
+
3
+ class LHS::Record
4
+
5
+ module Destroy
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+ def destroy(args, options = nil)
10
+ options = {} if options.blank?
11
+ params = args.respond_to?(:to_h) ? args : { id: args }
12
+ request(options.merge(params: params, method: :delete))
13
+ end
14
+ end
15
+ end
16
+ end
@@ -6,8 +6,9 @@ class LHS::Record
6
6
  include Chainable
7
7
  include Configuration
8
8
  include Create
9
- include Equality
9
+ include Destroy
10
10
  include Endpoints
11
+ include Equality
11
12
  include Find
12
13
  include FindBy
13
14
  include First
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "6.6.2"
2
+ VERSION = "6.7.0"
3
3
  end
@@ -0,0 +1,36 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHS::Record do
4
+ context 'destroy' do
5
+ before(:each) do
6
+ class Record < LHS::Record
7
+ endpoint 'http://datastore/history'
8
+ endpoint 'http://datastore/history/:id'
9
+ end
10
+ end
11
+
12
+ let(:entry) { { what: 'Cafe', where: 'Zurich' } }
13
+
14
+ it 'allows to destroy by parameters directly' do
15
+ stub_request(:delete, "http://datastore/history?what=Cafe&where=Zurich")
16
+ .to_return(body: [entry].to_json)
17
+ deleted_entries = Record.destroy(what: 'Cafe', where: 'Zurich')
18
+ expect(deleted_entries.first.to_h).to eq entry
19
+ end
20
+
21
+ it 'allows to destroy by id' do
22
+ stub_request(:delete, "http://datastore/history/1")
23
+ .to_return(body: entry.to_json)
24
+ deleted_entry = Record.destroy(1)
25
+ expect(deleted_entry.to_h).to eq entry
26
+ end
27
+
28
+ it 'chains' do
29
+ stub_request(:delete, "http://datastore/history/1")
30
+ .with(headers: { 'Authorization' => 'Bearer 123' })
31
+ .to_return(body: entry.to_json)
32
+ deleted_entry = Record.options(headers: { 'Authorization' => 'Bearer 123' }).destroy(1)
33
+ expect(deleted_entry.to_h).to eq entry
34
+ end
35
+ end
36
+ 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: 6.6.2
4
+ version: 6.7.0
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: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -192,6 +192,7 @@ files:
192
192
  - lib/lhs/concerns/record/chainable.rb
193
193
  - lib/lhs/concerns/record/configuration.rb
194
194
  - lib/lhs/concerns/record/create.rb
195
+ - lib/lhs/concerns/record/destroy.rb
195
196
  - lib/lhs/concerns/record/endpoints.rb
196
197
  - lib/lhs/concerns/record/equality.rb
197
198
  - lib/lhs/concerns/record/find.rb
@@ -294,6 +295,7 @@ files:
294
295
  - spec/record/create_spec.rb
295
296
  - spec/record/creation_failed_spec.rb
296
297
  - spec/record/definitions_spec.rb
298
+ - spec/record/destroy_spec.rb
297
299
  - spec/record/endpoint_inheritance_spec.rb
298
300
  - spec/record/endpoint_misconfiguration_spec.rb
299
301
  - spec/record/endpoint_options_spec.rb
@@ -442,6 +444,7 @@ test_files:
442
444
  - spec/record/create_spec.rb
443
445
  - spec/record/creation_failed_spec.rb
444
446
  - spec/record/definitions_spec.rb
447
+ - spec/record/destroy_spec.rb
445
448
  - spec/record/endpoint_inheritance_spec.rb
446
449
  - spec/record/endpoint_misconfiguration_spec.rb
447
450
  - spec/record/endpoint_options_spec.rb