palletjack 0.1.3 → 0.2.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.tar.gz.sig +0 -0
- data/README.md +8 -0
- data/lib/palletjack.rb +21 -3
- data/lib/palletjack/pallet.rb +61 -36
- data/lib/palletjack/pallet/identity.rb +65 -0
- data/lib/palletjack/tool.rb +3 -29
- data/lib/palletjack/version.rb +1 -1
- data/palletjack.gemspec +2 -0
- metadata +56 -4
- 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: ad0c8785d6c2e0df5f352e67ea82abad9ee6803b
|
4
|
+
data.tar.gz: ce7296d715491c9a78e139b7578552b505e21c1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca68935c9d97734d28b139629873774eeaca5d8f06bb468047c0a16a09c5c51f4983b04cfbabce97517c9fb259739830782acea3e93b6334cc4400392b19274f
|
7
|
+
data.tar.gz: 6963849234c18071bdece0e5f5fd37fcf9edf8984775f69ec71084e994bbdf297959d2a1511e6c12dcc3e80a4a84c06c77efc4b5a52c3c2519d84d5fed5945ab
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/README.md
CHANGED
@@ -241,3 +241,11 @@ We are happy to accept contributions in the form of issues and pull requests on
|
|
241
241
|
- If your code needs larger chunks of static data to work, please provide it in a separate directory under `examples/`. See e.g. [the `examples/pxelinux/` tree](https://github.com/saab-simc-admin/palletjack/tree/master/examples/pxelinux), which contains files required to make sense of the output from `palletjack2pxelinux`.
|
242
242
|
|
243
243
|
- Write your commit messages in the usual Git style: a short summary in the first line, then paragraphs of explanatory text, line wrapped.
|
244
|
+
|
245
|
+
- Test your code.
|
246
|
+
|
247
|
+
- Tests shall be written in [RSpec](http://rspec.info/).
|
248
|
+
|
249
|
+
- Library code shall have unit tests.
|
250
|
+
|
251
|
+
- Tools shall have integration and end-to-end tests.
|
data/lib/palletjack.rb
CHANGED
@@ -6,10 +6,12 @@ require 'palletjack/keytransformer'
|
|
6
6
|
require 'palletjack/pallet'
|
7
7
|
|
8
8
|
class PalletJack < KVDAG
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :warehouse
|
10
10
|
attr_reader :keytrans_reader
|
11
11
|
attr_reader :keytrans_writer
|
12
12
|
|
13
|
+
# Create and load a PalletJack warehouse, and all its pallets
|
14
|
+
|
13
15
|
def self.load(warehouse)
|
14
16
|
new.load(warehouse)
|
15
17
|
end
|
@@ -19,6 +21,8 @@ class PalletJack < KVDAG
|
|
19
21
|
@pallets = Hash.new
|
20
22
|
end
|
21
23
|
|
24
|
+
# Load a PalletJack warehouse, and all its pallets
|
25
|
+
|
22
26
|
def load(warehouse)
|
23
27
|
@warehouse = File.expand_path(warehouse)
|
24
28
|
key_transforms = YAML::load_file(File.join(@warehouse, "transforms.yaml"))
|
@@ -32,12 +36,26 @@ class PalletJack < KVDAG
|
|
32
36
|
Dir.foreach(kindpath) do |pallet|
|
33
37
|
palletpath = File.join(kindpath, pallet)
|
34
38
|
next unless File.directory?(palletpath) and pallet !~ /^\.{1,2}$/
|
35
|
-
|
39
|
+
pallet(kind, pallet)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
self
|
39
43
|
end
|
40
44
|
|
45
|
+
# Return a named pallet from the warehouse
|
46
|
+
#
|
47
|
+
# If the pallet is not yet loaded, it will be.
|
48
|
+
#
|
49
|
+
# Raises RuntimeError if the warehouse is not loaded.
|
50
|
+
# Raises Errno::ENOENT if the pallet can't be loaded.
|
51
|
+
|
52
|
+
def pallet(kind, name)
|
53
|
+
raise "warehouse is not loaded" unless @warehouse
|
54
|
+
|
55
|
+
identity = Pallet::Identity.new(self, File.join(kind, name))
|
56
|
+
@pallets[identity.path] ||= Pallet.load(self, identity)
|
57
|
+
end
|
58
|
+
|
41
59
|
# Search for pallets in a PalletJack warehouse
|
42
60
|
#
|
43
61
|
# The search is filtered by KVDAG::Vertex#match? expressions.
|
@@ -64,7 +82,7 @@ class PalletJack < KVDAG
|
|
64
82
|
result = self[filter]
|
65
83
|
|
66
84
|
if result.length != 1
|
67
|
-
raise KeyError.new("#{
|
85
|
+
raise KeyError.new("#{filter} matched #{result.length} pallets")
|
68
86
|
end
|
69
87
|
result.first
|
70
88
|
end
|
data/lib/palletjack/pallet.rb
CHANGED
@@ -1,52 +1,39 @@
|
|
1
|
-
|
1
|
+
require 'palletjack/pallet/identity'
|
2
|
+
|
3
|
+
class PalletJack < KVDAG
|
2
4
|
# PalletJack managed pallet of key boxes inside a warehouse.
|
3
5
|
class Pallet < KVDAG::Vertex
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# N.B: A pallet should never be created manually; use
|
9
|
-
# +PalletJack::new+ to initialize a complete warehouse.
|
7
|
+
# N.B: A pallet should never be loaded manually; use
|
8
|
+
# +PalletJack.load+ to initialize a complete warehouse.
|
10
9
|
#
|
11
10
|
# [+jack+] PalletJack that will manage this pallet.
|
12
|
-
# [+
|
11
|
+
# [+identity+] Identity of the pallet to be loaded.
|
13
12
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# Use relative path inside of warehouse as kind/name for this
|
17
|
-
# pallet, and make a singletonish object for that key.
|
18
|
-
|
19
|
-
def Pallet.new(jack, path) #:doc:
|
20
|
-
ppath, name = File.split(path)
|
21
|
-
_, kind = File.split(ppath)
|
13
|
+
# Creates and loads a new PalletJack warehouse pallet.
|
22
14
|
|
23
|
-
|
24
|
-
jack.
|
15
|
+
def self.load(jack, identity)
|
16
|
+
new(jack).load(identity)
|
25
17
|
end
|
26
18
|
|
27
|
-
# N.B: A pallet should never be
|
28
|
-
# +PalletJack::
|
19
|
+
# N.B: A pallet should never be loaded manually; use
|
20
|
+
# +PalletJack::load+ to initialize a complete warehouse.
|
29
21
|
#
|
30
|
-
# [+
|
31
|
-
# [+path+] Filesystem path to pallet data.
|
22
|
+
# [+identity+] Identity of the pallet to be loaded.
|
32
23
|
#
|
33
24
|
# Loads and merges all YAML files in +path+ into this Vertex.
|
34
25
|
#
|
35
26
|
# Follows all symlinks in +path+ and creates edges towards
|
36
27
|
# the pallet located in the symlink target.
|
37
28
|
|
38
|
-
|
39
|
-
|
40
|
-
@jack = jack
|
41
|
-
@path = path
|
42
|
-
ppath, @name = File.split(path)
|
43
|
-
_, @kind = File.split(ppath)
|
29
|
+
def load(identity)
|
30
|
+
@identity = identity
|
44
31
|
boxes = Array.new
|
45
|
-
|
46
|
-
super(jack, pallet:{@kind => @name})
|
32
|
+
path = @identity.path
|
47
33
|
|
48
34
|
Dir.foreach(path) do |file|
|
49
|
-
next if file[0] == '.'
|
35
|
+
next if file[0] == '.' # skip dot.files
|
36
|
+
|
50
37
|
filepath = File.join(path, file)
|
51
38
|
filestat = File.lstat(filepath)
|
52
39
|
case
|
@@ -55,15 +42,19 @@ class PalletJack
|
|
55
42
|
boxes << file
|
56
43
|
when filestat.symlink?
|
57
44
|
link = File.readlink(filepath)
|
58
|
-
|
45
|
+
link_id = Identity.new(jack, File.expand_path(link, path))
|
59
46
|
|
60
|
-
pallet =
|
61
|
-
edge(pallet, pallet:{references:{file =>
|
47
|
+
pallet = jack.pallet(link_id.kind, link_id.full_name)
|
48
|
+
edge(pallet, pallet:{references:{file => link_id.full_name}})
|
49
|
+
when filestat.directory?
|
50
|
+
child = jack.pallet(kind, File.join(name, file))
|
51
|
+
child.edge(self, pallet:{references:{_parent: name}})
|
62
52
|
end
|
63
53
|
end
|
64
|
-
merge!(pallet:{boxes: boxes})
|
65
|
-
|
66
|
-
|
54
|
+
merge!(pallet:{kind => name, boxes: boxes})
|
55
|
+
jack.keytrans_writer.transform!(self)
|
56
|
+
|
57
|
+
self
|
67
58
|
end
|
68
59
|
|
69
60
|
def inspect
|
@@ -73,8 +64,42 @@ class PalletJack
|
|
73
64
|
# Override standard to_yaml serialization, because pallet objects
|
74
65
|
# are ephemeral by nature. The natural serialization is that of
|
75
66
|
# their to_hash analogue.
|
67
|
+
|
76
68
|
def to_yaml
|
77
69
|
to_hash.to_yaml
|
78
70
|
end
|
71
|
+
|
72
|
+
# The kind of this pallet
|
73
|
+
|
74
|
+
def kind
|
75
|
+
@identity.kind
|
76
|
+
end
|
77
|
+
|
78
|
+
# The leaf name of this pallet in its hierarchy
|
79
|
+
|
80
|
+
def leaf_name
|
81
|
+
@identity.leaf_name
|
82
|
+
end
|
83
|
+
|
84
|
+
# Compatibility alias name is the leaf name
|
85
|
+
|
86
|
+
alias name leaf_name
|
87
|
+
|
88
|
+
# The full hierarchical name of this pallet
|
89
|
+
|
90
|
+
def full_name
|
91
|
+
@identity.full_name
|
92
|
+
end
|
93
|
+
|
94
|
+
# The full name of the hierarchical parent for this pallet,
|
95
|
+
# or nil if there is no parent.
|
96
|
+
|
97
|
+
def parent_name
|
98
|
+
@identity.parent_name
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
alias :jack :dag
|
79
104
|
end
|
80
105
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class PalletJack < KVDAG
|
2
|
+
class Pallet < KVDAG::Vertex
|
3
|
+
|
4
|
+
# Represents the identity aspects of a warehouse pallet
|
5
|
+
|
6
|
+
class Identity
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
# Full expanded path to this pallet
|
10
|
+
attr_reader :path
|
11
|
+
|
12
|
+
# Base path of the warehouse for this pallet
|
13
|
+
attr_reader :warehouse
|
14
|
+
|
15
|
+
# The kind of this pallet
|
16
|
+
attr_reader :kind
|
17
|
+
|
18
|
+
# The full name of the hierarchical parent for this pallet,
|
19
|
+
# or nil if there is no parent.
|
20
|
+
attr_reader :parent_name
|
21
|
+
|
22
|
+
# The full hierarchical name for this pallet
|
23
|
+
attr_reader :full_name
|
24
|
+
|
25
|
+
# The leaf name for this pallet in its hierarchy
|
26
|
+
attr_reader :leaf_name
|
27
|
+
|
28
|
+
# Initialize identity aspects for a Pallet from components of its
|
29
|
+
# +path+ within the +jack.warehouse+
|
30
|
+
|
31
|
+
def initialize(jack, path)
|
32
|
+
@warehouse = jack.warehouse
|
33
|
+
@path = path = File.expand_path(path, @warehouse)
|
34
|
+
|
35
|
+
path_components = []
|
36
|
+
while path > @warehouse do
|
37
|
+
path, part = File.split(path)
|
38
|
+
path_components = [part, *path_components]
|
39
|
+
end
|
40
|
+
|
41
|
+
@kind, *path_components = path_components
|
42
|
+
@full_name = File.join(*path_components)
|
43
|
+
@leaf_name = path_components.last
|
44
|
+
*path_components, _ = path_components
|
45
|
+
@parent_name = File.join(*path_components) unless path_components.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
# Comparability uses the full path of the pallet
|
49
|
+
|
50
|
+
def <=>(other)
|
51
|
+
path <=> other.path
|
52
|
+
end
|
53
|
+
|
54
|
+
# Hashing uses the full path of the pallet for uniqueness
|
55
|
+
|
56
|
+
def hash
|
57
|
+
path.hash
|
58
|
+
end
|
59
|
+
|
60
|
+
# eql? must be overridden for Hash comparisons to work as expected
|
61
|
+
|
62
|
+
alias eql? ==
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/palletjack/tool.rb
CHANGED
@@ -49,8 +49,6 @@ class PalletJack
|
|
49
49
|
class Tool
|
50
50
|
include Singleton
|
51
51
|
|
52
|
-
# v0.1.1 API:
|
53
|
-
#
|
54
52
|
# :call-seq:
|
55
53
|
# run
|
56
54
|
#
|
@@ -67,34 +65,10 @@ class PalletJack
|
|
67
65
|
# MyTool.run
|
68
66
|
# end
|
69
67
|
|
70
|
-
# v0.1.0 API, retained until all tools have been updated to
|
71
|
-
# v0.1.1:
|
72
|
-
#
|
73
|
-
# :call-seq:
|
74
|
-
# run &block
|
75
|
-
#
|
76
|
-
# Run the +block+ given in the context of the tool singleton instance
|
77
|
-
# as convenience for simple tools.
|
78
|
-
#
|
79
|
-
# More complex tools probably want to override parse_options to
|
80
|
-
# add option parsing, and split functionality into multiple methods.
|
81
|
-
#
|
82
|
-
# Example:
|
83
|
-
#
|
84
|
-
# MyTool.run { jack.each(kind:'system') {|sys| puts sys.to_yaml } }
|
85
|
-
|
86
68
|
def self.run(&block)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
instance.setup
|
91
|
-
instance.instance_eval(&block)
|
92
|
-
else
|
93
|
-
# v0.1.1 API
|
94
|
-
instance.setup
|
95
|
-
instance.process
|
96
|
-
instance.output
|
97
|
-
end
|
69
|
+
instance.setup
|
70
|
+
instance.process
|
71
|
+
instance.output
|
98
72
|
end
|
99
73
|
|
100
74
|
# Predicate for detecting if we are being invoked as a standalone
|
data/lib/palletjack/version.rb
CHANGED
data/palletjack.gemspec
CHANGED
@@ -31,6 +31,8 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 1.13"
|
32
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "rspec_structure_matcher", "~> 0.0.6"
|
35
|
+
spec.add_development_dependency "rspec-collection_matchers", "~> 1.1.2"
|
34
36
|
|
35
37
|
spec.has_rdoc = true
|
36
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: palletjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calle Englund
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRYwFAYDVQQDDA1jYWxs
|
14
|
+
ZS5lbmdsdW5kMRkwFwYKCZImiZPyLGQ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XaRd5
|
29
|
+
fiNj/nBTb0YTQA0E4pZ0Aud80qZ2WLdc6FfzHUEMW91BL3bhLeDL40noHK5Lvk52
|
30
|
+
phzVHIrDjCowUMTnGiPZCXEo4KZW76KwYYV6oQ6LzcrYBw5mJ4XpdgQKZgnTnRBP
|
31
|
+
f8wtQllq82VF0AXUYeLtTh1f+DW3WW5BO1e2OCu5eOV7dbyaVPaNK/+rHjCN8kM/
|
32
|
+
DGZSwUoNADmVkQ==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
35
|
dependencies:
|
13
36
|
- !ruby/object:Gem::Dependency
|
14
37
|
name: activesupport
|
@@ -94,6 +117,34 @@ dependencies:
|
|
94
117
|
- - ~>
|
95
118
|
- !ruby/object:Gem::Version
|
96
119
|
version: '3.0'
|
120
|
+
- !ruby/object:Gem::Dependency
|
121
|
+
name: rspec_structure_matcher
|
122
|
+
requirement: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 0.0.6
|
127
|
+
type: :development
|
128
|
+
prerelease: false
|
129
|
+
version_requirements: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 0.0.6
|
134
|
+
- !ruby/object:Gem::Dependency
|
135
|
+
name: rspec-collection_matchers
|
136
|
+
requirement: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ~>
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 1.1.2
|
141
|
+
type: :development
|
142
|
+
prerelease: false
|
143
|
+
version_requirements: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ~>
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: 1.1.2
|
97
148
|
description: Lightweight Configuration Management Database
|
98
149
|
email:
|
99
150
|
- calle.englund@saabgroup.com
|
@@ -111,6 +162,7 @@ files:
|
|
111
162
|
- lib/palletjack.rb
|
112
163
|
- lib/palletjack/keytransformer.rb
|
113
164
|
- lib/palletjack/pallet.rb
|
165
|
+
- lib/palletjack/pallet/identity.rb
|
114
166
|
- lib/palletjack/tool.rb
|
115
167
|
- lib/palletjack/version.rb
|
116
168
|
- palletjack.gemspec
|
@@ -134,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
186
|
version: '0'
|
135
187
|
requirements: []
|
136
188
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.0.14
|
138
190
|
signing_key:
|
139
191
|
specification_version: 4
|
140
192
|
summary: Lightweight Configuration Management Database
|
metadata.gz.sig
ADDED
Binary file
|