smart_properties 1.16.0 → 1.17.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
  SHA256:
3
- metadata.gz: 76b840210991bfec855a2e1159426635bc29e3994269bf305b5f0a8fe40fb0cf
4
- data.tar.gz: f10d37b213920338b36b8a2da7bbecc1e8e0caf1d6eecf66084b6cbb4914a95e
3
+ metadata.gz: 7215ef47e61eb079f744d20ea8ee623fecd1efa03d2e66594c2191f376a1f694
4
+ data.tar.gz: 9775e8cb32223967f0970be9bf5132aef00d9082a395a900ca3c0767f9e069c5
5
5
  SHA512:
6
- metadata.gz: 30f8ed85cd3db3e2c17ddc30b63f85cba5541d26d8c8747a92529320531c11a58ae20435f08175061faedc7edf8f3bad2899ff32f2aa36465d4de2a78c8ca75e
7
- data.tar.gz: fb602a52c408989d44c9ef0dd232f5891c6bc96f64444d077d498bb06ed1f63dfa671712abfe9ab0680214fb442ee4b029b6e0e518df01a35860e5fc6c072151
6
+ metadata.gz: 0540c22c62ff52121aad4e4309ec92d53d7e8269212cd711e20aa094411f8072801ddf74fd1d88cb830eef2d1f3fab69da06343743cd95367d87ff8b92a90e84
7
+ data.tar.gz: 145ef1c96af37dc9e9c4b5134ef9e6f1a0b9595fe84c5b8fead3af06be5a9ed0b1518231d1e1e1699cdf42c5688a9e3b00fc8f4a78b5a099f5f713383ac08e0a
@@ -2,23 +2,25 @@ name: Testing
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: [master]
6
6
  pull_request:
7
- branches: [ master ]
7
+ branches: [master]
8
8
  workflow_dispatch:
9
9
 
10
10
  jobs:
11
11
  test:
12
-
12
+ name: Ruby v${{ matrix.ruby_version}}
13
13
  runs-on: ubuntu-latest
14
-
14
+ strategy:
15
+ matrix:
16
+ ruby_version: [2.6.9, 2.7.5, 3.0.3]
15
17
  steps:
16
- - uses: actions/checkout@v2
17
- - name: Set up Ruby
18
- uses: ruby/setup-ruby@v1
19
- with:
20
- ruby-version: 2.6
21
- - name: Install dependencies
22
- run: bundle install
23
- - name: Run tests
24
- run: bundle exec rake
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby_version }}
23
+ - name: Install dependencies
24
+ run: bundle install
25
+ - name: Run tests
26
+ run: bundle exec rake
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.6
1
+ 3.0.3
data/dev.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: smart-properties
3
3
  up:
4
- - ruby: 2.4.1
4
+ - ruby: 3.0.3
5
5
  - bundler
6
6
  commands:
7
- test: bundle exec rake test
7
+ test: bundle exec rake
@@ -10,11 +10,11 @@ module SmartProperties
10
10
  attr_reader :instance_variable_name
11
11
  attr_reader :writable
12
12
 
13
- def self.define(scope, name, options = {})
14
- new(name, options).tap { |p| p.define(scope) }
13
+ def self.define(scope, name, **options)
14
+ new(name, **options).tap { |p| p.define(scope) }
15
15
  end
16
16
 
17
- def initialize(name, attrs = {})
17
+ def initialize(name, **attrs)
18
18
  attrs = attrs.dup
19
19
 
20
20
  @name = name.to_sym
@@ -11,9 +11,10 @@ module SmartProperties
11
11
  ancestor != SmartProperties
12
12
  end
13
13
 
14
- parents.reduce(collection = new) do |previous, current|
15
- current.properties.register(previous)
16
- current.properties
14
+ collection = new
15
+
16
+ parents.reverse.each do |parent|
17
+ parent.properties.register(collection)
17
18
  end
18
19
 
19
20
  collection
@@ -75,7 +76,7 @@ module SmartProperties
75
76
  end
76
77
 
77
78
  def refresh(parent_collection)
78
- @collection_with_parent_collection = parent_collection.merge(collection)
79
+ @collection_with_parent_collection.merge!(parent_collection)
79
80
  notify_children
80
81
  nil
81
82
  end
@@ -1,3 +1,3 @@
1
1
  module SmartProperties
2
- VERSION = "1.16.0"
2
+ VERSION = "1.17.0"
3
3
  end
