wxruby3-shapes 0.9.0.pre.beta.3 → 0.9.6
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/INSTALL.md +5 -7
- data/README.md +38 -6
- data/assets/logo.svg +339 -0
- data/assets/logo.xpm +60 -0
- data/assets/screenshot.png +0 -0
- data/assets/social.png +0 -0
- data/bin/wx-shapes +1 -1
- data/lib/wx/shapes/arrow_base.rb +4 -11
- data/lib/wx/shapes/arrows/circle_arrow.rb +22 -11
- data/lib/wx/shapes/arrows/circle_prong_arrow.rb +48 -0
- data/lib/wx/shapes/arrows/cross_bar_arrow.rb +57 -0
- data/lib/wx/shapes/arrows/cross_bar_circle_arrow.rb +56 -0
- data/lib/wx/shapes/arrows/cross_bar_prong_arrow.rb +49 -0
- data/lib/wx/shapes/arrows/crossed_circle.rb +46 -0
- data/lib/wx/shapes/arrows/cup_arrow.rb +65 -0
- data/lib/wx/shapes/arrows/diamond_arrow.rb +8 -13
- data/lib/wx/shapes/arrows/double_cross_bar_arrow.rb +27 -0
- data/lib/wx/shapes/arrows/filled_arrow.rb +60 -0
- data/lib/wx/shapes/arrows/line_arrow.rb +67 -0
- data/lib/wx/shapes/arrows/open_arrow.rb +22 -23
- data/lib/wx/shapes/arrows/prong_arrow.rb +42 -0
- data/lib/wx/shapes/arrows/solid_arrow.rb +21 -35
- data/lib/wx/shapes/arrows/square_arrow.rb +37 -0
- data/lib/wx/shapes/auto_layout.rb +2 -2
- data/lib/wx/shapes/base.rb +1 -1
- data/lib/wx/shapes/canvas_history.rb +20 -0
- data/lib/wx/shapes/connection_point.rb +10 -6
- data/lib/wx/shapes/diagram.rb +98 -78
- data/lib/wx/shapes/events.rb +8 -8
- data/lib/wx/shapes/printout.rb +3 -16
- data/lib/wx/shapes/serializable.rb +2 -436
- data/lib/wx/shapes/serialize/wx.rb +30 -18
- data/lib/wx/shapes/shape.rb +211 -168
- data/lib/wx/shapes/shape_canvas.rb +728 -267
- data/lib/wx/shapes/shape_data_object.rb +99 -18
- data/lib/wx/shapes/shape_handle.rb +18 -11
- data/lib/wx/shapes/shape_list.rb +34 -67
- data/lib/wx/shapes/shapes/bitmap_shape.rb +23 -24
- data/lib/wx/shapes/shapes/box_shape.rb +389 -0
- data/lib/wx/shapes/shapes/circle_shape.rb +19 -22
- data/lib/wx/shapes/shapes/control_shape.rb +77 -41
- data/lib/wx/shapes/shapes/curve_shape.rb +38 -31
- data/lib/wx/shapes/shapes/diamond_shape.rb +7 -17
- data/lib/wx/shapes/shapes/edit_text_shape.rb +6 -9
- data/lib/wx/shapes/shapes/ellipse_shape.rb +12 -15
- data/lib/wx/shapes/shapes/flex_grid_shape.rb +58 -33
- data/lib/wx/shapes/shapes/grid_shape.rb +259 -161
- data/lib/wx/shapes/shapes/line_shape.rb +155 -161
- data/lib/wx/shapes/shapes/manager_shape.rb +77 -0
- data/lib/wx/shapes/shapes/multi_sel_rect.rb +8 -8
- data/lib/wx/shapes/shapes/ortho_shape.rb +31 -36
- data/lib/wx/shapes/shapes/polygon_shape.rb +23 -29
- data/lib/wx/shapes/shapes/rect_shape.rb +95 -53
- data/lib/wx/shapes/shapes/round_ortho_shape.rb +6 -8
- data/lib/wx/shapes/shapes/round_rect_shape.rb +20 -24
- data/lib/wx/shapes/shapes/square_shape.rb +14 -17
- data/lib/wx/shapes/shapes/text_shape.rb +95 -53
- data/lib/wx/shapes/version.rb +1 -1
- data/lib/wx/shapes/wx.rb +16 -7
- data/lib/wx/wx-shapes/cmd/test.rb +1 -1
- data/samples/demo/arrows.json +1 -0
- data/samples/demo/arrows.yaml +793 -0
- data/samples/demo/art/HBox.xpm +22 -0
- data/samples/demo/art/VBox.xpm +22 -0
- data/samples/demo/art/logo.xpm +60 -0
- data/samples/demo/class.json +1 -0
- data/samples/demo/class.yaml +5631 -0
- data/samples/demo/demo.rb +301 -91
- data/samples/demo/dialogs.rb +1405 -0
- data/samples/demo/erd.json +1 -0
- data/samples/demo/erd.yaml +4072 -0
- data/samples/demo/frame_canvas.rb +409 -33
- data/samples/sample1/art/logo.xpm +60 -0
- data/samples/sample1/sample.rb +11 -11
- data/samples/sample2/art/logo.xpm +60 -0
- data/samples/sample2/sample.rb +2 -2
- data/samples/sample2/sample_shape.rb +15 -15
- data/samples/sample3/art/logo.xpm +60 -0
- data/samples/sample3/sample.rb +3 -3
- data/samples/sample4/art/logo.xpm +60 -0
- data/samples/sample4/sample.rb +2 -2
- data/tests/lib/wxapp_runner.rb +4 -0
- data/tests/serializer_tests.rb +8 -441
- data/tests/test_grid_shapes.rb +2 -2
- data/tests/test_serialize_xml.rb +17 -0
- data/tests/test_serialize_yaml.rb +2 -2
- metadata +78 -28
- data/lib/wx/shapes/serialize/core.rb +0 -40
- data/lib/wx/shapes/serialize/id.rb +0 -82
- data/lib/wx/shapes/serializer/json.rb +0 -258
- data/lib/wx/shapes/serializer/yaml.rb +0 -125
- data/samples/demo/art/sample.xpm +0 -251
- data/samples/sample1/art/sample.xpm +0 -251
- data/samples/sample2/art/sample.xpm +0 -251
- data/samples/sample3/art/sample.xpm +0 -251
- data/samples/sample4/art/sample.xpm +0 -251
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wxruby3-shapes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Corino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: nokogiri
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.12'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.12'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +52,62 @@ dependencies:
|
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: firm
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: wxruby3
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: '1.3'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: wxruby3-mdap
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
76
104
|
type: :runtime
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
110
|
+
version: '1.0'
|
83
111
|
description: wxRuby3/Shapes is a pure Ruby library providing 2D shapes and diagramming
|
84
112
|
framework based on wxRuby3
|
85
113
|
email: mcorino@m2c-software.nl
|
@@ -93,14 +121,28 @@ files:
|
|
93
121
|
- INSTALL.md
|
94
122
|
- LICENSE
|
95
123
|
- README.md
|
124
|
+
- assets/logo.svg
|
125
|
+
- assets/logo.xpm
|
96
126
|
- assets/screenshot.png
|
127
|
+
- assets/social.png
|
97
128
|
- bin/wx-shapes
|
98
129
|
- lib/wx/shapes.rb
|
99
130
|
- lib/wx/shapes/arrow_base.rb
|
100
131
|
- lib/wx/shapes/arrows/circle_arrow.rb
|
132
|
+
- lib/wx/shapes/arrows/circle_prong_arrow.rb
|
133
|
+
- lib/wx/shapes/arrows/cross_bar_arrow.rb
|
134
|
+
- lib/wx/shapes/arrows/cross_bar_circle_arrow.rb
|
135
|
+
- lib/wx/shapes/arrows/cross_bar_prong_arrow.rb
|
136
|
+
- lib/wx/shapes/arrows/crossed_circle.rb
|
137
|
+
- lib/wx/shapes/arrows/cup_arrow.rb
|
101
138
|
- lib/wx/shapes/arrows/diamond_arrow.rb
|
139
|
+
- lib/wx/shapes/arrows/double_cross_bar_arrow.rb
|
140
|
+
- lib/wx/shapes/arrows/filled_arrow.rb
|
141
|
+
- lib/wx/shapes/arrows/line_arrow.rb
|
102
142
|
- lib/wx/shapes/arrows/open_arrow.rb
|
143
|
+
- lib/wx/shapes/arrows/prong_arrow.rb
|
103
144
|
- lib/wx/shapes/arrows/solid_arrow.rb
|
145
|
+
- lib/wx/shapes/arrows/square_arrow.rb
|
104
146
|
- lib/wx/shapes/art/shape_canvas/page.xpm
|
105
147
|
- lib/wx/shapes/auto_layout.rb
|
106
148
|
- lib/wx/shapes/base.rb
|
@@ -111,17 +153,14 @@ files:
|
|
111
153
|
- lib/wx/shapes/events.rb
|
112
154
|
- lib/wx/shapes/printout.rb
|
113
155
|
- lib/wx/shapes/serializable.rb
|
114
|
-
- lib/wx/shapes/serialize/core.rb
|
115
|
-
- lib/wx/shapes/serialize/id.rb
|
116
156
|
- lib/wx/shapes/serialize/wx.rb
|
117
|
-
- lib/wx/shapes/serializer/json.rb
|
118
|
-
- lib/wx/shapes/serializer/yaml.rb
|
119
157
|
- lib/wx/shapes/shape.rb
|
120
158
|
- lib/wx/shapes/shape_canvas.rb
|
121
159
|
- lib/wx/shapes/shape_data_object.rb
|
122
160
|
- lib/wx/shapes/shape_handle.rb
|
123
161
|
- lib/wx/shapes/shape_list.rb
|
124
162
|
- lib/wx/shapes/shapes/bitmap_shape.rb
|
163
|
+
- lib/wx/shapes/shapes/box_shape.rb
|
125
164
|
- lib/wx/shapes/shapes/circle_shape.rb
|
126
165
|
- lib/wx/shapes/shapes/control_shape.rb
|
127
166
|
- lib/wx/shapes/shapes/curve_shape.rb
|
@@ -131,6 +170,7 @@ files:
|
|
131
170
|
- lib/wx/shapes/shapes/flex_grid_shape.rb
|
132
171
|
- lib/wx/shapes/shapes/grid_shape.rb
|
133
172
|
- lib/wx/shapes/shapes/line_shape.rb
|
173
|
+
- lib/wx/shapes/shapes/manager_shape.rb
|
134
174
|
- lib/wx/shapes/shapes/multi_sel_rect.rb
|
135
175
|
- lib/wx/shapes/shapes/ortho_shape.rb
|
136
176
|
- lib/wx/shapes/shapes/polygon_shape.rb
|
@@ -151,6 +191,8 @@ files:
|
|
151
191
|
- rakelib/yard/yard-relative_markdown_links.rb
|
152
192
|
- rakelib/yard/yard/relative_markdown_links.rb
|
153
193
|
- rakelib/yard/yard/relative_markdown_links/version.rb
|
194
|
+
- samples/demo/arrows.json
|
195
|
+
- samples/demo/arrows.yaml
|
154
196
|
- samples/demo/art/AlignBottom.xpm
|
155
197
|
- samples/demo/art/AlignCenter.xpm
|
156
198
|
- samples/demo/art/AlignLeft.xpm
|
@@ -167,6 +209,7 @@ files:
|
|
167
209
|
- samples/demo/art/FlexGrid.xpm
|
168
210
|
- samples/demo/art/GC.xpm
|
169
211
|
- samples/demo/art/Grid.xpm
|
212
|
+
- samples/demo/art/HBox.xpm
|
170
213
|
- samples/demo/art/Line.xpm
|
171
214
|
- samples/demo/art/NoSource.xpm
|
172
215
|
- samples/demo/art/OrthoLine.xpm
|
@@ -177,26 +220,33 @@ files:
|
|
177
220
|
- samples/demo/art/StandAloneLine.xpm
|
178
221
|
- samples/demo/art/Text.xpm
|
179
222
|
- samples/demo/art/Tool.xpm
|
180
|
-
- samples/demo/art/
|
223
|
+
- samples/demo/art/VBox.xpm
|
224
|
+
- samples/demo/art/logo.xpm
|
225
|
+
- samples/demo/class.json
|
226
|
+
- samples/demo/class.yaml
|
181
227
|
- samples/demo/demo.rb
|
228
|
+
- samples/demo/dialogs.rb
|
229
|
+
- samples/demo/erd.json
|
230
|
+
- samples/demo/erd.yaml
|
182
231
|
- samples/demo/frame_canvas.rb
|
183
232
|
- samples/demo/images/motyl.bmp
|
184
233
|
- samples/demo/images/motyl2.bmp
|
185
|
-
- samples/sample1/art/
|
234
|
+
- samples/sample1/art/logo.xpm
|
186
235
|
- samples/sample1/sample.rb
|
187
|
-
- samples/sample2/art/
|
236
|
+
- samples/sample2/art/logo.xpm
|
188
237
|
- samples/sample2/sample.rb
|
189
238
|
- samples/sample2/sample_canvas.rb
|
190
239
|
- samples/sample2/sample_shape.rb
|
191
|
-
- samples/sample3/art/
|
240
|
+
- samples/sample3/art/logo.xpm
|
192
241
|
- samples/sample3/sample.rb
|
193
|
-
- samples/sample4/art/
|
242
|
+
- samples/sample4/art/logo.xpm
|
194
243
|
- samples/sample4/sample.rb
|
195
244
|
- tests/art/motyl.bmp
|
196
245
|
- tests/lib/wxapp_runner.rb
|
197
246
|
- tests/serializer_tests.rb
|
198
247
|
- tests/test_grid_shapes.rb
|
199
248
|
- tests/test_serialize.rb
|
249
|
+
- tests/test_serialize_xml.rb
|
200
250
|
- tests/test_serialize_yaml.rb
|
201
251
|
homepage: https://github.com/mcorino/wxRuby3-shapes
|
202
252
|
licenses:
|
@@ -235,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
285
|
- !ruby/object:Gem::Version
|
236
286
|
version: '0'
|
237
287
|
requirements: []
|
238
|
-
rubygems_version: 3.
|
288
|
+
rubygems_version: 3.3.5
|
239
289
|
signing_key:
|
240
290
|
specification_version: 4
|
241
291
|
summary: wxRuby3 2D shapes and diagramming framework
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# Wx::SF::Serializer - Ruby core serializer extensions
|
2
|
-
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
-
|
4
|
-
# we do not include Wx::SF::Serializer::SerializeMethod here as that would
|
5
|
-
# also extend these classes with the engine specific extension that we do not
|
6
|
-
# need or want here
|
7
|
-
|
8
|
-
class Array
|
9
|
-
def serialize(io = nil, pretty: false, format: Wx::SF::Serializable.default_format)
|
10
|
-
Wx::SF::Serializable[format].dump(self, io, pretty: pretty)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Hash
|
15
|
-
def serialize(io = nil, pretty: false, format: Wx::SF::Serializable.default_format)
|
16
|
-
Wx::SF::Serializable[format].dump(self, io, pretty: pretty)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Struct
|
21
|
-
def serialize(io = nil, pretty: false, format: Wx::SF::Serializable.default_format)
|
22
|
-
Wx::SF::Serializable[format].dump(self, io, pretty: pretty)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require 'set'
|
27
|
-
|
28
|
-
class Set
|
29
|
-
def serialize(io = nil, pretty: false, format: Wx::SF::Serializable.default_format)
|
30
|
-
Wx::SF::Serializable[format].dump(self, io, pretty: pretty)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
require 'ostruct'
|
35
|
-
|
36
|
-
class OpenStruct
|
37
|
-
def serialize(io = nil, pretty: false, format: Wx::SF::Serializable.default_format)
|
38
|
-
Wx::SF::Serializable[format].dump(self, io, pretty: pretty)
|
39
|
-
end
|
40
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# Wx::SF::Serializer - Wx::SF serializable ID class
|
2
|
-
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
-
|
4
|
-
module Wx::SF::Serializable
|
5
|
-
|
6
|
-
class ID
|
7
|
-
|
8
|
-
include Wx::SF::Serializable
|
9
|
-
|
10
|
-
class << self
|
11
|
-
|
12
|
-
TLS_RESTORATION_MAP_KEY = :wx_sf_serializable_id_restoration_map.freeze
|
13
|
-
private_constant :TLS_RESTORATION_MAP_KEY
|
14
|
-
|
15
|
-
def init_restoration_map
|
16
|
-
(::Thread.current[TLS_RESTORATION_MAP_KEY] ||= []) << {}
|
17
|
-
end
|
18
|
-
|
19
|
-
def clear_restoration_map
|
20
|
-
::Thread.current[TLS_RESTORATION_MAP_KEY].pop
|
21
|
-
end
|
22
|
-
|
23
|
-
def restoration_map
|
24
|
-
::Thread.current[TLS_RESTORATION_MAP_KEY].last
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
# Returns a Serialized::Id instance matching the deserialized id number
|
30
|
-
# either by retrieving an earlier restored Id from the (thread/fiber-)current
|
31
|
-
# restoration map or creating (and mapping) a new Id instance.
|
32
|
-
# @param [Hash] data deserialized properties hash
|
33
|
-
# @return [ID] restored ID instance
|
34
|
-
# @see SerializeClassMethods#create_for_deserialize
|
35
|
-
def self.create_for_deserialize(data)
|
36
|
-
serialized_id = data[:id] || 0
|
37
|
-
restoration_map[serialized_id] ||= self.new
|
38
|
-
end
|
39
|
-
|
40
|
-
# Collects the ID's object_id for serialization.
|
41
|
-
# Note that this is fixed and cannot be excluded.
|
42
|
-
# @param [Hash] hash property serialization hash
|
43
|
-
# @param [Set] _excludes ignored
|
44
|
-
# @return [Hash] property serialization hash
|
45
|
-
def for_serialize(hash, _excludes=nil)
|
46
|
-
hash[:id] = self.object_id
|
47
|
-
hash
|
48
|
-
end
|
49
|
-
protected :for_serialize
|
50
|
-
|
51
|
-
# Noop for ID instances.
|
52
|
-
# @param [Hash] _hash ignored
|
53
|
-
# @return [self]
|
54
|
-
def from_serialized(_hash)
|
55
|
-
# no deserializing necessary
|
56
|
-
self
|
57
|
-
end
|
58
|
-
protected :from_serialized
|
59
|
-
|
60
|
-
# Always returns false for IDs.
|
61
|
-
# @return [Boolean]
|
62
|
-
def serialize_disabled?
|
63
|
-
false
|
64
|
-
end
|
65
|
-
|
66
|
-
def to_s
|
67
|
-
"Wx::SF::Serializable::ID<#{object_id}>"
|
68
|
-
end
|
69
|
-
|
70
|
-
def inspect
|
71
|
-
to_s
|
72
|
-
end
|
73
|
-
|
74
|
-
def to_i
|
75
|
-
object_id
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
serializables << ID
|
81
|
-
|
82
|
-
end
|
@@ -1,258 +0,0 @@
|
|
1
|
-
# Wx::SF::Serializer - shape serializer module
|
2
|
-
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
-
|
4
|
-
require 'json'
|
5
|
-
require 'json/add/core'
|
6
|
-
require 'json/add/set'
|
7
|
-
require 'json/add/ostruct'
|
8
|
-
|
9
|
-
module Wx::SF
|
10
|
-
|
11
|
-
module Serializable
|
12
|
-
|
13
|
-
module JSON
|
14
|
-
|
15
|
-
# Derived Hash class to use for deserialized JSON object data which
|
16
|
-
# supports using Symbol keys.
|
17
|
-
class ObjectHash < ::Hash
|
18
|
-
# Returns the object associated with given key.
|
19
|
-
# @param [String,Symbol] key key value
|
20
|
-
# @return [Object] associated object
|
21
|
-
# @see ::Hash#[]
|
22
|
-
def [](key)
|
23
|
-
super(key.to_s)
|
24
|
-
end
|
25
|
-
# Returns true if the given key exists in self otherwise false.
|
26
|
-
# @param [String,Symbol] key key value
|
27
|
-
# @return [Boolean]
|
28
|
-
# @see ::Hash#include?
|
29
|
-
def include?(key)
|
30
|
-
super(key.to_s)
|
31
|
-
end
|
32
|
-
alias member? include?
|
33
|
-
alias has_key? include?
|
34
|
-
alias key? include?
|
35
|
-
end
|
36
|
-
|
37
|
-
# Mixin module to patch hash objects during JSON serialization.
|
38
|
-
# By default JSON will not consider hash keys for custom serialization
|
39
|
-
# but assumes any key should be serialized as it's string representation.
|
40
|
-
# This is restrictive but compatible with "pure" JSON object notation.
|
41
|
-
# JSON however also does not (correctly?) honour overriding Hash#to_json to
|
42
|
-
# customize serialization of Hash-es which seems too restrictive (stupid?)
|
43
|
-
# as using more complex custom keys for Hash-es instead of String/Symbol-s
|
44
|
-
# is not that uncommon.
|
45
|
-
# This mixin is used to "patch" Hash **instances** through #extend.
|
46
|
-
module HashInstancePatch
|
47
|
-
def patch_nested_hashes(obj)
|
48
|
-
case obj
|
49
|
-
when ::Hash
|
50
|
-
obj.extend(HashInstancePatch) unless obj.singleton_class.include?(HashInstancePatch)
|
51
|
-
obj.each_pair { |k, v| patch_nested_hashes(k); patch_nested_hashes(v) }
|
52
|
-
when ::Array
|
53
|
-
obj.each { |e| patch_nested_hashes(e) }
|
54
|
-
end
|
55
|
-
obj
|
56
|
-
end
|
57
|
-
private :patch_nested_hashes
|
58
|
-
|
59
|
-
# Returns JSON representation (String) of self.
|
60
|
-
# Hash data which is part of object properties/members being serialized
|
61
|
-
# (including any nested Hash-es) will be patched with HashInstancePatch.
|
62
|
-
# Patched Hash instances will be serialized as JSON-creatable objects
|
63
|
-
# (so provided with a JSON#create_id) with the hash contents represented
|
64
|
-
# as an array of key/value pairs (arrays).
|
65
|
-
# @param [Array<Object>] args any args passed by the JSON generator
|
66
|
-
# @return [String] JSON representation
|
67
|
-
def to_json(*args)
|
68
|
-
if self.has_key?(::JSON.create_id)
|
69
|
-
if self.has_key?('data')
|
70
|
-
if (data = self['data']).is_a?(::Hash)
|
71
|
-
data.each_value { |v| patch_nested_hashes(v) }
|
72
|
-
end
|
73
|
-
else # core class extensions use different data members for property serialization
|
74
|
-
self.each_value { |v| patch_nested_hashes(v) }
|
75
|
-
end
|
76
|
-
super
|
77
|
-
else
|
78
|
-
{
|
79
|
-
::JSON.create_id => self.class.name,
|
80
|
-
'data' => patch_nested_hashes(to_a)
|
81
|
-
}.to_json(*args)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# Mixin module to patch singleton_clas of the Hash class to make Hash-es
|
87
|
-
# JSON creatable (#json_creatable? returns true).
|
88
|
-
module HashClassPatch
|
89
|
-
# Create a new Hash instance from deserialized JSON data.
|
90
|
-
# @param [Hash] object deserialized JSON object
|
91
|
-
# @return [Hash] restored Hash instance
|
92
|
-
def json_create(object)
|
93
|
-
object['data'].to_h
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
class ::Hash
|
98
|
-
include Wx::SF::Serializable::JSON::HashInstancePatch
|
99
|
-
class << self
|
100
|
-
include Wx::SF::Serializable::JSON::HashClassPatch
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
class << self
|
105
|
-
def serializables
|
106
|
-
::Set.new [::NilClass, ::TrueClass, ::FalseClass, ::Integer, ::Float, ::String, ::Array, ::Hash,
|
107
|
-
::Date, ::DateTime, ::Exception, ::Range, ::Regexp, ::Struct, ::Symbol, ::Time, ::Set, ::OpenStruct]
|
108
|
-
end
|
109
|
-
|
110
|
-
TLS_SAFE_DESERIALIZE_KEY = :wx_sf_json_safe_deserialize.freeze
|
111
|
-
private_constant :TLS_SAFE_DESERIALIZE_KEY
|
112
|
-
|
113
|
-
TLS_PARSE_STACK_KEY = :wx_sf_json_parse_stack.freeze
|
114
|
-
private_constant :TLS_PARSE_STACK_KEY
|
115
|
-
|
116
|
-
def safe_deserialize
|
117
|
-
::Thread.current[TLS_SAFE_DESERIALIZE_KEY] ||= []
|
118
|
-
end
|
119
|
-
private :safe_deserialize
|
120
|
-
|
121
|
-
def start_safe_deserialize
|
122
|
-
safe_deserialize.push(true)
|
123
|
-
end
|
124
|
-
|
125
|
-
def end_safe_deserialize
|
126
|
-
safe_deserialize.pop
|
127
|
-
end
|
128
|
-
|
129
|
-
def parse_stack
|
130
|
-
::Thread.current[TLS_PARSE_STACK_KEY] ||= []
|
131
|
-
end
|
132
|
-
private :parse_stack
|
133
|
-
|
134
|
-
def start_parse
|
135
|
-
parse_stack.push(safe_deserialize.pop)
|
136
|
-
end
|
137
|
-
|
138
|
-
def end_parse
|
139
|
-
unless (val = parse_stack.pop).nil?
|
140
|
-
safe_deserialize.push(val)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def safe_parsing?
|
145
|
-
!!parse_stack.last
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def self.dump(obj, io=nil, pretty: false)
|
150
|
-
obj.extend(HashInstancePatch) if obj.is_a?(::Hash)
|
151
|
-
if pretty
|
152
|
-
if io || io.respond_to?(:write)
|
153
|
-
io.write(::JSON.pretty_generate(obj))
|
154
|
-
io
|
155
|
-
else
|
156
|
-
::JSON.pretty_generate(obj)
|
157
|
-
end
|
158
|
-
else
|
159
|
-
::JSON.dump(obj, io)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def self.load(source)
|
164
|
-
begin
|
165
|
-
# initialize ID restoration map
|
166
|
-
Serializable::ID.init_restoration_map
|
167
|
-
# enable safe deserializing
|
168
|
-
self.start_safe_deserialize
|
169
|
-
::JSON.parse!(source,
|
170
|
-
**{create_additions: true,
|
171
|
-
object_class: Serializable::JSON::ObjectHash})
|
172
|
-
ensure
|
173
|
-
# reset safe deserializing
|
174
|
-
self.end_safe_deserialize
|
175
|
-
# reset ID restoration map
|
176
|
-
Serializable::ID.clear_restoration_map
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
# extend serialization class methods
|
183
|
-
module SerializeClassMethods
|
184
|
-
|
185
|
-
def json_create(object)
|
186
|
-
create_for_deserialize(data = object['data'])
|
187
|
-
.__send__(:from_serialized, data)
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
# extend instance serialization methods
|
193
|
-
module SerializeInstanceMethods
|
194
|
-
|
195
|
-
def to_json(*args)
|
196
|
-
{
|
197
|
-
::JSON.create_id => self.class.name,
|
198
|
-
'data' => for_serialize(Hash.new)
|
199
|
-
}.to_json(*args)
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
class ID
|
205
|
-
|
206
|
-
def self.json_create(object)
|
207
|
-
create_for_deserialize(data = object['data'])
|
208
|
-
end
|
209
|
-
|
210
|
-
def to_json(*args)
|
211
|
-
{
|
212
|
-
::JSON.create_id => self.class.name,
|
213
|
-
'data' => for_serialize(Hash.new)
|
214
|
-
}.to_json(*args)
|
215
|
-
end
|
216
|
-
|
217
|
-
end
|
218
|
-
|
219
|
-
register(Serializable.default_format, JSON)
|
220
|
-
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
module ::JSON
|
226
|
-
class << self
|
227
|
-
|
228
|
-
alias :pre_wxsf_parse! :parse!
|
229
|
-
def parse!(*args, **kwargs)
|
230
|
-
begin
|
231
|
-
# setup parsing stack for safe or normal deserializing
|
232
|
-
# the double bracketing provided from Wx::SF::Serializable::JSON#load and here
|
233
|
-
# makes sure to support both nested Wx::SF deserializing as well as nested
|
234
|
-
# hybrid deserializing (Wx::SF -> common JSON -> ...)
|
235
|
-
Wx::SF::Serializable::JSON.start_parse
|
236
|
-
pre_wxsf_parse!(*args, **kwargs)
|
237
|
-
ensure
|
238
|
-
# reset parsing stack
|
239
|
-
Wx::SF::Serializable::JSON.end_parse
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
class ::Class
|
247
|
-
|
248
|
-
# override this to be able to do safe deserializing
|
249
|
-
def json_creatable?
|
250
|
-
if Wx::SF::Serializable::JSON.safe_parsing?
|
251
|
-
return false unless Wx::SF::Serializable::JSON.serializables.include?(self) ||
|
252
|
-
Wx::SF::Serializable.serializables.include?(self) ||
|
253
|
-
::Struct > self
|
254
|
-
end
|
255
|
-
respond_to?(:json_create)
|
256
|
-
end
|
257
|
-
|
258
|
-
end
|