palletjack 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/palletjack/keytransformer.rb +7 -0
- data/lib/palletjack/pallet.rb +3 -1
- data/lib/palletjack/version.rb +1 -1
- data/lib/palletjack.rb +2 -1
- data/lib/traceable.rb +217 -0
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f14f5c45a068c34bf0fc6444ec9b05ce81f26397
|
4
|
+
data.tar.gz: 3eadcf8f4243fca26d2f7bac66eb0822c8b7543f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9c5a9585753b2bc53a007063ac4e9562419fb44d060220ba5a7e3e557391ad99600e4d0738402c8f3fa32311e6ea60402e29cb7636185ce40ea8bfca7af6940
|
7
|
+
data.tar.gz: 3b7044a659bd1cd171095d9a2faf5041c56c70f0026ec219b7b374bb18dd66c9c42180aacab3c4cd4c69d8065de5837d000c0647bbfc7ee3680d35ee128894f5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'traceable'
|
2
|
+
|
1
3
|
class PalletJack
|
2
4
|
class KeyTransformer
|
3
5
|
class Reader < KeyTransformer
|
@@ -251,6 +253,11 @@ class PalletJack
|
|
251
253
|
if self.respond_to?(transform.to_sym) then
|
252
254
|
if new_value = self.send(transform.to_sym, param, context)
|
253
255
|
then
|
256
|
+
new_value = TraceableString.new(new_value)
|
257
|
+
new_value.file = transform.file
|
258
|
+
new_value.line = transform.line
|
259
|
+
new_value.column = transform.column
|
260
|
+
new_value.byte = transform.byte
|
254
261
|
pallet[key] = new_value
|
255
262
|
break
|
256
263
|
end
|
data/lib/palletjack/pallet.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'palletjack/pallet/identity'
|
2
|
+
require 'traceable'
|
2
3
|
|
3
4
|
class PalletJack < KVDAG
|
4
5
|
# PalletJack managed pallet of key boxes inside a warehouse.
|
@@ -38,7 +39,8 @@ class PalletJack < KVDAG
|
|
38
39
|
filestat = File.lstat(filepath)
|
39
40
|
case
|
40
41
|
when (filestat.file? and file =~ /\.yaml$/)
|
41
|
-
merge!(
|
42
|
+
merge!(TraceableYAML::load_file(filepath,
|
43
|
+
filepath.sub(@identity.warehouse, '')[1..-1]))
|
42
44
|
boxes << file
|
43
45
|
when filestat.symlink?
|
44
46
|
link = File.readlink(filepath)
|
data/lib/palletjack/version.rb
CHANGED
data/lib/palletjack.rb
CHANGED
@@ -4,6 +4,7 @@ require 'kvdag'
|
|
4
4
|
require 'palletjack/version'
|
5
5
|
require 'palletjack/keytransformer'
|
6
6
|
require 'palletjack/pallet'
|
7
|
+
require 'traceable'
|
7
8
|
|
8
9
|
class PalletJack < KVDAG
|
9
10
|
attr_reader :warehouse
|
@@ -23,7 +24,7 @@ class PalletJack < KVDAG
|
|
23
24
|
|
24
25
|
def load(warehouse)
|
25
26
|
@warehouse = File.expand_path(warehouse)
|
26
|
-
key_transforms =
|
27
|
+
key_transforms = TraceableYAML::load_file(File.join(@warehouse, 'transforms.yaml'), 'transforms.yaml')
|
27
28
|
@keytrans_reader = KeyTransformer::Reader.new(key_transforms)
|
28
29
|
@keytrans_writer = KeyTransformer::Writer.new(key_transforms)
|
29
30
|
|
data/lib/traceable.rb
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'psych'
|
2
|
+
|
3
|
+
# Read YAML files and remember where each value came from.
|
4
|
+
#
|
5
|
+
# Objects behave like normal in most respects. Objects that implement
|
6
|
+
# Traceable can be asked for their position by calling file(), line(),
|
7
|
+
# column() and byte().
|
8
|
+
#
|
9
|
+
# If the class attribute TraceableString.debug is set, +inspect+ and
|
10
|
+
# +to_yaml+ output position information for each atom, in the case of
|
11
|
+
# +to_yaml+ separated from its value by the string " =^.^= ".
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
#
|
15
|
+
# yaml = "---
|
16
|
+
# foo:
|
17
|
+
# bar: 1
|
18
|
+
# baz:
|
19
|
+
# - gazonk
|
20
|
+
# - foobar"
|
21
|
+
# handler = PositionHandler.new("<STDIN>")
|
22
|
+
# parser = Psych::Parser.new(handler)
|
23
|
+
# handler.parser = parser
|
24
|
+
# parser.parse(yaml)
|
25
|
+
# visitor = PositionVisitor.new
|
26
|
+
# tree = visitor.accept(handler.root)
|
27
|
+
#
|
28
|
+
# tree[0]['foo']['bar']
|
29
|
+
# => "1"
|
30
|
+
# tree[0]['foo']['bar'].file
|
31
|
+
# => "<STDIN>"
|
32
|
+
# tree[0]['foo']['bar'].line
|
33
|
+
# => 3
|
34
|
+
# tree[0]['foo']['bar'].column
|
35
|
+
# => 2
|
36
|
+
#
|
37
|
+
# puts tree[0].to_yaml
|
38
|
+
# ---
|
39
|
+
# foo:
|
40
|
+
# bar: 1
|
41
|
+
# baz:
|
42
|
+
# - gazonk
|
43
|
+
# - foobar
|
44
|
+
#
|
45
|
+
# TraceableString.debug = true
|
46
|
+
# puts tree[0].to_yaml.gsub(' =^.^= ', ' # ')
|
47
|
+
# ---
|
48
|
+
# foo # <STDIN> (line 1, column 4):
|
49
|
+
# bar # <STDIN> (line 2, column 6): 1 # <STDIN> (line 3, column 2)
|
50
|
+
# baz # <STDIN> (line 3, column 6):
|
51
|
+
# - gazonk # <STDIN> (line 5, column 4)
|
52
|
+
# - foobar # <STDIN> (line 6, column 0)
|
53
|
+
|
54
|
+
# Attributes required to trace the origin of a value.
|
55
|
+
module Traceable
|
56
|
+
attr_accessor :file
|
57
|
+
attr_accessor :byte
|
58
|
+
attr_accessor :line
|
59
|
+
attr_accessor :column
|
60
|
+
end
|
61
|
+
|
62
|
+
# A string that remembers the source of its value, and can output it
|
63
|
+
# again when serialised to YAML.
|
64
|
+
class TraceableString < String
|
65
|
+
include Traceable
|
66
|
+
|
67
|
+
def encode_with(coder)
|
68
|
+
coder.tag = nil
|
69
|
+
coder.scalar = self.to_str
|
70
|
+
if debug?
|
71
|
+
# LibYAML, the C YAML library which underlies Ruby's Psych
|
72
|
+
# library, does not handle comments at all. The parser ignores
|
73
|
+
# them and the emitter cannot write them. Thus, to output the
|
74
|
+
# sourcing information in a manner that is at least semi-sane,
|
75
|
+
# we need to put it in the actual value, behind some sort of
|
76
|
+
# separator.
|
77
|
+
#
|
78
|
+
# The separator needs to be representable in Latin-1, otherwise
|
79
|
+
# LibYAML quotes it. It needs to be non-breaking, otherwise
|
80
|
+
# LibYAML will break here to wrap at 80 characters. It cannot
|
81
|
+
# have any special meaning in YAML (including the quote
|
82
|
+
# character), otherwise LibYAML quotes it. It shouldn't appear
|
83
|
+
# in real data, sine we'll need to substitute all instances of
|
84
|
+
# it.
|
85
|
+
#
|
86
|
+
# Also, I like cats, even ASCII ones.
|
87
|
+
coder.scalar += " =^.^= #{@file} (line #{@line}, column #{@column})"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def inspect
|
92
|
+
if debug?
|
93
|
+
"\"%s\" (%s, line: %i, col: %i, byte: %i)" %
|
94
|
+
[self.to_str, @file, @line, @column, @byte]
|
95
|
+
else
|
96
|
+
super
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.debug=(maybe)
|
101
|
+
@@debug = maybe
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.debug
|
105
|
+
@@debug ||= false
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def debug?
|
111
|
+
self.class.debug
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Make the nodes in Psych's YAML parse tree track their positions.
|
116
|
+
class Psych::Nodes::Node
|
117
|
+
include Traceable
|
118
|
+
end
|
119
|
+
|
120
|
+
# Extend the parser to remember the position of each object.
|
121
|
+
class PositionHandler < Psych::TreeBuilder
|
122
|
+
|
123
|
+
# The handler needs access to the parser in order to call mark
|
124
|
+
attr_accessor :parser
|
125
|
+
|
126
|
+
# +filename+ is the name of the source file the YAML structure will
|
127
|
+
# be parsed from. It is only copied into parsed objects, not
|
128
|
+
# interpreted.
|
129
|
+
def initialize(filename)
|
130
|
+
super()
|
131
|
+
@file = filename
|
132
|
+
end
|
133
|
+
|
134
|
+
# Copy a parser position from a +Psych::Parser::Mark+ to a parse
|
135
|
+
# tree node.
|
136
|
+
def record_position(node, mark)
|
137
|
+
node.extend Traceable
|
138
|
+
node.file = @file
|
139
|
+
node.byte = mark.index
|
140
|
+
node.line = mark.line
|
141
|
+
node.column = mark.column
|
142
|
+
node
|
143
|
+
end
|
144
|
+
|
145
|
+
def start_mapping(anchor, tag, implicit, style)
|
146
|
+
record_position(super, parser.mark)
|
147
|
+
end
|
148
|
+
|
149
|
+
def start_sequence(anchor, tag, implicit, style)
|
150
|
+
record_position(super, parser.mark)
|
151
|
+
end
|
152
|
+
|
153
|
+
def scalar(value, anchor, tag, plain, quoted, style)
|
154
|
+
record_position(super, parser.mark)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Extend the Ruby structure builder to remeber each object's position.
|
159
|
+
class PositionVisitor < Psych::Visitors::ToRuby
|
160
|
+
|
161
|
+
# Copy a parser position from a parse tree node to a primitive
|
162
|
+
# object.
|
163
|
+
def record_position(s, o)
|
164
|
+
s.extend Traceable
|
165
|
+
s.file = o.file
|
166
|
+
s.byte = o.byte
|
167
|
+
s.line = o.line
|
168
|
+
s.column = o.column
|
169
|
+
s
|
170
|
+
end
|
171
|
+
|
172
|
+
def visit_Psych_Nodes_Scalar o
|
173
|
+
# Primitive YAML values can be either strings or integers. Ruby
|
174
|
+
# integers cannot be extended, so convert everything to strings
|
175
|
+
# before inserting position information.
|
176
|
+
record_position(TraceableString.new(String(super)), o)
|
177
|
+
end
|
178
|
+
|
179
|
+
def visit_Psych_Nodes_Sequence o
|
180
|
+
record_position(super, o)
|
181
|
+
end
|
182
|
+
|
183
|
+
def visit_Psych_Nodes_Mapping o
|
184
|
+
record_position(super, o)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
module TraceableYAML
|
189
|
+
|
190
|
+
# Parse a YAML document from the string +doc+, tagging each value
|
191
|
+
# with the source +tag+, and return a Ruby object tree representing
|
192
|
+
# the result.
|
193
|
+
def self.parse(doc, tag)
|
194
|
+
handler = PositionHandler.new(tag)
|
195
|
+
parser = Psych::Parser.new(handler)
|
196
|
+
handler.parser = parser
|
197
|
+
parser.parse doc
|
198
|
+
if PositionVisitor.respond_to?(:create)
|
199
|
+
# Ruby 2.1 and above
|
200
|
+
visitor = PositionVisitor.create
|
201
|
+
else
|
202
|
+
# Ruby 2.0
|
203
|
+
visitor = PositionVisitor.new
|
204
|
+
end
|
205
|
+
tree = visitor.accept(handler.root)
|
206
|
+
tree[0]
|
207
|
+
end
|
208
|
+
|
209
|
+
# Load a YAML document from the file +path+, tagging each value with
|
210
|
+
# the source +tag+, and return a Ruby object tree representing the
|
211
|
+
# result.
|
212
|
+
def self.load_file(path, tag)
|
213
|
+
File.open(path) do |f|
|
214
|
+
parse(f.read, tag)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: palletjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calle Englund
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
f8wtQllq82VF0AXUYeLtTh1f+DW3WW5BO1e2OCu5eOV7dbyaVPaNK/+rHjCN8kM/
|
32
32
|
DGZSwUoNADmVkQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2016-11-
|
34
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- lib/palletjack/pallet/identity.rb
|
166
166
|
- lib/palletjack/tool.rb
|
167
167
|
- lib/palletjack/version.rb
|
168
|
+
- lib/traceable.rb
|
168
169
|
- palletjack.gemspec
|
169
170
|
homepage: https://github.com/saab-simc-admin/palletjack
|
170
171
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|