puppet-function-updater 0.0.1 → 0.0.2
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/bin/puppet_function_updater +1 -0
- data/lib/pfu.rb +1 -1
- data/lib/pfu/generator.rb +3 -1
- data/lib/pfu/parser.rb +25 -2
- data/lib/pfu/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4e20e5f6989948ee8a47c6be69b5c381a0817ae8b26ccf7daac5d3e437de74b
|
4
|
+
data.tar.gz: cd83a4c1687b449691de92a67de33a9a80fd11f31411232ff41472b4735cd3b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d308a64a254c50864dd8b0840f42cb2feee2da57c452696b0e3069ddb602bbb35119ee3708a71801e057c51c5b3aebaaff52ebf113e0a8380f714b1e5f1f1d66
|
7
|
+
data.tar.gz: c08d5bef117c504be32a60e19b42e860d63f9e390c0708d64ef0a345985499d7caf43b2e10c8b2d2494de4b0459d908807578d961d9fc65925814f7923939e9a
|
data/bin/puppet_function_updater
CHANGED
data/lib/pfu.rb
CHANGED
data/lib/pfu/generator.rb
CHANGED
@@ -19,12 +19,14 @@ class Pfu::Generator
|
|
19
19
|
template = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'function.erb')
|
20
20
|
contents = ERB.new(File.read(template), nil, '-').result(binding)
|
21
21
|
|
22
|
+
$logger.info "Creating #{newpath}"
|
23
|
+
$logger.debug "Function contents:\n#{contents}"
|
24
|
+
|
22
25
|
begin
|
23
26
|
# syntax check the code before writing it
|
24
27
|
RubyVM::InstructionSequence.compile(contents)
|
25
28
|
FileUtils.mkdir_p("lib/puppet/functions/#{opts[:namespace]}")
|
26
29
|
File.write(newpath, contents)
|
27
|
-
$logger.info "Created #{newpath}."
|
28
30
|
rescue Exception => e
|
29
31
|
$logger.error "Oh crap; the generated function isn't valid Ruby code!"
|
30
32
|
$logger.error e.message
|
data/lib/pfu/parser.rb
CHANGED
@@ -10,14 +10,31 @@ module Puppet
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
# shudder
|
14
|
+
module Kernel
|
15
|
+
alias original_require require
|
16
|
+
|
17
|
+
def require(*a, &b)
|
18
|
+
original_require(*a, &b)
|
19
|
+
rescue LoadError => e
|
20
|
+
$logger.error "The function attempted to load libraries outside the function block."
|
21
|
+
$logger.warn "#{e.message} (ignored)"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
|
14
26
|
class Pfu::Parser
|
15
27
|
def self.parse(path)
|
16
28
|
source = File.read(path)
|
17
29
|
lines = source.split("\n")
|
18
30
|
|
19
|
-
|
20
|
-
|
31
|
+
begin
|
32
|
+
funcname, opts, lineno = eval(source)
|
33
|
+
rescue => e
|
34
|
+
$logger.error "The function in #{path} doesn't load properly!"
|
35
|
+
$logger.error e.message
|
36
|
+
return nil
|
37
|
+
end
|
21
38
|
|
22
39
|
stripcount = case source
|
23
40
|
when /module\s+Puppet::Parser::Functions/
|
@@ -30,9 +47,15 @@ class Pfu::Parser
|
|
30
47
|
block.gsub!(/\A.*\|\w+\|/, '') # remove block arg string ("|args|")
|
31
48
|
block.gsub!(/((end|})\s*){#{stripcount}}(^#.*|\s*)*\z/, '') # remove closing block keywords and trailing comments
|
32
49
|
|
50
|
+
heredoc = source.match(/<<-['"]?(\w+)['"]?/)
|
51
|
+
if heredoc
|
52
|
+
block.gsub!(/\A.*#{heredoc[1]}/m, '')
|
53
|
+
end
|
54
|
+
|
33
55
|
header = lines[0...(lines.index { |l| l =~ /Puppet::Parser::Functions/ })].join("\n")
|
34
56
|
args = lines[lineno-1].match(/\|\s*(\w+)\s*\|/)[1]
|
35
57
|
|
58
|
+
opts[:doc].gsub!("\n", "\n#")
|
36
59
|
|
37
60
|
opts[:name] = funcname.to_sym
|
38
61
|
opts[:header] = header
|
data/lib/pfu/version.rb
CHANGED