klenod-build 0.0.29 → 0.0.31
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/lib/klenod/build/plugins/data_plugin.rb +62 -9
- data/lib/klenod/build/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 138e1ff7f2bde9f495d98443509718767e179b5e0c7c2a95e92edcd40e3e028a
|
|
4
|
+
data.tar.gz: 927ea94c5136765c21b25e7b95fe9fb59ecbf3e2b9d697a35a0f457297186c51
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9c0d70321556eef5ed84c1c96da47ce50dc3a0ed8c940b268cdfa58736a47380f511104cd8385398dff4b4da4757582f447058c1b888a4b04e4edfc550668157
|
|
7
|
+
data.tar.gz: a0ad06933426e2a03814ed459e52c9d0506825f6ba71e0fc8bf8a6b4e39c681df37f8317d25e812cb84f035b4617bb4dde39001bfc7c67be1c5208050eaef103
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "date"
|
|
3
4
|
require "json"
|
|
4
5
|
require "toml-rb"
|
|
5
6
|
require "yaml"
|
|
@@ -63,9 +64,42 @@ module Klenod
|
|
|
63
64
|
|
|
64
65
|
def module_source(data)
|
|
65
66
|
<<~RUBY
|
|
66
|
-
Default = #{data
|
|
67
|
+
Default = #{ruby_literal(data)}
|
|
67
68
|
RUBY
|
|
68
69
|
end
|
|
70
|
+
|
|
71
|
+
# `inspect` is not Ruby source for every parsed value: dates, times,
|
|
72
|
+
# and non-finite floats need constructor calls instead.
|
|
73
|
+
def ruby_literal(value)
|
|
74
|
+
case value
|
|
75
|
+
when Hash
|
|
76
|
+
entries = value.map { |key, entry| "#{ruby_literal(key)} => #{ruby_literal(entry)}" }
|
|
77
|
+
"{#{entries.join(", ")}}"
|
|
78
|
+
when Array
|
|
79
|
+
"[#{value.map { ruby_literal(it) }.join(", ")}]"
|
|
80
|
+
when Float
|
|
81
|
+
float_literal(value)
|
|
82
|
+
when Time
|
|
83
|
+
zone = value.utc? ? "UTC" : value.utc_offset
|
|
84
|
+
"::Time.at(#{value.to_i}, #{value.nsec}, :nsec, in: #{zone.inspect})"
|
|
85
|
+
when Date
|
|
86
|
+
"::Date.new(#{value.year}, #{value.month}, #{value.day})"
|
|
87
|
+
when nil, true, false, String, Symbol, Integer
|
|
88
|
+
value.inspect
|
|
89
|
+
else
|
|
90
|
+
raise TypeError, "Cannot write #{value.class} as data module source"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def float_literal(value)
|
|
95
|
+
if value.nan?
|
|
96
|
+
"::Float::NAN"
|
|
97
|
+
elsif value.infinite?
|
|
98
|
+
value.positive? ? "::Float::INFINITY" : "-::Float::INFINITY"
|
|
99
|
+
else
|
|
100
|
+
value.inspect
|
|
101
|
+
end
|
|
102
|
+
end
|
|
69
103
|
end
|
|
70
104
|
end
|
|
71
105
|
|
|
@@ -155,8 +189,8 @@ module Klenod
|
|
|
155
189
|
end
|
|
156
190
|
|
|
157
191
|
class ParseError < Klenod::Build::SourceError
|
|
158
|
-
# "
|
|
159
|
-
LOCATION =
|
|
192
|
+
# "Unexpected \"\\n\" at line 2, column 10: expected a value"
|
|
193
|
+
LOCATION = / at line (?<line>\d+), column (?<column>\d+)/
|
|
160
194
|
|
|
161
195
|
def kind
|
|
162
196
|
"TOML parse error"
|
|
@@ -165,16 +199,16 @@ module Klenod
|
|
|
165
199
|
private
|
|
166
200
|
|
|
167
201
|
def location(error)
|
|
202
|
+
# Invalid values such as "Invalid date: 1979-13-01" carry no location.
|
|
168
203
|
found = LOCATION.match(error.message)
|
|
169
204
|
return nil unless found
|
|
170
205
|
|
|
171
|
-
#
|
|
172
|
-
#
|
|
206
|
+
# One-based. The location is rendered as the title and the caret, so
|
|
207
|
+
# drop the copy the parser puts in its message.
|
|
173
208
|
Location.new(
|
|
174
209
|
line: found[:line].to_i,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
detail: "Could not parse TOML"
|
|
210
|
+
column: found[:column].to_i,
|
|
211
|
+
detail: error.message.sub(LOCATION, "")
|
|
178
212
|
)
|
|
179
213
|
end
|
|
180
214
|
end
|
|
@@ -186,7 +220,26 @@ module Klenod
|
|
|
186
220
|
private
|
|
187
221
|
|
|
188
222
|
def parse(code)
|
|
189
|
-
TomlRB.parse(code)
|
|
223
|
+
plain_values(TomlRB.parse(code))
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# toml-rb returns its own Time subclasses for local values. Exports
|
|
227
|
+
# and bundles should not depend on toml-rb, so a local date becomes a
|
|
228
|
+
# Date, as in YAML, and a local datetime or time becomes a UTC Time
|
|
229
|
+
# with the same clock time. A local time falls on 1970-01-01.
|
|
230
|
+
def plain_values(value)
|
|
231
|
+
case value
|
|
232
|
+
when Hash
|
|
233
|
+
value.transform_values { plain_values(it) }
|
|
234
|
+
when Array
|
|
235
|
+
value.map { plain_values(it) }
|
|
236
|
+
when TomlRB::LocalDate
|
|
237
|
+
Date.new(value.year, value.month, value.day)
|
|
238
|
+
when TomlRB::LocalDateTime, TomlRB::LocalTime
|
|
239
|
+
Time.at(value, in: "UTC")
|
|
240
|
+
else
|
|
241
|
+
value
|
|
242
|
+
end
|
|
190
243
|
end
|
|
191
244
|
end
|
|
192
245
|
end
|
data/lib/klenod/build/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: klenod-build
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.31
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrés Alin
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.0.
|
|
18
|
+
version: 0.0.31
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.0.
|
|
25
|
+
version: 0.0.31
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: async
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -217,14 +217,14 @@ dependencies:
|
|
|
217
217
|
requirements:
|
|
218
218
|
- - "~>"
|
|
219
219
|
- !ruby/object:Gem::Version
|
|
220
|
-
version: '
|
|
220
|
+
version: '6.0'
|
|
221
221
|
type: :runtime
|
|
222
222
|
prerelease: false
|
|
223
223
|
version_requirements: !ruby/object:Gem::Requirement
|
|
224
224
|
requirements:
|
|
225
225
|
- - "~>"
|
|
226
226
|
- !ruby/object:Gem::Version
|
|
227
|
-
version: '
|
|
227
|
+
version: '6.0'
|
|
228
228
|
- !ruby/object:Gem::Dependency
|
|
229
229
|
name: tsort
|
|
230
230
|
requirement: !ruby/object:Gem::Requirement
|