@@ -79,14 +79,14 @@ module SmartProperties
79
79
  # :default => :de,
80
80
  # :required => true
81
81
  #
82
- def property(name, options = {})
83
- properties[name] = Property.define(self, name, options)
82
+ def property(name, **options)
83
+ properties[name] = Property.define(self, name, **options)
84
84
  end
85
85
  protected :property
86
86
 
87
- def property!(name, options = {})
87
+ def property!(name, **options)
88
88
  options[:required] = true
89
- property(name, options)
89
+ property(name, **options)
90
90
  end
91
91
  protected :property!
92
92
  end
@@ -109,7 +109,7 @@ module SmartProperties
109
109
  #
110
110
  def included(base)
111
111
  base.extend(ClassMethods)
112
- base.extend(ModuleMethods) if base.is_a?(Module)
112
+ base.extend(ModuleMethods) unless base.is_a?(Class)
113
113
  end
114
114
  end
115
115
 
@@ -226,33 +226,85 @@ RSpec.describe SmartProperties, 'intheritance' do
226
226
  end
227
227
  end
228
228
 
229
- it "supports multiple inheritance through modules" do
230
- m = Module.new do
231
- include SmartProperties
232
- property :m, default: 1
229
+ context "through modules" do
230
+ let(:m) do
231
+ m = Module.new do
232
+ include SmartProperties
233
+ property :m, default: 1
234
+ end
233
235
  end
234
236
 
235
- n = Module.new do
236
- include SmartProperties
237
- property :n, default: 2
237
+ let(:n) do
238
+ n = Module.new do
239
+ include SmartProperties
240
+ property :n, default: 2
241
+ end
238
242
  end
239
243
 
240
- o = Module.new {}
244
+ it "is supported" do
245
+ n = self.n
246
+ m = self.m
247
+ o = Module.new {}
248
+
249
+ klass = Class.new do
250
+ include m
251
+ include o
252
+ include n
253
+ end
254
+
255
+ n.module_eval do
256
+ property :p, default: 3
257
+ end
241
258
 
242
- klass = Class.new do
243
- include m
244
- include o
245
- include n
259
+ instance = klass.new
260
+
261
+ expect(instance.m).to eq(1)
262
+ expect(instance.n).to eq(2)
263
+ expect(instance.p).to eq(3)
264
+
265
+ expect { klass.new(m: 4, n: 5, p: 6) }.to_not raise_error
246
266
  end
247
267
 
248
- n.module_eval do
249
- property :p, default: 3
268
+ it "always extends module with ModuleMethods but never classes" do
269
+ n = self.n
270
+
271
+ klass = Class.new do
272
+ include n
273
+ end
274
+
275
+ module_singleton_class_ancestors = n.singleton_class.ancestors
276
+
277
+ expect(module_singleton_class_ancestors).to include(SmartProperties::ClassMethods)
278
+ expect(module_singleton_class_ancestors).to include(SmartProperties::ModuleMethods)
279
+
280
+ singleton_class_ancestors = klass.singleton_class.ancestors
281
+
282
+ expect(singleton_class_ancestors).to include(SmartProperties::ClassMethods)
283
+ expect(singleton_class_ancestors).not_to include(SmartProperties::ModuleMethods)
250
284
  end
251
285
 
252
- instance = klass.new
286
+ it "yields properly ordered properties – child properties have higher precedence than parent properties" do
287
+ n = self.n
288
+ m = self.m
289
+
290
+ parent = Class.new do
291
+ include m
292
+ include n
293
+ end
294
+ expect(parent.new.m).to eq(1)
295
+
296
+ child = Class.new(parent) do
297
+ property :m, default: 0
298
+ end
299
+ expect(child.new.m).to eq(0)
300
+
301
+ grandchild = Class.new(child)
302
+ expect(grandchild.new.m).to eq(0)
253
303
 
254
- expect(instance.m).to eq(1)
255
- expect(instance.n).to eq(2)
256
- expect(instance.p).to eq(3)
304
+ grandgrandchild = Class.new(grandchild) do
305
+ property :m, default: 1000
306
+ end
307
+ expect(grandgrandchild.new.m).to eq(1000)
308
+ end
257
309
  end
258
310
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_properties
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Tennhard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-18 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.2.3
116
+ rubygems_version: 3.2.32
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: SmartProperties – Ruby accessors on steroids