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 +4 -4
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -1
- data/lib/lb/persistence/functions.rb +18 -6
- data/lib/lb/persistence/version.rb +1 -1
- data/spec/unit/lb/persistence/functions/class_methods/group_prefix_spec.rb +1 -1
- data/spec/unit/lb/persistence/functions/class_methods/wrap_prefix_spec.rb +56 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3248153cfc72bbf73768873e1105cb04831a2476e6fb1adcf4c7e92b88ffb469
|
4
|
+
data.tar.gz: 37c6bfd937b4b07cbc37dc011ce6259bad345a1a41bbf98e23e7823eeff3a49b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ba856063afe63e3ed996e95463b336ad7d68e6965b4c7f070149773a73a9ca68d867ff27db96536fd46c99c519ef7fe6c1593c8137aa86d1eee3b1d5ca78954
|
7
|
+
data.tar.gz: c02b76edfd81d3f94fd2c3cbc8fae31ba48259a8f122f66ac7cdac52b44221d4265cc03c33439c25913d0b50f24fe0bd855c7775b78b3fd1600dfb7c8bd38df3
|
data/config/flay.yml
CHANGED
data/config/flog.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
@@ -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.
|
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
|
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
|