lb-persistence 0.0.4 → 0.0.5
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.rb +1 -0
- data/lib/lb/persistence/model/attributes.rb +25 -0
- data/lib/lb/persistence/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/lb/persistence/model/redefine_attribute_spec.rb +53 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 721d2501ba3b20e2b2c3e8fc8ed420ffb9d1c54d527e3701b3010a873c3a0035
|
4
|
+
data.tar.gz: 13ccd0ca429d21b1ca095cea1ea2b58779885924b2c93fb287b9bc8d9307d7e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b465101495c5f45502165a2218e65734117c8d44313554ce0a692fa5a6ce0712987e40094564c6fd5e0fec5ea62f70f1916f63f2a1c49503ccd1e3d8033d1a3
|
7
|
+
data.tar.gz: 9037ab8d02fcad742a57a141f54add7d1ca316b455e8f2a2b5a6d42be79acd583600ce86b1fefac465f9526f539a36c92abdbc12633fdbeb502553a7aa737b56
|
data/config/flay.yml
CHANGED
data/config/flog.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
2
|
+
threshold: 11.6
|
data/lib/lb/persistence.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LB
|
4
|
+
class Persistence
|
5
|
+
module Model
|
6
|
+
# Helper for dry-struct attributes
|
7
|
+
module Attributes
|
8
|
+
def delete_attribute(name)
|
9
|
+
@schema.delete(name)
|
10
|
+
equalizer.instance_variable_get('@keys').delete(name)
|
11
|
+
superclass.instance_variable_get('@schema').delete(name)
|
12
|
+
@constructor = Dry::Types['coercible.hash']
|
13
|
+
.public_send(constructor_type, @schema)
|
14
|
+
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def redefine_attribute(name, type)
|
19
|
+
delete_attribute(name)
|
20
|
+
attribute(name, type)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe LB::Persistence::Model::Attributes, '#redefine_attribute' do
|
6
|
+
include_context 'settings'
|
7
|
+
|
8
|
+
subject { object }
|
9
|
+
|
10
|
+
let(:model_base_class) do
|
11
|
+
Class.new(Dry::Struct) do
|
12
|
+
module Types
|
13
|
+
include Dry::Types.module
|
14
|
+
end
|
15
|
+
|
16
|
+
attribute :a, Types::Strict::Symbol
|
17
|
+
attribute :b, Types::Strict::String
|
18
|
+
attribute :c, Types::Strict::Hash
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:model_child_class) do
|
23
|
+
Class.new(model_base_class) do
|
24
|
+
extend LB::Persistence::Model::Attributes
|
25
|
+
|
26
|
+
redefine_attribute :b, Types::Strict::Bool
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:object) { model_child_class.new(values) }
|
31
|
+
|
32
|
+
let(:base_values) do
|
33
|
+
{
|
34
|
+
a: :symbol,
|
35
|
+
c: { key: 'value' }
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:values) { base_values.merge(b: true) }
|
40
|
+
|
41
|
+
it 'should create model with redefined attribute' do
|
42
|
+
expect(subject.b).to be(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with invalid value' do
|
46
|
+
let(:values) { base_values.merge(b: 'true') }
|
47
|
+
let(:expected_msg) { /has invalid type for #{Regexp.escape(':b')}/ }
|
48
|
+
|
49
|
+
it 'should not create model with old attribute' do
|
50
|
+
expect { subject }.to raise_error(Dry::Struct::Error, expected_msg)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Firas Zaidan
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lb-persistence.gemspec
|
190
190
|
- lib/lb-persistence.rb
|
191
191
|
- lib/lb/persistence.rb
|
192
|
+
- lib/lb/persistence/model/attributes.rb
|
192
193
|
- lib/lb/persistence/relation/joins.rb
|
193
194
|
- lib/lb/persistence/settings.rb
|
194
195
|
- lib/lb/persistence/types.rb
|
@@ -200,6 +201,7 @@ files:
|
|
200
201
|
- spec/unit/lb/persistence/class_methods/new_spec.rb
|
201
202
|
- spec/unit/lb/persistence/connect_spec.rb
|
202
203
|
- spec/unit/lb/persistence/container_spec.rb
|
204
|
+
- spec/unit/lb/persistence/model/redefine_attribute_spec.rb
|
203
205
|
- spec/unit/lb/persistence/repository_spec.rb
|
204
206
|
- spec/unit/lb/persistence/uri_spec.rb
|
205
207
|
homepage: https://github.com/lb-rb/lb-persistence
|
@@ -234,5 +236,6 @@ test_files:
|
|
234
236
|
- spec/unit/lb/persistence/class_methods/new_spec.rb
|
235
237
|
- spec/unit/lb/persistence/connect_spec.rb
|
236
238
|
- spec/unit/lb/persistence/container_spec.rb
|
239
|
+
- spec/unit/lb/persistence/model/redefine_attribute_spec.rb
|
237
240
|
- spec/unit/lb/persistence/repository_spec.rb
|
238
241
|
- spec/unit/lb/persistence/uri_spec.rb
|