lhs 19.2.0 → 19.3.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
  SHA256:
3
- metadata.gz: bae8511bbecfd667c0139f103d932be9b15738f17ebef9c01e4205c855ba6aef
4
- data.tar.gz: eb47255b3090beb319d4079c0a6dabc601a30b596ed50c5ee51f6d31c2222826
3
+ metadata.gz: 90772215b1826bbd27f4f9d891a063267009282fc4c62a8cd84aa4888749eb25
4
+ data.tar.gz: c9ba59c1c5dbff84597fb8ffd0f3666971f678cb3eba000a9480d851e5abe62d
5
5
  SHA512:
6
- metadata.gz: 1f46c168d58d08d7c78d7d7ec5db86ac5f0ff07ce4fb212387bce4b64f3774fa143434a31bafeea3cbebb112d673a33609858bdc74c175f9eeb37efdd0d82175
7
- data.tar.gz: ad8ced63ed66b4697b0cf1629147bac8ca1bbc6878c8fe2bdac4c26b5e0ed0d6f658479719ebca9c06aa1d71607af352362495b08c4d700c133289e42ab09d93
6
+ metadata.gz: c32491f62744f730c3466aa259e46c68ecb8acafce58f55bc647f99a4611b94e6b8342c7faa7f309447f3943bbbf05c99003cea27a0bb5b4f7d7f4581e1ca97b
7
+ data.tar.gz: 748088f623655bad2866a85b3b1625cb0b6984ba67506b9f16d589061cef649e5f648ec2c695bfee95b73e454c900f770a0b22e4ac4628cfcea08563a30fac9c
data/README.md CHANGED
@@ -128,6 +128,7 @@ record.review # "Lunch was great
128
128
  * [find_each](#find_each)
129
129
  * [find_in_batches](#find_in_batches)
130
130
  * [Convert/Cast specific record types: becomes](#convertcast-specific-record-types-becomes)
131
+ * [Assign attributes](#assign-attributes)
131
132
  * [Request Cycle Cache](#request-cycle-cache)
132
133
  * [Change store for LHS' request cycle cache](#change-store-for-lhs-request-cycle-cache)
133
134
  * [Disable request cycle cache](#disable-request-cycle-cache)
@@ -2188,6 +2189,16 @@ synchronization.save!
2188
2189
  POST https://service.example.com/location/1/sync { body: '{ ... }' }
2189
2190
  ```
2190
2191
 
2192
+ ### Assign attributes
2193
+
2194
+ Allows you to set the attributes by passing in a hash of attributes.
2195
+
2196
+ ```ruby
2197
+ entry = LocalEntry.new
2198
+ entry.assign_attributes(company_name: 'localsearch')
2199
+ entry.company_name # => 'localsearch'
2200
+ ```
2201
+
2191
2202
  ## Request Cycle Cache
2192
2203
 
2193
2204
  By default, LHS does not perform the same http request multiple times during one request/response cycle.
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class LHS::Record
4
+
5
+ module AttributeAssignment
6
+ extend ActiveSupport::Concern
7
+
8
+ def assign_attributes(new_attributes)
9
+ if !new_attributes.respond_to?(:stringify_keys)
10
+ raise ArgumentError, "When assigning attributes, you must pass a hash as an argument, #{new_attributes.class} passed."
11
+ end
12
+ return if new_attributes.empty?
13
+
14
+ _assign_attributes(new_attributes)
15
+ end
16
+ alias attributes= assign_attributes
17
+
18
+ private
19
+
20
+ def _assign_attributes(attributes)
21
+ attributes.each do |key, value|
22
+ public_send(:"#{key}=", value)
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/lhs/record.rb CHANGED
@@ -39,6 +39,8 @@ class LHS::Record
39
39
  'lhs/concerns/record/scope'
40
40
  autoload :Tracing,
41
41
  'lhs/concerns/record/tracing'
42
+ autoload :AttributeAssignment,
43
+ 'lhs/concerns/record/attribute_assignment'
42
44
 
43
45
  module RequestCycleCache
44
46
  autoload :RequestCycleThreadRegistry,
@@ -68,6 +70,7 @@ class LHS::Record
68
70
  include RequestCycleCache
69
71
  include Scope
70
72
  include Tracing
73
+ include AttributeAssignment
71
74
 
72
75
  delegate :_proxy, :_endpoint, :merge_raw!, :select, :becomes, :respond_to?, to: :_data
73
76
 
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.2.0'
4
+ VERSION = '19.3.0'
5
5
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHS::Record do
6
+ before do
7
+ class LocalEntry < LHS::Record
8
+ endpoint '{+datastore}/local-entries'
9
+ end
10
+ end
11
+
12
+ context '#assign_attributes' do
13
+ it 'sets the attributes' do
14
+ entry = LocalEntry.new
15
+ entry.assign_attributes(company_name: 'localsearch')
16
+ expect(entry.company_name).to eq 'localsearch'
17
+ end
18
+ end
19
+
20
+ context '#attributes=' do
21
+ it 'sets the attributes' do
22
+ entry = LocalEntry.new
23
+ entry.attributes = { company_name: 'localsearch' }
24
+ expect(entry.company_name).to eq 'localsearch'
25
+ end
26
+ end
27
+
28
+ context 'when not a hash was passed' do
29
+ it 'raises an error' do
30
+ entry = LocalEntry.new
31
+ expect do
32
+ entry.assign_attributes([:company_name, 'localsearch'])
33
+ end.to raise_error(ArgumentError)
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: 19.2.0
4
+ version: 19.3.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: 2019-04-18 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -237,6 +237,7 @@ files:
237
237
  - lib/lhs/concerns/proxy/create.rb
238
238
  - lib/lhs/concerns/proxy/link.rb
239
239
  - lib/lhs/concerns/proxy/problems.rb
240
+ - lib/lhs/concerns/record/attribute_assignment.rb
240
241
  - lib/lhs/concerns/record/batch.rb
241
242
  - lib/lhs/concerns/record/chainable.rb
242
243
  - lib/lhs/concerns/record/configuration.rb
@@ -384,6 +385,7 @@ files:
384
385
  - spec/proxy/record_identification_spec.rb
385
386
  - spec/rails_helper.rb
386
387
  - spec/record/all_spec.rb
388
+ - spec/record/attribute_assignment_spec.rb
387
389
  - spec/record/build_spec.rb
388
390
  - spec/record/cast_nested_data_spec.rb
389
391
  - spec/record/create_spec.rb
@@ -475,8 +477,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
475
477
  version: '0'
476
478
  requirements:
477
479
  - Ruby >= 2.3.0
478
- rubyforge_project:
479
- rubygems_version: 2.7.8
480
+ rubygems_version: 3.0.2
480
481
  signing_key:
481
482
  specification_version: 4
482
483
  summary: 'REST services accelerator: Rails gem providing an easy, active-record-like
@@ -586,6 +587,7 @@ test_files:
586
587
  - spec/proxy/record_identification_spec.rb
587
588
  - spec/rails_helper.rb
588
589
  - spec/record/all_spec.rb
590
+ - spec/record/attribute_assignment_spec.rb
589
591
  - spec/record/build_spec.rb
590
592
  - spec/record/cast_nested_data_spec.rb
591
593
  - spec/record/create_spec.rb