yasl 0.2.1 → 0.2.2
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/CHANGELOG.md +4 -0
- data/README.md +13 -3
- data/VERSION +1 -1
- data/lib/yasl/dumper.rb +3 -1
- data/yasl.gemspec +3 -4
- metadata +2 -3
- data/lib/yasl/ext/struct.rb +0 -148
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c75bacb520b9e29374e8b3d6b2b4ec369c2be8b73ed99376c63ec08b04c89fed
|
4
|
+
data.tar.gz: ad5b153b427ff38dd35cf4d6c0d1fef18fdc8bead3de3fcd546967f39207dc64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2e317ba827131f3bc27ccc893a03a24894251fe6d5b7a4bbbb1cf5e7b6df91397e0df93bfceaa8ba1920b09e9c0490ee343adb5750de5370b2e6f3157a475b5
|
7
|
+
data.tar.gz: d4b4b6fc515a1e26cb5f6992983aabd16305c398cecd7d566231be94b3e3198ea477dbabbc6d9ce1dfc39ee6f5af9ef511340bfff8797d91792d560aa8f31da6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Run:
|
|
26
26
|
Or add to Gemfile:
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
gem 'yasl', '~> 0.2.
|
29
|
+
gem 'yasl', '~> 0.2.2'
|
30
30
|
```
|
31
31
|
|
32
32
|
And, run:
|
@@ -309,10 +309,20 @@ puts car2.inspect
|
|
309
309
|
|
310
310
|
Struct serialization/deserialization works out of the box in standard [MRI Ruby](https://www.ruby-lang.org/) and [JRuby](https://www.jruby.org/).
|
311
311
|
|
312
|
-
|
312
|
+
`Struct` in [Opal](https://opalrb.com/) has some odd JS issues and `keyword_init` gotchas unrelated to YASL. To completely avoid these issues, you may use the optional pure Ruby `Struct` re-implementation in the [pure-struct](https://github.com/AndyObtiva/pure-struct) gem:
|
313
313
|
|
314
314
|
```ruby
|
315
|
-
require '
|
315
|
+
require 'pure-struct' # depends on installing the [pure-struct](https://github.com/AndyObtiva/pure-struct) gem
|
316
|
+
require 'yasl'
|
317
|
+
```
|
318
|
+
|
319
|
+
Optionally, you may code block by the specific [Ruby](https://www.ruby-lang.org/) engine where it is needed (e.g. [Opal](https://opalrb.com/)):
|
320
|
+
|
321
|
+
```ruby
|
322
|
+
if RUBY_ENGINE == 'opal'
|
323
|
+
require 'pure-struct'
|
324
|
+
end
|
325
|
+
require 'yasl'
|
316
326
|
```
|
317
327
|
|
318
328
|
## Contributing
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/yasl/dumper.rb
CHANGED
@@ -72,7 +72,9 @@ module YASL
|
|
72
72
|
|
73
73
|
def dump_ruby_basic_data_type_data(obj)
|
74
74
|
class_ancestors_names_include = lambda do |*class_names|
|
75
|
-
lambda
|
75
|
+
lambda do |object|
|
76
|
+
class_names.any? { |class_name| obj.class.ancestors.map(&:name).include?(class_name) }
|
77
|
+
end
|
76
78
|
end
|
77
79
|
case obj
|
78
80
|
when class_ancestors_names_include['Time']
|
data/yasl.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: yasl 0.2.
|
5
|
+
# stub: yasl 0.2.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "yasl".freeze
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Andy Maleh".freeze]
|
14
|
-
s.date = "2021-01-
|
14
|
+
s.date = "2021-01-02"
|
15
15
|
s.description = "A pure Ruby serialization library that works across different Ruby implementations like Opal and JRuby as an alternative to YAML/Marshal.".freeze
|
16
16
|
s.email = "andy.am@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"lib/yasl.rb",
|
28
28
|
"lib/yasl/dumper.rb",
|
29
|
-
"lib/yasl/ext/struct.rb",
|
30
29
|
"lib/yasl/loader.rb",
|
31
30
|
"yasl.gemspec"
|
32
31
|
]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yasl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -124,7 +124,6 @@ files:
|
|
124
124
|
- VERSION
|
125
125
|
- lib/yasl.rb
|
126
126
|
- lib/yasl/dumper.rb
|
127
|
-
- lib/yasl/ext/struct.rb
|
128
127
|
- lib/yasl/loader.rb
|
129
128
|
- yasl.gemspec
|
130
129
|
homepage: http://github.com/AndyObtiva/yasl
|
data/lib/yasl/ext/struct.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
# Copyright (c) 2020 Andy Maleh
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
# a copy of this software and associated documentation files (the
|
5
|
-
# "Software"), to deal in the Software without restriction, including
|
6
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
# the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be
|
12
|
-
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
|
22
|
-
Object.send(:remove_const, :Struct) if Object.constants.include?(:Struct)
|
23
|
-
|
24
|
-
# Optional re-implmentation of Struct in Pure Ruby (to get around JS issues in Opal Struct)
|
25
|
-
class Struct
|
26
|
-
class << self
|
27
|
-
CLASS_DEFINITION_FOR_ATTRIBUTES = lambda do |attributes, keyword_init|
|
28
|
-
lambda do |defined_class|
|
29
|
-
members_array = attributes
|
30
|
-
|
31
|
-
define_method(:members) do
|
32
|
-
members_array
|
33
|
-
end
|
34
|
-
|
35
|
-
def []=(attribute, value)
|
36
|
-
normalized_attribute = attribute.to_s.to_sym
|
37
|
-
raise NameError, "no member #{attribute} in struct" unless members.include?(normalized_attribute)
|
38
|
-
@member_values[normalized_attribute] = value
|
39
|
-
end
|
40
|
-
|
41
|
-
def [](attribute)
|
42
|
-
normalized_attribute = attribute.to_s.to_sym
|
43
|
-
raise NameError, "no member #{attribute} in struct" unless members.include?(normalized_attribute)
|
44
|
-
@member_values[normalized_attribute]
|
45
|
-
end
|
46
|
-
|
47
|
-
def each(&block)
|
48
|
-
to_a.each(&block)
|
49
|
-
end
|
50
|
-
|
51
|
-
def each_pair(&block)
|
52
|
-
@member_values.each_pair(&block)
|
53
|
-
end
|
54
|
-
|
55
|
-
def to_h
|
56
|
-
@member_values.clone
|
57
|
-
end
|
58
|
-
|
59
|
-
def to_a
|
60
|
-
@member_values.values
|
61
|
-
end
|
62
|
-
|
63
|
-
def size
|
64
|
-
members.size
|
65
|
-
end
|
66
|
-
alias length size
|
67
|
-
|
68
|
-
def dig(*args)
|
69
|
-
@member_values.dig(*args)
|
70
|
-
end
|
71
|
-
|
72
|
-
def select(&block)
|
73
|
-
to_a.select(&block)
|
74
|
-
end
|
75
|
-
|
76
|
-
def eql?(other)
|
77
|
-
instance_of?(other.class) &&
|
78
|
-
members.all? { |key| self[key].eql?(other[key]) }
|
79
|
-
end
|
80
|
-
|
81
|
-
def ==(other)
|
82
|
-
other = coerce(other).first if respond_to?(:coerce, true)
|
83
|
-
other.kind_of?(self.class) &&
|
84
|
-
members.all? { |key| self[key] == other[key] }
|
85
|
-
end
|
86
|
-
|
87
|
-
def hash
|
88
|
-
self.class.hash +
|
89
|
-
to_a.each_with_index.map {|value, i| (i+1) * value.hash}.sum
|
90
|
-
end
|
91
|
-
|
92
|
-
if keyword_init
|
93
|
-
def initialize(struct_class_keyword_args = {})
|
94
|
-
@member_values = {}
|
95
|
-
members.each do |attribute|
|
96
|
-
singleton_class.define_method(attribute) do
|
97
|
-
self[attribute]
|
98
|
-
end
|
99
|
-
singleton_class.define_method("#{attribute}=") do |value|
|
100
|
-
self[attribute] = value
|
101
|
-
end
|
102
|
-
end
|
103
|
-
struct_class_keyword_args.each do |attribute, value|
|
104
|
-
self[attribute] = value
|
105
|
-
end
|
106
|
-
end
|
107
|
-
else
|
108
|
-
def initialize(*attribute_values)
|
109
|
-
@member_values = {}
|
110
|
-
members.each do |attribute|
|
111
|
-
singleton_class.define_method(attribute) do
|
112
|
-
self[attribute]
|
113
|
-
end
|
114
|
-
singleton_class.define_method("#{attribute}=") do |value|
|
115
|
-
self[attribute] = value
|
116
|
-
end
|
117
|
-
end
|
118
|
-
attribute_values.each_with_index do |value, i|
|
119
|
-
attribute = members[i]
|
120
|
-
self[attribute] = value
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
ARG_VALIDATION = lambda do |class_name_or_attribute, *attributes|
|
128
|
-
class_name_or_attribute.nil? || attributes.any?(&:nil?)
|
129
|
-
end
|
130
|
-
|
131
|
-
CLASS_NAME_EXTRACTION = lambda do |class_name_or_attribute|
|
132
|
-
if class_name_or_attribute.is_a?(String)
|
133
|
-
raise NameError, "identifier name needs to be constant" unless class_name_or_attribute.match(/^[A-Z]/)
|
134
|
-
class_name_or_attribute
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def new(class_name_or_attribute, *attributes, keyword_init: false)
|
139
|
-
raise 'Arguments cannot be nil' if ARG_VALIDATION[class_name_or_attribute, *attributes]
|
140
|
-
class_name = CLASS_NAME_EXTRACTION[class_name_or_attribute]
|
141
|
-
attributes.unshift(class_name_or_attribute) if class_name.nil?
|
142
|
-
attributes = attributes.map(&:to_sym)
|
143
|
-
struct_class = Class.new(&CLASS_DEFINITION_FOR_ATTRIBUTES[attributes, keyword_init])
|
144
|
-
class_name.nil? ? struct_class : const_set(class_name, struct_class)
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|
148
|
-
end
|