smart_properties 1.15.0 → 1.16.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 +4 -4
- data/.github/workflows/testing.yml +24 -0
- data/.ruby-version +1 -1
- data/README.md +1 -1
- data/lib/smart_properties.rb +8 -0
- data/lib/smart_properties/property.rb +14 -7
- data/lib/smart_properties/property_collection.rb +6 -6
- data/lib/smart_properties/version.rb +1 -1
- data/smart_properties.gemspec +5 -1
- data/spec/configuration_error_spec.rb +19 -0
- data/spec/inheritance_spec.rb +30 -0
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76b840210991bfec855a2e1159426635bc29e3994269bf305b5f0a8fe40fb0cf
|
4
|
+
data.tar.gz: f10d37b213920338b36b8a2da7bbecc1e8e0caf1d6eecf66084b6cbb4914a95e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30f8ed85cd3db3e2c17ddc30b63f85cba5541d26d8c8747a92529320531c11a58ae20435f08175061faedc7edf8f3bad2899ff32f2aa36465d4de2a78c8ca75e
|
7
|
+
data.tar.gz: fb602a52c408989d44c9ef0dd232f5891c6bc96f64444d077d498bb06ed1f63dfa671712abfe9ab0680214fb442ee4b029b6e0e518df01a35860e5fc6c072151
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: Testing
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
workflow_dispatch:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
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
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6.
|
1
|
+
2.6.6
|
data/README.md
CHANGED
@@ -177,7 +177,7 @@ often. These validations can be found in the `SmartProperties::Validations` modu
|
|
177
177
|
|
178
178
|
```ruby
|
179
179
|
class Article
|
180
|
-
property :view_count, accepts: Ancestor.must_be(Number)
|
180
|
+
property :view_count, accepts: Ancestor.must_be(type: Number)
|
181
181
|
end
|
182
182
|
```
|
183
183
|
|
data/lib/smart_properties.rb
CHANGED
@@ -91,6 +91,13 @@ module SmartProperties
|
|
91
91
|
protected :property!
|
92
92
|
end
|
93
93
|
|
94
|
+
module ModuleMethods
|
95
|
+
def included(target)
|
96
|
+
super
|
97
|
+
target.include(SmartProperties)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
94
101
|
class << self
|
95
102
|
private
|
96
103
|
|
@@ -102,6 +109,7 @@ module SmartProperties
|
|
102
109
|
#
|
103
110
|
def included(base)
|
104
111
|
base.extend(ClassMethods)
|
112
|
+
base.extend(ModuleMethods) if base.is_a?(Module)
|
105
113
|
end
|
106
114
|
end
|
107
115
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SmartProperties
|
2
2
|
class Property
|
3
3
|
MODULE_REFERENCE = :"@_smart_properties_method_scope"
|
4
|
-
ALLOWED_DEFAULT_CLASSES = [Proc, Numeric, String, Range, TrueClass, FalseClass, NilClass, Symbol].freeze
|
4
|
+
ALLOWED_DEFAULT_CLASSES = [Proc, Numeric, String, Range, TrueClass, FalseClass, NilClass, Symbol, Module].freeze
|
5
5
|
|
6
6
|
attr_reader :name
|
7
7
|
attr_reader :converter
|
@@ -157,12 +157,19 @@ module SmartProperties
|
|
157
157
|
rescue NoMethodError => error
|
158
158
|
# BasicObject does not respond to #nil? by default, so we need to double
|
159
159
|
# check if somebody implemented it and it fails internally or if the
|
160
|
-
# error occured because the method is actually not present.
|
161
|
-
|
162
|
-
#
|
163
|
-
|
164
|
-
|
165
|
-
|
160
|
+
# error occured because the method is actually not present.
|
161
|
+
|
162
|
+
# This is a workaround for the fact that #singleton_class is defined on Object, but not BasicObject.
|
163
|
+
the_singleton_class = (class << object; self; end)
|
164
|
+
|
165
|
+
if the_singleton_class.public_instance_methods.include?(:nil?)
|
166
|
+
# object defines #nil?, but it raised NoMethodError,
|
167
|
+
# something is wrong with the implementation, so raise the exception.
|
168
|
+
raise error
|
169
|
+
else
|
170
|
+
# treat the object as truthy because we don't know better.
|
171
|
+
false
|
172
|
+
end
|
166
173
|
end
|
167
174
|
end
|
168
175
|
end
|
@@ -5,18 +5,18 @@ module SmartProperties
|
|
5
5
|
attr_reader :parent
|
6
6
|
|
7
7
|
def self.for(scope)
|
8
|
-
|
8
|
+
parents = scope.ancestors[1..-1].select do |ancestor|
|
9
9
|
ancestor.ancestors.include?(SmartProperties) &&
|
10
10
|
ancestor != scope &&
|
11
11
|
ancestor != SmartProperties
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
parent.properties.register(collection = new)
|
18
|
-
collection
|
14
|
+
parents.reduce(collection = new) do |previous, current|
|
15
|
+
current.properties.register(previous)
|
16
|
+
current.properties
|
19
17
|
end
|
18
|
+
|
19
|
+
collection
|
20
20
|
end
|
21
21
|
|
22
22
|
def initialize
|
data/smart_properties.gemspec
CHANGED
@@ -12,6 +12,10 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = %q{SmartProperties – Ruby accessors on steroids}
|
13
13
|
gem.homepage = ""
|
14
14
|
|
15
|
+
gem.metadata = {
|
16
|
+
"source_code_uri" => "https://github.com/t6d/smart_properties"
|
17
|
+
}
|
18
|
+
|
15
19
|
gem.files = `git ls-files`.split($\)
|
16
20
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
21
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
@@ -20,6 +24,6 @@ Gem::Specification.new do |gem|
|
|
20
24
|
gem.version = SmartProperties::VERSION
|
21
25
|
|
22
26
|
gem.add_development_dependency "rspec", "~> 3.0"
|
23
|
-
gem.add_development_dependency "rake", "~>
|
27
|
+
gem.add_development_dependency "rake", "~> 13.0"
|
24
28
|
gem.add_development_dependency "pry"
|
25
29
|
end
|
@@ -14,6 +14,25 @@ RSpec.describe SmartProperties, 'configuration error' do
|
|
14
14
|
expect(&invalid_property_definition).to raise_error(SmartProperties::ConfigurationError, "SmartProperties do not support the following configuration options: invalid_option_1, invalid_option_2, invalid_option_3.")
|
15
15
|
end
|
16
16
|
|
17
|
+
it "should accept default values that can't be mutated" do
|
18
|
+
valid_property_definition = lambda do
|
19
|
+
klass.class_eval do
|
20
|
+
property :proc, default: -> { }
|
21
|
+
property :numeric_float, default: 1.23
|
22
|
+
property :numeric_int, default: 456
|
23
|
+
property :string, default: "abc"
|
24
|
+
property :range, default: 123...456
|
25
|
+
property :bool_true, default: true
|
26
|
+
property :bool_false, default: false
|
27
|
+
property :nil, default: nil
|
28
|
+
property :symbol, default: :abc
|
29
|
+
property :module, default: Integer
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
expect(&valid_property_definition).not_to raise_error
|
34
|
+
end
|
35
|
+
|
17
36
|
it "should not accept default values that may be mutated" do
|
18
37
|
invalid_property_definition = lambda do
|
19
38
|
klass.class_eval do
|
data/spec/inheritance_spec.rb
CHANGED
@@ -225,4 +225,34 @@ RSpec.describe SmartProperties, 'intheritance' do
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
end
|
228
|
+
|
229
|
+
it "supports multiple inheritance through modules" do
|
230
|
+
m = Module.new do
|
231
|
+
include SmartProperties
|
232
|
+
property :m, default: 1
|
233
|
+
end
|
234
|
+
|
235
|
+
n = Module.new do
|
236
|
+
include SmartProperties
|
237
|
+
property :n, default: 2
|
238
|
+
end
|
239
|
+
|
240
|
+
o = Module.new {}
|
241
|
+
|
242
|
+
klass = Class.new do
|
243
|
+
include m
|
244
|
+
include o
|
245
|
+
include n
|
246
|
+
end
|
247
|
+
|
248
|
+
n.module_eval do
|
249
|
+
property :p, default: 3
|
250
|
+
end
|
251
|
+
|
252
|
+
instance = klass.new
|
253
|
+
|
254
|
+
expect(instance.m).to eq(1)
|
255
|
+
expect(instance.n).to eq(2)
|
256
|
+
expect(instance.p).to eq(3)
|
257
|
+
end
|
228
258
|
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.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Tennhard
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +62,7 @@ executables: []
|
|
62
62
|
extensions: []
|
63
63
|
extra_rdoc_files: []
|
64
64
|
files:
|
65
|
+
- ".github/workflows/testing.yml"
|
65
66
|
- ".gitignore"
|
66
67
|
- ".ruby-version"
|
67
68
|
- ".yardopts"
|
@@ -95,8 +96,9 @@ files:
|
|
95
96
|
- spec/writable_spec.rb
|
96
97
|
homepage: ''
|
97
98
|
licenses: []
|
98
|
-
metadata:
|
99
|
-
|
99
|
+
metadata:
|
100
|
+
source_code_uri: https://github.com/t6d/smart_properties
|
101
|
+
post_install_message:
|
100
102
|
rdoc_options: []
|
101
103
|
require_paths:
|
102
104
|
- lib
|
@@ -111,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
113
|
- !ruby/object:Gem::Version
|
112
114
|
version: '0'
|
113
115
|
requirements: []
|
114
|
-
rubygems_version: 3.
|
115
|
-
signing_key:
|
116
|
+
rubygems_version: 3.2.3
|
117
|
+
signing_key:
|
116
118
|
specification_version: 4
|
117
119
|
summary: SmartProperties – Ruby accessors on steroids
|
118
120
|
test_files:
|