safestruct 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f085259a240f99941fe60eef6a271a6066e649d3
4
- data.tar.gz: a289d416c0ade1aa76eae8e0c897fac7b63e6700
3
+ metadata.gz: 45b65afeb50dbc59c31112c55d488a76b0de48b5
4
+ data.tar.gz: 82b0e94423bfd55c11d4d4667d29017ec7e12cea
5
5
  SHA512:
6
- metadata.gz: 7a71c903f7ecddfe2a42c48465f7a76969db5566e7d0cdf18bf53878f5bad067c7b7e86029a1516e5515124547a6ce5a2c9badc36f84e1a1ca05cb6fcd049e65
7
- data.tar.gz: aade5b05f5666e89204cd5b95a4561829d7f70bae9380a7d204013527bdd03e21757c9f30f379c74f5ced2b558e25b702ccf1cbcaa13cd2d4e9df71c833688fb
6
+ metadata.gz: 13400c0b1154a455baae1b46108186e1c5d8a6cc03608f0a924b21fb8656b61182b803e9c63c5a3fc2138c0b0ed1b516e0f5f1ae7ff252be6e39e9c313e8cb31
7
+ data.tar.gz: 80f08cf43e05456ee749e5a2249191cfd74bb7149512c3169ae98db305b3caa3ae8ce60971184324c546f8a7f284d41c8b8e234b3b3819a97e9314f2843f116d
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Hoe.spec 'safestruct' do
18
18
  self.history_file = 'CHANGELOG.md'
19
19
 
20
20
  self.extra_deps = [
21
- ['enums', '>=1.1.0'],
21
+ ['enums', '>=1.1.1'],
22
22
  ]
23
23
 
24
24
  self.licenses = ['Public Domain']
@@ -26,6 +26,7 @@ class Integer
26
26
  def zero?() self == self.class.zero; end
27
27
  end
28
28
 
29
+
29
30
  class Bool
30
31
  def self.zero() false; end ## note: false.frozen? == true by default
31
32
  end
@@ -88,14 +89,21 @@ class Array
88
89
  end
89
90
 
90
91
 
91
-
92
- module Safe
92
+ module Classic ## use/add Unsafe alias too - why? why not?
93
93
  ############################
94
94
  # note: HACK redefine built in struct in module Safe "context"
95
- ClassicStruct = ::Struct ## save old classic struct class
96
- Struct = SafeStruct
95
+ Struct = ::Struct ## save old classic struct class
96
+
97
+ ### add Hash and Array too - why? why not?
98
+ end
99
+
100
+
101
+
102
+
103
+ module Safe
104
+ Struct = SafeStruct
97
105
 
98
- module ClassMethods
106
+ module SafeHelper
99
107
  ## add more convenience "constructor" methods
100
108
  ## e.g. struct 'Voter', { weight: 0, voted: false, vote: 0, delegate: '0x0000'}
101
109
  ## or struct 'Voter', weight: 0, voted: false, vote: 0, delegate: '0x0000'
@@ -107,7 +115,7 @@ module Safe
107
115
  ## - hash( class_name, ...) and
108
116
  ## - array( class_name, ...) for now
109
117
  ## why? why not? needs more testing/considerations for overloading / breaking builtin defaults
110
- end # module ClassMethods
118
+ end # module SafeHelper
111
119
  end # module Safe
112
120
 
113
121
 
@@ -37,6 +37,16 @@ class SafeArray
37
37
 
38
38
  ## add to cache for later (re)use
39
39
  cache[ klass_value ][ size ] = klass
40
+
41
+ ## note: also add a Constant to Safe for easy debugging and (re)use - will "auto"name class
42
+ class_name = "Array"
43
+ class_name << "#{size}" if size > 0 ## add size if non-zero
44
+
45
+ name = klass_value.name
46
+ name = name.sub( /\bSafe::/, '' ) ## remove safe module from name if present
47
+ name = name.gsub( '::', '' ) ## remove module separator if present
48
+ class_name << "_#{name}"
49
+ Safe.const_set( class_name, klass )
40
50
  end
41
51
  klass
42
52
  end
@@ -55,6 +55,19 @@ class SafeHash
55
55
 
56
56
  ## add to cache for later (re)use
57
57
  cache[ klass_value ] = klass
58
+
59
+ ## note: also add a Constant to Safe for easy debugging and (re)use - will "auto"name class
60
+ ## note: use X for now for key class name
61
+ class_name = "Hash_X"
62
+
63
+ name = klass_value.name
64
+ name = name.sub( /\bSafe::/, '' ) ## remove safe module from name if present
65
+ name = name.gsub( '::', '' ) ## remove module separator if present
66
+ class_name << "_#{name}"
67
+ if debug?
68
+ puts "[debug] SafeHash - class_name >#{class_name}<"
69
+ end
70
+ Safe.const_set( class_name, klass )
58
71
  else
59
72
  if debug?
60
73
  puts "[debug] SafeHash - build_class bingo!! (re)use cached class:"
@@ -12,7 +12,7 @@ module SaferStruct
12
12
 
13
13
  MAJOR = 1
14
14
  MINOR = 2
15
- PATCH = 1
15
+ PATCH = 2
16
16
  VERSION = [MAJOR,MINOR,PATCH].join('.')
17
17
 
18
18
  def self.version
@@ -4,10 +4,16 @@
4
4
  module Safe
5
5
 
6
6
  ## sig: [Integer, Bool, Integer, Address]
7
- Struct.new( :Voter,
8
- weight: 0,
9
- voted: false,
10
- vote: 0,
11
- delegate: '0x0000' )
7
+ ## Struct.new( :Voter,
8
+ ## weight: 0,
9
+ ## voted: false,
10
+ ## vote: 0,
11
+ ## delegate: '0x0000' )
12
+
13
+ struct :Voter,
14
+ weight: 0,
15
+ voted: false,
16
+ vote: 0,
17
+ delegate: '0x0000'
12
18
 
13
19
  end # module Safe
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safestruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-20 00:00:00.000000000 Z
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: enums
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0
19
+ version: 1.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.0
26
+ version: 1.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement