blob: e11748ce600ca767f0fd4fd0008dee9e09004ebd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
require 'puppet/network/format_handler'
Puppet::Network::FormatHandler.create(:yaml, :mime => "text/yaml") do
# Yaml doesn't need the class name; it's serialized.
def intern(klass, text)
YAML.load(text)
end
# Yaml doesn't need the class name; it's serialized.
def intern_multiple(klass, text)
YAML.load(text)
end
def render(instance)
instance.to_yaml
end
# Yaml monkey-patches Array, so this works.
def render_multiple(instances)
instances.to_yaml
end
# Everything's supported
def supported?(klass)
true
end
end
Puppet::Network::FormatHandler.create(:marshal, :mime => "text/marshal") do
# Marshal doesn't need the class name; it's serialized.
def intern(klass, text)
Marshal.load(text)
end
# Marshal doesn't need the class name; it's serialized.
def intern_multiple(klass, text)
Marshal.load(text)
end
def render(instance)
Marshal.dump(instance)
end
# Yaml monkey-patches Array, so this works.
def render_multiple(instances)
Marshal.dump(instances)
end
# Everything's supported
def supported?(klass)
true
end
end
Puppet::Network::FormatHandler.create(:s, :mime => "text/plain") do
# For now, use the YAML separator.
SEPARATOR = "\n---\n"
def intern_multiple(klass, text)
text.split(SEPARATOR).collect { |inst| intern(klass, inst) }
end
def render_multiple(instances)
instances.collect { |inst| render(inst) }.join(SEPARATOR)
end
# Everything's supported
def supported?(klass)
true
end
end
|