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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3b75fc9863dd79ea23f4053b680f9ab80ad99712ca454b6ed472dba73ce1d5f
4
- data.tar.gz: 6e0995df0f6749f92b1d156b039ab0fe94bb603ee948d2bf91436d6a25d8608c
3
+ metadata.gz: 721d2501ba3b20e2b2c3e8fc8ed420ffb9d1c54d527e3701b3010a873c3a0035
4
+ data.tar.gz: 13ccd0ca429d21b1ca095cea1ea2b58779885924b2c93fb287b9bc8d9307d7e7
5
5
  SHA512:
6
- metadata.gz: 946cea4cb835456c6ccd78026d56da074831e2f2fa3b77d40321e08ce1cd25ae54030cf175cf533a33b606b055c94d4e8f4beee530f3b1074b127f0e2cb033c2
7
- data.tar.gz: 5ae594af7e7e68258edd4a12ffd218dd67187680e3d29ee5f6f0c570e4092ef0a0bdac0d842239cd19dc70799c5c929a0314003b5db93dc08443e935f86f0dab
6
+ metadata.gz: 0b465101495c5f45502165a2218e65734117c8d44313554ce0a692fa5a6ce0712987e40094564c6fd5e0fec5ea62f70f1916f63f2a1c49503ccd1e3d8033d1a3
7
+ data.tar.gz: 9037ab8d02fcad742a57a141f54add7d1ca316b455e8f2a2b5a6d42be79acd583600ce86b1fefac465f9526f539a36c92abdbc12633fdbeb502553a7aa737b56
data/config/flay.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 7
3
- total_score: 24
3
+ total_score: 29
data/config/flog.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 10.4
2
+ threshold: 11.6
@@ -9,6 +9,7 @@ require 'lb/persistence/settings'
9
9
 
10
10
  # Helpers
11
11
  require 'lb/persistence/relation/joins'
12
+ require 'lb/persistence/model/attributes'
12
13
 
13
14
  # LB namespace
14
15
  module LB
@@ -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
@@ -3,6 +3,6 @@
3
3
  module LB
4
4
  class Persistence
5
5
  # Version
6
- VERSION = '0.0.4'
6
+ VERSION = '0.0.5'
7
7
  end
8
8
  end
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,7 @@ if ENV['COVERAGE'] == 'true'
10
10
  add_filter 'config'
11
11
  add_filter 'spec'
12
12
 
13
- minimum_coverage 86
13
+ minimum_coverage 89
14
14
  end
15
15
  end
16
16
 
@@ -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
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