yamlstar 0.0.1 → 0.1.11
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/Gemfile +4 -0
- data/ReadMe.md +20 -0
- data/lib/yamlstar/version.rb +6 -0
- data/lib/yamlstar.rb +147 -0
- data/yamlstar.gemspec +24 -0
- metadata +18 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4db632f1e7bd5bdf7d4390124bbf947d4839af78f470adbdd5fad12917a0af14
|
|
4
|
+
data.tar.gz: 92a44b0dec4edcf4ad66704e70b17ceecdf51a2fcc9d42d2aee53f13690656fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54559ceab26b7005fbecedbacb21f64d56274fb8626e17b297352b57a2c05775d0689fe51afa803653c78761ddb25ec3f856e2a469f595f18bcc442f152d3786
|
|
7
|
+
data.tar.gz: 0e27d50968840e194f774846c064c0e810767155d8b24434c9f9b7dfac3d05c02c8bfa218e4ad8c913c7091eaeb10c4eb08988d852350fa52aab35b322cff821
|
data/Gemfile
ADDED
data/ReadMe.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# YAMLStar Ruby Binding
|
|
2
|
+
|
|
3
|
+
Ruby binding for the YAMLStar shared library.
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
require "yamlstar"
|
|
7
|
+
|
|
8
|
+
ys = YAMLStar.new
|
|
9
|
+
data = ys.load("key: value")
|
|
10
|
+
text = ys.dump({"foo" => [["bar"]]})
|
|
11
|
+
ys.close
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Install the matching `libyamlstar` release before using this gem:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
curl -sSL https://yamlstar.org/install | LIB=1 bash
|
|
18
|
+
gem install yamlstar
|
|
19
|
+
```
|
|
20
|
+
|
data/lib/yamlstar.rb
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fiddle"
|
|
4
|
+
require "fiddle/import"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
require_relative "yamlstar/version"
|
|
8
|
+
|
|
9
|
+
class YAMLStar
|
|
10
|
+
Error = Class.new(StandardError)
|
|
11
|
+
|
|
12
|
+
LIBYAMLSTAR_VERSION = VERSION
|
|
13
|
+
|
|
14
|
+
module LibYAMLStar
|
|
15
|
+
extend Fiddle::Importer
|
|
16
|
+
|
|
17
|
+
def self.extension
|
|
18
|
+
case RUBY_PLATFORM
|
|
19
|
+
when /darwin/
|
|
20
|
+
"dylib"
|
|
21
|
+
when /linux/
|
|
22
|
+
"so"
|
|
23
|
+
when /mswin|mingw|cygwin/
|
|
24
|
+
"dll"
|
|
25
|
+
else
|
|
26
|
+
raise Error, "Unsupported platform #{RUBY_PLATFORM} for yamlstar."
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.library_names
|
|
31
|
+
base = "libyamlstar.#{extension}"
|
|
32
|
+
[base, "#{base}.#{LIBYAMLSTAR_VERSION}"]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.library_paths
|
|
36
|
+
paths = []
|
|
37
|
+
dev_path = File.expand_path("../../libyamlstar/lib", __dir__)
|
|
38
|
+
paths << dev_path
|
|
39
|
+
env_var = extension == "dll" ? "PATH" : "LD_LIBRARY_PATH"
|
|
40
|
+
paths.concat(ENV.fetch(env_var, "").split(File::PATH_SEPARATOR))
|
|
41
|
+
paths << "/usr/local/lib" unless extension == "dll"
|
|
42
|
+
paths << File.join(ENV.fetch("HOME", ""), ".local", "lib")
|
|
43
|
+
paths.reject(&:empty?)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.find_library
|
|
47
|
+
library_paths.each do |dir|
|
|
48
|
+
library_names.each do |name|
|
|
49
|
+
path = File.join(dir, name)
|
|
50
|
+
return path if File.exist?(path)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
raise Error, <<~ERROR
|
|
55
|
+
Shared library file `libyamlstar.#{extension}` not found
|
|
56
|
+
Search paths: #{library_paths.join(File::PATH_SEPARATOR)}
|
|
57
|
+
Try: curl -sSL https://yamlstar.org/install | LIB=1 bash
|
|
58
|
+
ERROR
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
dlload find_library
|
|
62
|
+
|
|
63
|
+
extern "int graal_create_isolate(void* params, void** isolate, void** thread)"
|
|
64
|
+
extern "int graal_tear_down_isolate(void* thread)"
|
|
65
|
+
extern "char* yamlstar_load(void* thread, char* yaml)"
|
|
66
|
+
extern "char* yamlstar_load_all(void* thread, char* yaml)"
|
|
67
|
+
extern "char* yamlstar_dump(void* thread, char* json)"
|
|
68
|
+
extern "char* yamlstar_dump_all(void* thread, char* json)"
|
|
69
|
+
extern "char* yamlstar_version(void* thread)"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.load(yaml)
|
|
73
|
+
new.load(yaml)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def self.load_all(yaml)
|
|
77
|
+
new.load_all(yaml)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def self.dump(value)
|
|
81
|
+
new.dump(value)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.dump_all(values)
|
|
85
|
+
new.dump_all(values)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
attr_reader :error
|
|
89
|
+
|
|
90
|
+
def initialize
|
|
91
|
+
@isolate = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
|
92
|
+
thread = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
|
93
|
+
rc = LibYAMLStar.graal_create_isolate(nil, @isolate.ref, thread.ref)
|
|
94
|
+
raise Error, "Failed to create GraalVM isolate" unless rc.zero?
|
|
95
|
+
|
|
96
|
+
@thread = thread
|
|
97
|
+
@closed = false
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def load(yaml)
|
|
101
|
+
call_yaml(:yamlstar_load, yaml)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def load_all(yaml)
|
|
105
|
+
call_yaml(:yamlstar_load_all, yaml)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def dump(value)
|
|
109
|
+
call_json(:yamlstar_dump, value)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def dump_all(values)
|
|
113
|
+
call_json(:yamlstar_dump_all, values)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def version
|
|
117
|
+
LibYAMLStar.yamlstar_version(@thread).to_s
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def close
|
|
121
|
+
return if @closed
|
|
122
|
+
|
|
123
|
+
rc = LibYAMLStar.graal_tear_down_isolate(@thread)
|
|
124
|
+
raise Error, "Failed to tear down GraalVM isolate" unless rc.zero?
|
|
125
|
+
|
|
126
|
+
@closed = true
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
private
|
|
130
|
+
|
|
131
|
+
def call_yaml(function, input)
|
|
132
|
+
handle_response(LibYAMLStar.public_send(function, @thread, input.to_s).to_s)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def call_json(function, value)
|
|
136
|
+
handle_response(LibYAMLStar.public_send(function, @thread, JSON.generate(value)).to_s)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def handle_response(json)
|
|
140
|
+
resp = JSON.parse(json)
|
|
141
|
+
@error = resp["error"]
|
|
142
|
+
raise Error, "libyamlstar: #{@error["cause"]}" if @error
|
|
143
|
+
raise Error, "Unexpected response from 'libyamlstar'" unless resp.key?("data")
|
|
144
|
+
|
|
145
|
+
resp["data"]
|
|
146
|
+
end
|
|
147
|
+
end
|
data/yamlstar.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/yamlstar/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "yamlstar"
|
|
7
|
+
spec.version = YAMLStar::VERSION
|
|
8
|
+
spec.authors = ["Ingy dot Net"]
|
|
9
|
+
spec.email = ["ingy@ingy.net"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Ruby binding for YAMLStar"
|
|
12
|
+
spec.description = "Ruby binding for YAMLStar, a YAML 1.2 load/dump framework."
|
|
13
|
+
spec.homepage = "https://yamlstar.org"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/yaml/yamlstar"
|
|
19
|
+
|
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
21
|
+
Dir["lib/**/*.rb", "ReadMe.md", "Gemfile", "yamlstar.gemspec"]
|
|
22
|
+
end
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
end
|
metadata
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yamlstar
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.1.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Ingy
|
|
8
|
-
|
|
9
|
-
bindir: exe
|
|
7
|
+
- Ingy dot Net
|
|
8
|
+
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
|
-
description:
|
|
12
|
+
description: Ruby binding for YAMLStar, a YAML 1.2 load/dump framework.
|
|
14
13
|
email:
|
|
15
14
|
- ingy@ingy.net
|
|
16
15
|
executables: []
|
|
17
16
|
extensions: []
|
|
18
17
|
extra_rdoc_files: []
|
|
19
|
-
files:
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
files:
|
|
19
|
+
- Gemfile
|
|
20
|
+
- ReadMe.md
|
|
21
|
+
- lib/yamlstar.rb
|
|
22
|
+
- lib/yamlstar/version.rb
|
|
23
|
+
- yamlstar.gemspec
|
|
24
|
+
homepage: https://yamlstar.org
|
|
25
|
+
licenses:
|
|
26
|
+
- MIT
|
|
22
27
|
metadata:
|
|
23
|
-
homepage_uri: https://
|
|
28
|
+
homepage_uri: https://yamlstar.org
|
|
24
29
|
source_code_uri: https://github.com/yaml/yamlstar
|
|
25
|
-
changelog_uri: https://github.com/yaml/yamlstar/tree/main/ruby/ChangeLog.md
|
|
26
|
-
post_install_message:
|
|
27
30
|
rdoc_options: []
|
|
28
31
|
require_paths:
|
|
29
32
|
- lib
|
|
@@ -31,15 +34,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
31
34
|
requirements:
|
|
32
35
|
- - ">="
|
|
33
36
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: 2.
|
|
37
|
+
version: 2.7.0
|
|
35
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
39
|
requirements:
|
|
37
40
|
- - ">="
|
|
38
41
|
- !ruby/object:Gem::Version
|
|
39
42
|
version: '0'
|
|
40
43
|
requirements: []
|
|
41
|
-
rubygems_version:
|
|
42
|
-
signing_key:
|
|
44
|
+
rubygems_version: 4.0.10
|
|
43
45
|
specification_version: 4
|
|
44
|
-
summary:
|
|
46
|
+
summary: Ruby binding for YAMLStar
|
|
45
47
|
test_files: []
|