lb-persistence 0.0.7 → 0.0.8

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: 88c297bf05f552a33b4c4fd5f7203b8de93f820275d18c743c869e8eb5f51a95
4
- data.tar.gz: f2d175ce189f0526d3d6d8dd64f59f4896d9e8da22aa2962275fcee5a1b658fc
3
+ metadata.gz: 3248153cfc72bbf73768873e1105cb04831a2476e6fb1adcf4c7e92b88ffb469
4
+ data.tar.gz: 37c6bfd937b4b07cbc37dc011ce6259bad345a1a41bbf98e23e7823eeff3a49b
5
5
  SHA512:
6
- metadata.gz: ea8c01ac54d558a4873e282b612267b7f7aaf3bb9bc1574db0be7e7ef074252f583372094c448614aa02532df353d3775488b53a0314bc2a413c4a4f64097694
7
- data.tar.gz: 7499307f0f49d136a2475b1959b62c0ef43f42c62a50f4faf713c304c149d33f1d2ca480e92baa4369fbfc2e01eef3f81804e2b7db8caff28f8250a6faada3fd
6
+ metadata.gz: 9ba856063afe63e3ed996e95463b336ad7d68e6965b4c7f070149773a73a9ca68d867ff27db96536fd46c99c519ef7fe6c1593c8137aa86d1eee3b1d5ca78954
7
+ data.tar.gz: c02b76edfd81d3f94fd2c3cbc8fae31ba48259a8f122f66ac7cdac52b44221d4265cc03c33439c25913d0b50f24fe0bd855c7775b78b3fd1600dfb7c8bd38df3
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 9
3
- total_score: 60
3
+ total_score: 62
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 13.7
2
+ threshold: 11.6
@@ -35,12 +35,19 @@ module LB
35
35
  key.start_with?(prefix) ? key.gsub(/^#{prefix}/, '') : key
36
36
  end
37
37
 
38
- def group_prefix(array, key, keys, prefix, model = nil)
39
- compose do |ops|
40
- ops << t(:group, key, keys)
41
- ops << t(:map_array,
42
- t(:remove_key_prefix_inject_for, key, prefix, model))
43
- end.call(array)
38
+ {
39
+ group: :remove_key_prefix_inject_for,
40
+ wrap: :remove_key_prefix_inject_hash_for
41
+ }.each do |operation, inject|
42
+ # rubocop:disable Metrics/LineLength
43
+ define_method :"#{operation}_prefix" do |array, key, keys, prefix, model = nil|
44
+ # rubocop:enable Metrics/LineLength
45
+ compose do |ops|
46
+ ops << t(operation, key, keys)
47
+ ops << t(:map_array,
48
+ t(inject, key, prefix, model))
49
+ end.call(array)
50
+ end
44
51
  end
45
52
 
46
53
  def remove_key_prefix_inject_for(hash, key, prefix, model = nil)
@@ -69,6 +76,11 @@ module LB
69
76
  t(:map_array, t(:constructor_inject, model)).call(array)
70
77
  end
71
78
  alias model inject_array
79
+
80
+ def remove_key_prefix_inject_hash_for(hash, key, prefix, model = nil)
81
+ t(:map_value, key,
82
+ t(:remove_key_prefix_inject, prefix, model)).call(hash)
83
+ end
72
84
  end
73
85
  end
74
86
  end
@@ -3,6 +3,6 @@
3
3
  module LB
4
4
  class Persistence
5
5
  # Version
6
- VERSION = '0.0.7'
6
+ VERSION = '0.0.8'
7
7
  end
8
8
  end
@@ -22,7 +22,7 @@ describe LB::Persistence::Functions, '.group_prefix' do
22
22
  end
23
23
 
24
24
  attribute :a, Types::Strict::String
25
- attribute :items, Types::Strict::Array.member(nested)
25
+ attribute :items, Types::Strict::Array.of(nested)
26
26
  end
27
27
  end
28
28
 
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe LB::Persistence::Functions, '.wrap_prefix' do
6
+ subject { object.call(data) }
7
+
8
+ let(:object) do
9
+ described_class.t(:wrap_prefix, key, keys, prefix, nested_class)
10
+ .>> described_class.t(:model, model_class)
11
+ end
12
+
13
+ let(:key) { :item }
14
+ let(:keys) { [:item_a] }
15
+ let(:prefix) { 'item_' }
16
+
17
+ let(:model_class) do
18
+ nested = nested_class
19
+ Class.new(Dry::Struct) do
20
+ module Types
21
+ include Dry::Types.module
22
+ end
23
+
24
+ attribute :a, Types::Strict::String
25
+ attribute :item, nested
26
+ end
27
+ end
28
+
29
+ let(:nested_class) do
30
+ Class.new(Dry::Struct) do
31
+ module Types
32
+ include Dry::Types.module
33
+ end
34
+
35
+ attribute :a, Types::Strict::String
36
+ end
37
+ end
38
+
39
+ let(:data) do
40
+ [
41
+ { a: 'a1', item_a: 'item_a1' },
42
+ { a: 'a2', item_a: 'item_a3' }
43
+ ]
44
+ end
45
+
46
+ let(:expected_hash_values) do
47
+ [
48
+ { a: 'a1', item: { a: 'item_a1' } },
49
+ { a: 'a2', item: { a: 'item_a3' } }
50
+ ]
51
+ end
52
+
53
+ it 'should group hash' do
54
+ expect(subject.map(&:to_h)).to eq(expected_hash_values)
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lb-persistence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firas Zaidan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2018-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -203,6 +203,7 @@ files:
203
203
  - spec/unit/lb/persistence/connect_spec.rb
204
204
  - spec/unit/lb/persistence/container_spec.rb
205
205
  - spec/unit/lb/persistence/functions/class_methods/group_prefix_spec.rb
206
+ - spec/unit/lb/persistence/functions/class_methods/wrap_prefix_spec.rb
206
207
  - spec/unit/lb/persistence/model/redefine_attribute_spec.rb
207
208
  - spec/unit/lb/persistence/repository_spec.rb
208
209
  - spec/unit/lb/persistence/uri_spec.rb
@@ -239,6 +240,7 @@ test_files:
239
240
  - spec/unit/lb/persistence/connect_spec.rb
240
241
  - spec/unit/lb/persistence/container_spec.rb
241
242
  - spec/unit/lb/persistence/functions/class_methods/group_prefix_spec.rb
243
+ - spec/unit/lb/persistence/functions/class_methods/wrap_prefix_spec.rb
242
244
  - spec/unit/lb/persistence/model/redefine_attribute_spec.rb
243
245
  - spec/unit/lb/persistence/repository_spec.rb
244
246
  - spec/unit/lb/persistence/uri_spec.rb