huck 0.2.2 → 0.2.3
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/huck/generator.rb +0 -27
- data/lib/huck/util.rb +25 -0
- data/lib/huck/version.rb +1 -1
- data/lib/huck.rb +6 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef804b8c7db217ba15215e4130274d571f28540e
|
4
|
+
data.tar.gz: 5725488dde39cbaa15655a171a146d3490131fd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d732a5dc916c896c9fc806fbcc1d7104cea7a716fa53995f137d24f45c020b81f49ec57ab84cfa8afc90dd35ea3bf3a63a335b6de03f202bcbb195134b046b9c
|
7
|
+
data.tar.gz: fc996cf475ca5389e0a8d7da611f239a3e3caf8197ece289a9cd511acc8a5a099fd2044d5c8c0ed682e2372a6141af8f59bce5e81eb347416a004956759f2b74
|
data/lib/huck/generator.rb
CHANGED
@@ -4,33 +4,6 @@ module Huck
|
|
4
4
|
|
5
5
|
attr_accessor :config
|
6
6
|
|
7
|
-
# This method will call the generation method, and return the data in the
|
8
|
-
# desired format.
|
9
|
-
#
|
10
|
-
# == Parameters:
|
11
|
-
# format::
|
12
|
-
# The serialization format (json or yaml)
|
13
|
-
#
|
14
|
-
# == Returns:
|
15
|
-
# A string of serialized text
|
16
|
-
#
|
17
|
-
def dump kwargs = {}
|
18
|
-
format = Huck::getarg kwargs, :format, 'json'
|
19
|
-
data = generate
|
20
|
-
if !data.is_a? Hash
|
21
|
-
raise RuntimeError, 'cannot handle non-hash data'
|
22
|
-
end
|
23
|
-
|
24
|
-
case format
|
25
|
-
when 'json'
|
26
|
-
return JSON.dump data
|
27
|
-
when 'yaml'
|
28
|
-
return YAML.dump data
|
29
|
-
else
|
30
|
-
raise RuntimeError, "unknown format '#{format}'"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
7
|
# Given a generator's name (or no name), return a new generator instance
|
35
8
|
#
|
36
9
|
# == Parameters:
|
data/lib/huck/util.rb
CHANGED
@@ -64,4 +64,29 @@ module Huck
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
# Serialize a hash to a desired format.
|
68
|
+
#
|
69
|
+
# == Parameters:
|
70
|
+
# format::
|
71
|
+
# The serialization format (json or yaml)
|
72
|
+
#
|
73
|
+
# == Returns:
|
74
|
+
# A string of serialized text
|
75
|
+
#
|
76
|
+
def self.serialize_hash data, kwargs = {}
|
77
|
+
format = Huck::getarg kwargs, :format, 'json'
|
78
|
+
if !data.is_a? Hash
|
79
|
+
raise RuntimeError, 'cannot serialize non-hash data'
|
80
|
+
end
|
81
|
+
|
82
|
+
case format
|
83
|
+
when 'json'
|
84
|
+
return JSON.dump data
|
85
|
+
when 'yaml'
|
86
|
+
return YAML.dump data
|
87
|
+
else
|
88
|
+
raise RuntimeError, "unknown format '#{format}'"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
67
92
|
end
|
data/lib/huck/version.rb
CHANGED
data/lib/huck.rb
CHANGED
@@ -19,7 +19,10 @@ require 'huck/handlers/exec'
|
|
19
19
|
|
20
20
|
module Huck
|
21
21
|
|
22
|
-
# Main method to run Huck and dump info
|
22
|
+
# Main method to run Huck and dump info. If a block is given, the block will
|
23
|
+
# be used as the generator code. Generator code must return a hash, anything
|
24
|
+
# else will cause a RuntimeException. If no block is passed, then the
|
25
|
+
# configured generator will be invoked instead.
|
23
26
|
#
|
24
27
|
# == Parameters:
|
25
28
|
# config::
|
@@ -50,7 +53,8 @@ module Huck
|
|
50
53
|
send_name = send_arg if !send_arg.nil?
|
51
54
|
s = Sender::factory :name => send_name, :config => config
|
52
55
|
|
53
|
-
|
56
|
+
data = block_given? ? yield : g.generate
|
57
|
+
s.send Huck::serialize_hash data
|
54
58
|
end
|
55
59
|
|
56
60
|
# Main method to receive messages from a Huck client. If a block is given, the
|