classprop 1.0 → 1.1
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/README.md +5 -4
- data/lib/classprop.rb +2 -13
- 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: 1190b0042541c7422fdfcf7891769705395f1339fce8a59e87b663f908a93742
|
4
|
+
data.tar.gz: 9da99d32afe6924ed861cd64f9a3cc6bb3a49029bbea2a45bb35af8006abcfe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae2533a97d7e3ac3f30d9706acf6f873dab107f75dadf0cd9ee1ba509ee6d8155a30f55f0f65b70af884204cc70387d165b3777c69b2335f1b99ad1587b0fc33
|
7
|
+
data.tar.gz: 1e7aa555f28167b94874b65167756f64920ceca0b291680b8a5ac9b8744ea36946b607e5f37c7b28cbb714b8de9b4ab5e4571548663c11ba85252e78d7f8babd
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ called `fco`. Finally, it sets the value of that property to *base*.
|
|
9
9
|
class Base
|
10
10
|
include ClassProp
|
11
11
|
define_class_prop 'fco'
|
12
|
-
|
12
|
+
self.fco = 'base'
|
13
13
|
end
|
14
14
|
```
|
15
15
|
|
@@ -37,7 +37,7 @@ puts X1.fco # => 'base'
|
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
class X1
|
40
|
-
|
40
|
+
self.fco = 'x1'
|
41
41
|
end
|
42
42
|
```
|
43
43
|
|
@@ -66,7 +66,7 @@ that property then an error is raised when the property is retrieved.
|
|
66
66
|
class Base
|
67
67
|
include ClassProp
|
68
68
|
define_class_prop 'fco'
|
69
|
-
|
69
|
+
self.fco = ClassProp::MustDefine
|
70
70
|
end
|
71
71
|
|
72
72
|
class X1 < Base
|
@@ -90,4 +90,5 @@ mike@idocs.com
|
|
90
90
|
|
91
91
|
| version | date | notes |
|
92
92
|
|---------|--------------|-------------------------------|
|
93
|
-
| 1.0 | Feb 24, 2020 | Initial upload. |
|
93
|
+
| 1.0 | Feb 24, 2020 | Initial upload. |
|
94
|
+
| 1.1 | Feb 24, 2020 | Reworked interface. |
|
data/lib/classprop.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
# ClassProp
|
3
3
|
#
|
4
4
|
module ClassProp
|
5
|
-
# version 1.
|
6
|
-
VERSION = '1.
|
5
|
+
# version 1.1
|
6
|
+
VERSION = '1.1'
|
7
7
|
|
8
8
|
# private
|
9
9
|
private
|
@@ -43,17 +43,8 @@ module ClassProp
|
|
43
43
|
# ClassMethods
|
44
44
|
#
|
45
45
|
module ClassMethods
|
46
|
-
# Normalizes a property name so that any leading @ is removed.
|
47
|
-
def normalize(prop_name)
|
48
|
-
prop_name = prop_name.to_s
|
49
|
-
prop_name = prop_name.sub(/\A\@/mu, '')
|
50
|
-
return prop_name
|
51
|
-
end
|
52
|
-
|
53
46
|
# Defines the set and get methods for the given property.
|
54
47
|
def define_class_prop(prop_name)
|
55
|
-
prop_name = normalize(prop_name)
|
56
|
-
|
57
48
|
# set
|
58
49
|
self.define_singleton_method("#{prop_name}=") do |val|
|
59
50
|
instance_variable_set "@#{prop_name}", val
|
@@ -81,8 +72,6 @@ module ClassProp
|
|
81
72
|
|
82
73
|
# delete_class_prop
|
83
74
|
def delete_class_prop(prop_name)
|
84
|
-
prop_name = normalize(prop_name)
|
85
|
-
|
86
75
|
if instance_variable_defined?("@#{prop_name}")
|
87
76
|
remove_instance_variable "@#{prop_name}"
|
88
77
|
end
|