classprop 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -5
  3. data/lib/classprop.rb +17 -5
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7ad660c9c8aaa8d5d673f698c2069ee72605a476dc53f47e2ed3a51356d6237
4
- data.tar.gz: fa4dc3fe32fdc3fc8ad6fa3123040f39bc0272889dbe94dd7748500d7c9ca238
3
+ metadata.gz: 49f81f6217d7baf2cc2b6ba28f2582d4629d9d5908202cd81a45c50389bb6e1c
4
+ data.tar.gz: 6e2d0a8268b7855097494f0fbef6f034bf329a57232fcdd9162b49de19d5b5f1
5
5
  SHA512:
6
- metadata.gz: c6005a18b8bcd3cd0d162f67adb4d10fe210d77b4f25e24b5f6bf627c9e0299967ec7474c8cea8d8c6a79fa946f4c4ec9d7938bb7882660a37315d503b6759e3
7
- data.tar.gz: 6ef9d519cde13bfa1efe6a4696590dab767d223ebb431dd1a87a0442bdf0ba4d6f04dcab239151e6926a6b2b80f8b3fc1c2c3c4b888dc565f1bfeb7fab69cd62
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. |
@@ -3,7 +3,7 @@
3
3
  #
4
4
  module ClassProp
5
5
  # version
6
- VERSION = '1.2'
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
- def define_class_prop(prop_name)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classprop
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike O'Sullivan