lhs 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a00b04e289a4748446105fc8701ddabc87f58d77
4
- data.tar.gz: 44f10bf8b376e4d849506074f39fd4373e7dc13b
3
+ metadata.gz: e27399738c34692f15a9ba1068981cf12443631e
4
+ data.tar.gz: e8eaccb70ea546cefbe1257cf381710ca238efc3
5
5
  SHA512:
6
- metadata.gz: 15b4da5598314dc9ad1029e1c2b9562ef0610bb4f2f240e6c1be7d813a49e2e94dbebed77fd4f0a8c699998970069274a4b4a0939bc49d52769b416315259873
7
- data.tar.gz: 83a9e1c944011beaea79e4a0b3c6cebaef12305234a91ebc0ed94741567a5dd919f9953af7d7d8e485bc944326d914f462ff91fa75507c4873ee42a2b752fa00
6
+ metadata.gz: c8a1c670452d45d81ed4d107887f40911b20909a4c834877571ad1d2d2ea7192506fe5fd15dde441446bd544f679b625143af9d78882d790a069a5e336f9ead5
7
+ data.tar.gz: 5f6a52abd26aa3521f1afeef73ab872b6f7d1a121d56a5f660aec54796c6c413f2694afe688ead9fade514c5cce0b87a5be809dbf5760942a4f1079662d567b8
data/README.md CHANGED
@@ -15,7 +15,7 @@ class Feedback < LHS::Record
15
15
 
16
16
  end
17
17
 
18
- feedback = Feedback.find_by_email('somebody@mail.com') #<Feedback>
18
+ feedback = Feedback.find_by(email: 'somebody@mail.com') #<Feedback>
19
19
  feedback.review # "Lunch was great"
20
20
  ```
21
21
 
@@ -5,8 +5,8 @@ class LHS::Data
5
5
  module Json
6
6
  extend ActiveSupport::Concern
7
7
 
8
- def as_json(_options = {})
9
- _data._raw.as_json
8
+ def as_json(options = {})
9
+ _data._raw.as_json(options)
10
10
  end
11
11
  end
12
12
  end
@@ -106,6 +106,8 @@ class LHS::Data
106
106
  json = JSON.parse(input)
107
107
  if json.is_a?(Hash)
108
108
  json.deep_symbolize_keys
109
+ elsif json.is_a?(Array)
110
+ json.map { |item| item.is_a?(Hash) ? item.deep_symbolize_keys : item }
109
111
  else
110
112
  json
111
113
  end
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "4.0.0"
2
+ VERSION = "4.1.0"
3
3
  end
@@ -19,6 +19,13 @@ describe LHS::Data do
19
19
  LHS::Data.new(item)
20
20
  end
21
21
 
22
+ let(:data_from_array) do
23
+ LHS::Data.new([
24
+ { href: 'http://www.local.ch/v2/stuff/3', id: '123123123' },
25
+ { href: 'http://www.local.ch/v2/stuff/4', id: '123123124' }
26
+ ].to_json)
27
+ end
28
+
22
29
  context 'raw' do
23
30
  it 'you can access raw data that is underlying' do
24
31
  expect(data_from_raw._raw).to be_kind_of Hash
@@ -30,5 +37,10 @@ describe LHS::Data do
30
37
  href: 'http://www.local.ch/v2/stuff'
31
38
  )
32
39
  end
40
+
41
+ it 'returns a Hash with symbols when the input is an array' do
42
+ expect(data_from_array._raw).to be_kind_of Array
43
+ expect(data_from_array._raw.first.keys.first).to be_kind_of Symbol
44
+ end
33
45
  end
34
46
  end
@@ -30,8 +30,37 @@ describe LHS::Data do
30
30
  .to eq JSON.parse(load_json(:feedbacks)).to_json
31
31
  end
32
32
 
33
+ it 'converts collection with options to json' do
34
+ expect(collection.as_json(only: [:items, :href])).to eq(
35
+ "items" => [
36
+ { "href" => "http://local.ch/v2/feedbacks/0sdaetZ-OWVg4oBiBJ-7IQ" },
37
+ { "href" => "http://local.ch/v2/feedbacks/QsUOQWNJoB-GFUNsX7z0jg" },
38
+ { "href" => "http://local.ch/v2/feedbacks/QynNtmpXlsEGvUJ0ekDKVw" },
39
+ { "href" => "http://local.ch/v2/feedbacks/INmminYWNZwW_qNFx5peJQ" },
40
+ { "href" => "http://local.ch/v2/feedbacks/ltgfr0VRYDN2nxyC119wTg" },
41
+ { "href" => "http://local.ch/v2/feedbacks/5dUdQP-kZ6sulN8NtpGXTw" },
42
+ { "href" => "http://local.ch/v2/feedbacks/Z3KfWzIEQ3ZVCUj2IdrSNQ" },
43
+ { "href" => "http://local.ch/v2/feedbacks/ZUUUeiw-Stw5Zb1baHDUzQ" },
44
+ { "href" => "http://local.ch/v2/feedbacks/GyeWvhEtU4cYN_5T2FX2UA" },
45
+ { "href" => "http://local.ch/v2/feedbacks/o-qTRqQGFS3Z_RPJm1f8SA" }
46
+ ],
47
+ "href" => "http://local.ch/v2/feedbacks/?exclude_hidden=false&offset=0&limit=10"
48
+ )
49
+ end
50
+
33
51
  it 'converts link to json' do
34
52
  expect(item.campaign.to_json)
35
53
  .to eq item.campaign._raw.to_json
36
54
  end
55
+
56
+ context 'collections from arrays' do
57
+ let(:collection) do
58
+ LHS::Data.new([{ foo: 'foo', bar: 'bar' }])
59
+ end
60
+
61
+ it 'converts with options to json' do
62
+ expect(collection.as_json(only: :foo)).to eq [{ 'foo' => 'foo' }]
63
+ expect(collection.to_json(only: :foo)).to eq "[{\"foo\":\"foo\"}]"
64
+ end
65
+ end
37
66
  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: 4.0.0
4
+ version: 4.1.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-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc