smart_properties 1.16.0 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/testing.yml +15 -13
- data/.ruby-version +1 -1
- data/dev.yml +2 -2
- data/lib/smart_properties/property.rb +3 -3
- data/lib/smart_properties/property_collection.rb +5 -4
- data/lib/smart_properties/version.rb +1 -1
- data/lib/smart_properties.rb +5 -5
- data/spec/inheritance_spec.rb +70 -18
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7215ef47e61eb079f744d20ea8ee623fecd1efa03d2e66594c2191f376a1f694
|
4
|
+
data.tar.gz: 9775e8cb32223967f0970be9bf5132aef00d9082a395a900ca3c0767f9e069c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: [
|
5
|
+
branches: [master]
|
6
6
|
pull_request:
|
7
|
-
branches: [
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
1
|
+
3.0.3
|
data/dev.yml
CHANGED
@@ -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
|
-
|
15
|
-
|
16
|
-
|
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
|
79
|
+
@collection_with_parent_collection.merge!(parent_collection)
|
79
80
|
notify_children
|
80
81
|
nil
|
81
82
|
end
|
data/lib/smart_properties.rb
CHANGED
@@ -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)
|
112
|
+
base.extend(ModuleMethods) unless base.is_a?(Class)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
data/spec/inheritance_spec.rb
CHANGED
@@ -226,33 +226,85 @@ RSpec.describe SmartProperties, 'intheritance' do
|
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
229
|
-
|
230
|
-
m
|
231
|
-
|
232
|
-
|
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
|
236
|
-
|
237
|
-
|
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
|
-
|
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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
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
|
-
|
249
|
-
|
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
|
-
|
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
|
-
|
255
|
-
|
256
|
-
|
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.
|
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-
|
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.
|
116
|
+
rubygems_version: 3.2.32
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: SmartProperties – Ruby accessors on steroids
|