firm 0.9.3 → 0.9.6

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
  SHA256:
3
- metadata.gz: 5c1c7b999e2db422d608d8aaf8e28a9bace6824640f50a8e5dabb30e2ca89a36
4
- data.tar.gz: a16d62247a09cc2e1d8b3c4d2a990ffefb7b48c18f6f1d8f27e12c770ff103eb
3
+ metadata.gz: be22317c4039737f9407836be331ea1b4c84750ba86404982e824079bbf712d2
4
+ data.tar.gz: '018828f0e65cdedc6532e7bc0114e2ba08b714ef819f4abd5c5423b1cf2e1b55'
5
5
  SHA512:
6
- metadata.gz: 6c45a0bc530a143ad8b37de7e00f6fdd4a2af91ffb52b18ce86f91ffac390ea05825d58b042e29361a96fd762be58d210d141bdb88d9748c3232e7c30232b8cc
7
- data.tar.gz: 939fe265f4f55f1255851e5f246b73ca416c6649af2ffcdad6aa8fb63341289ef64c71678bc02a7372c66acd6a91a26111ebc049d2a571b5f3f189f7010d3fb2
6
+ metadata.gz: cc7caa8558e867da5c810c8697e5c75781656a9de62b60bfd950a11ec07da24c47343979dbc392970f51e9186b9b26bc5fb7396efe6826191bed79bf3e404a5d
7
+ data.tar.gz: 58e1c3e781c8862c46f16f2ca97f66af1658a81334b306b98def70c56e3f7a39abfcb3d3ca39562e1443024c952d7118061cdd2053bab1bd69f6d768b55fd246
data/README.md CHANGED
@@ -43,6 +43,10 @@ FIRM supports (de-)serializing many core Ruby objects out of the box including:
43
43
  - `Date`
44
44
  - `DateTime`
45
45
 
46
+ For security reasons FIRM does **not** support direct (de-)serializing of `Class` objects but will rather
47
+ serialize (and deserialize) these as their scoped string names. Customized property setters can be used to
48
+ resolve Class objects from these names if really needed.
49
+
46
50
  FIRM also supports a simple scheme to provide (de-)serialization support for user defined classes.
47
51
 
48
52
  FIRM provides object aliasing support for JSON and XML in a similar fashion as the standard support provided
@@ -143,6 +143,12 @@ module FIRM
143
143
 
144
144
  class << self
145
145
 
146
+ TLS_VARS_KEY = :firm_tls_vars.freeze
147
+
148
+ def tls_vars
149
+ Thread.current[TLS_VARS_KEY] ||= {}
150
+ end
151
+
146
152
  def serializables
147
153
  @serializables ||= ::Set.new
148
154
  end
@@ -198,7 +204,7 @@ module FIRM
198
204
  private_constant :TLS_ALIAS_STACK_KEY
199
205
 
200
206
  def anchor_object_registry_stack
201
- ::Thread.current[TLS_ANCHOR_OBJECTS_KEY] ||= []
207
+ Serializable.tls_vars[TLS_ANCHOR_OBJECTS_KEY] ||= []
202
208
  end
203
209
  private :anchor_object_registry_stack
204
210
 
@@ -252,7 +258,7 @@ module FIRM
252
258
  end
253
259
 
254
260
  def anchor_references_stack
255
- ::Thread.current[TLS_ALIAS_STACK_KEY] ||= []
261
+ Serializable.tls_vars[TLS_ALIAS_STACK_KEY] ||= []
256
262
  end
257
263
  private :anchor_references_stack
258
264
 
@@ -70,7 +70,7 @@ module FIRM
70
70
  private_constant :TLS_PARSE_STACK_KEY
71
71
 
72
72
  def safe_deserialize
73
- ::Thread.current[TLS_SAFE_DESERIALIZE_KEY] ||= []
73
+ Serializable.tls_vars[TLS_SAFE_DESERIALIZE_KEY] ||= []
74
74
  end
75
75
  private :safe_deserialize
76
76
 
@@ -83,7 +83,7 @@ module FIRM
83
83
  end
84
84
 
85
85
  def parse_stack
86
- ::Thread.current[TLS_PARSE_STACK_KEY] ||= []
86
+ Serializable.tls_vars[TLS_PARSE_STACK_KEY] ||= []
87
87
  end
88
88
  private :parse_stack
89
89
 
@@ -20,7 +20,7 @@ module FIRM
20
20
  private_constant :TLS_STATE_KEY
21
21
 
22
22
  def xml_state
23
- ::Thread.current[TLS_STATE_KEY] ||= []
23
+ Serializable.tls_vars[TLS_STATE_KEY] ||= []
24
24
  end
25
25
  private :xml_state
26
26
 
@@ -133,6 +133,22 @@ module FIRM
133
133
  end
134
134
  end
135
135
 
136
+ # registered as tag 'Class' but that is never actually used
137
+ define_xml_handler(::Class, 'Class') do
138
+ # overload to emit 'String' tags
139
+ def create_type_node(xml)
140
+ xml.add_child(Nokogiri::XML::Node.new('String', xml.document))
141
+ end
142
+ def to_xml(xml, value)
143
+ create_type_node(xml).add_child(Nokogiri::XML::CDATA.new(xml.document, value.name))
144
+ xml
145
+ end
146
+ def from_xml(xml)
147
+ # should never be called
148
+ raise Serializable::Exception, 'Unsupported Class deserialization'
149
+ end
150
+ end
151
+
136
152
  define_xml_handler(::NilClass, :nil) do
137
153
  def to_xml(xml, _value)
138
154
  create_type_node(xml)
@@ -68,8 +68,26 @@ module FIRM
68
68
  end
69
69
  end
70
70
 
71
+ # Derived Psych YAMLTree class to emit simple strings for
72
+ # Class instances
73
+ class NoClassYAMLTree < ::Psych::Visitors::YAMLTree
74
+
75
+ def visit_Class(o)
76
+ raise TypeError, "can't dump anonymous module: #{o}" unless o.name
77
+ visit_String(o.name)
78
+ end
79
+
80
+ def visit_Module(o)
81
+ raise TypeError, "can't dump anonymous class: #{o}" unless o.name
82
+ visit_String(o.name)
83
+ end
84
+
85
+ end
86
+
71
87
  def self.dump(obj, io=nil, **)
72
- ::YAML.dump(obj, io)
88
+ visitor = YAML::NoClassYAMLTree.create
89
+ visitor << obj
90
+ visitor.tree.yaml io
73
91
  end
74
92
 
75
93
  def self.load(source)
data/lib/firm/version.rb CHANGED
@@ -4,6 +4,6 @@
4
4
  module FIRM
5
5
 
6
6
  # FIRM version
7
- VERSION = "0.9.3"
7
+ VERSION = "0.9.6"
8
8
 
9
9
  end
@@ -292,6 +292,17 @@ module SerializerTestMixin
292
292
 
293
293
  end
294
294
 
295
+ def test_class
296
+
297
+ obj_serial = [Point, Colour].serialize
298
+ obj_new = assert_nothing_raised { FIRM.deserialize(obj_serial) }
299
+ assert_instance_of(::Array, obj_new)
300
+ assert_true(obj_new.all? { |e| String === e })
301
+ assert_equal(Point.name, obj_new[0])
302
+ assert_equal(Colour.name, obj_new[1])
303
+
304
+ end
305
+
295
306
  class PointsOwner
296
307
  include FIRM::Serializable
297
308
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
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: 2024-09-14 00:00:00.000000000 Z
11
+ date: 2024-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake