classprop 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/lib/classprop.rb +17 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f81f6217d7baf2cc2b6ba28f2582d4629d9d5908202cd81a45c50389bb6e1c
|
4
|
+
data.tar.gz: 6e2d0a8268b7855097494f0fbef6f034bf329a57232fcdd9162b49de19d5b5f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2512ef8e519934c69754b52ae963fe47776bed2c60ff57038c3db8025015c9362cd7304b82a403b53fc6fd88a25f12cf3a4160f62a2bec96a0ef2de8cafa79a1
|
7
|
+
data.tar.gz: 0bb016fe201c86dd457b84ef446df6eead64057c7de4124ed8fae96ba5d0bb2a0ca22e603ad9ce840277e6e5b98a2a9e26247781e0e2073c8f5e5723357d6c7a
|
data/README.md
CHANGED
@@ -88,8 +88,9 @@ mike@idocs.com
|
|
88
88
|
|
89
89
|
## History
|
90
90
|
|
91
|
-
| version | date | notes
|
92
|
-
|
93
|
-
| 1.0 | Feb 24, 2020 | Initial upload.
|
94
|
-
| 1.1 | Feb 24, 2020 | Reworked interface.
|
95
|
-
| 1.2 | Feb 24, 2020 | Fixed minor problem with exception id.
|
91
|
+
| version | date | notes |
|
92
|
+
|---------|--------------|-------------------------------------------------------|
|
93
|
+
| 1.0 | Feb 24, 2020 | Initial upload. |
|
94
|
+
| 1.1 | Feb 24, 2020 | Reworked interface. |
|
95
|
+
| 1.2 | Feb 24, 2020 | Fixed minor problem with exception id. |
|
96
|
+
| 1.3 | Feb 26, 2020 | Added options to define_class_prop: init and inherit. |
|
data/lib/classprop.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
module ClassProp
|
5
5
|
# version
|
6
|
-
VERSION = '1.
|
6
|
+
VERSION = '1.3'
|
7
7
|
|
8
8
|
# private
|
9
9
|
private
|
@@ -44,7 +44,16 @@ module ClassProp
|
|
44
44
|
#
|
45
45
|
module ClassMethods
|
46
46
|
# Defines the set and get methods for the given property.
|
47
|
-
|
47
|
+
#
|
48
|
+
# option: init
|
49
|
+
# Sets the initial value of the property.
|
50
|
+
#
|
51
|
+
# option: inherit
|
52
|
+
# If set to false, the property is not inherited by subclasses.
|
53
|
+
def define_class_prop(prop_name, opts={})
|
54
|
+
# default options
|
55
|
+
opts = {'inherit'=>true}.merge(opts)
|
56
|
+
|
48
57
|
# set
|
49
58
|
self.define_singleton_method("#{prop_name}=") do |val|
|
50
59
|
instance_variable_set "@#{prop_name}", val
|
@@ -61,13 +70,18 @@ module ClassProp
|
|
61
70
|
return rv
|
62
71
|
end
|
63
72
|
else
|
64
|
-
if superclass.respond_to?(prop_name)
|
73
|
+
if opts['inherit'] and superclass.respond_to?(prop_name)
|
65
74
|
return superclass.public_send(prop_name)
|
66
75
|
else
|
67
76
|
return nil
|
68
77
|
end
|
69
78
|
end
|
70
79
|
end
|
80
|
+
|
81
|
+
# initial value
|
82
|
+
if opts.has_key?('init')
|
83
|
+
instance_variable_set "@#{prop_name}", opts['init']
|
84
|
+
end
|
71
85
|
end
|
72
86
|
|
73
87
|
# delete_class_prop
|
@@ -76,8 +90,6 @@ module ClassProp
|
|
76
90
|
remove_instance_variable "@#{prop_name}"
|
77
91
|
end
|
78
92
|
end
|
79
|
-
|
80
|
-
|
81
93
|
end
|
82
94
|
#
|
83
95
|
# ClassMethods
|