puppet-function-updater 0.0.4 → 0.0.5
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/CHANGELOG.md +3 -0
- data/bin/puppet_function_updater +2 -2
- data/lib/pfu/parser.rb +18 -5
- data/lib/pfu/version.rb +1 -1
- data/templates/function.erb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '094bf95a8bf88b5e9448ae673d41dc8f00302a82c8aab047f6910786c51b28e0'
|
4
|
+
data.tar.gz: f4b3e071ff53aa311f44b5918e2820fa52290f8c1f49126aed68ad4d1dcb64d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee2c6b1f06b074eabfdc11c659673e37c71013e5c7a0557d9991ac124ada0031847df5bb239db2a6773d0da51a2cd05d697c968bfe7bb9097c45e2e8e61bf874
|
7
|
+
data.tar.gz: 415fc16222ad2f3796b71a99e97a471868af5e5605c2e7eea81ab5e936acdc15df15bb2cc846d34c4f9b5d4f003637ba3423795ac2dfee046447030dc41985a4
|
data/CHANGELOG.md
CHANGED
data/bin/puppet_function_updater
CHANGED
@@ -65,8 +65,8 @@ options[:filenames].flatten!
|
|
65
65
|
|
66
66
|
if options[:namespace].nil?
|
67
67
|
if File.exist? 'metadata.json'
|
68
|
-
metadata = JSON.parse(File.read('metadata.json'))
|
69
|
-
options[:namespace] = metadata['name'].split('-')[1]
|
68
|
+
metadata = JSON.parse(File.read('metadata.json')) rescue {'name' => ''}
|
69
|
+
options[:namespace] = metadata['name'].split('-')[1] rescue nil
|
70
70
|
else
|
71
71
|
$logger.warn "*********** Namespace is highly suggested! *********** "
|
72
72
|
$logger.warn " Either run this command from within a module"
|
data/lib/pfu/parser.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# We don't actually use this, but a surprising number of functions assume it
|
2
|
+
require 'yaml'
|
3
|
+
|
1
4
|
module Puppet
|
2
5
|
module Parser
|
3
6
|
module Functions
|
@@ -13,6 +16,7 @@ end
|
|
13
16
|
# shudder
|
14
17
|
module Kernel
|
15
18
|
alias original_require require
|
19
|
+
alias original_require_relative require_relative
|
16
20
|
|
17
21
|
def require(*a, &b)
|
18
22
|
original_require(*a, &b)
|
@@ -20,16 +24,26 @@ module Kernel
|
|
20
24
|
$logger.warn "The function attempted to load libraries outside the function block."
|
21
25
|
$logger.warn "#{e.message} (ignored)"
|
22
26
|
end
|
27
|
+
|
28
|
+
def require_relative(*a, &b)
|
29
|
+
original_require_relative(*a, &b)
|
30
|
+
rescue LoadError => e
|
31
|
+
$logger.warn "The function attempted to relatively load libraries outside the function block."
|
32
|
+
$logger.warn "#{e.message} (ignored)"
|
33
|
+
end
|
23
34
|
end
|
24
35
|
|
25
36
|
|
26
37
|
class Pfu::Parser
|
27
38
|
def self.parse(path)
|
39
|
+
return unless File.extname(path) == '.rb'
|
28
40
|
source = File.read(path)
|
29
41
|
lines = source.split("\n")
|
30
42
|
|
31
43
|
begin
|
32
44
|
funcname, opts, lineno = eval(source)
|
45
|
+
|
46
|
+
raise 'Invalid function definition' unless (funcname and opts and lineno)
|
33
47
|
rescue => e
|
34
48
|
$logger.error "The function in #{path} doesn't load properly!"
|
35
49
|
$logger.error e.message
|
@@ -39,12 +53,12 @@ class Pfu::Parser
|
|
39
53
|
stripcount = case source
|
40
54
|
when /module\s+Puppet::Parser::Functions/
|
41
55
|
2
|
42
|
-
when /Puppet::Parser::Functions
|
56
|
+
when /Puppet::Parser::Functions(.|::)newfunction/
|
43
57
|
1
|
44
58
|
end
|
45
59
|
|
46
60
|
block = lines[(lineno-1)..-1].join("\n")
|
47
|
-
block.gsub!(/\A
|
61
|
+
block.gsub!(/\A.*\|\*?\w+\|/, '') # remove block arg string ("|args|")
|
48
62
|
block.gsub!(/((end|})\s*){#{stripcount}}(^#.*|\s*)*\z/, '') # remove closing block keywords and trailing comments
|
49
63
|
|
50
64
|
heredoc = source.match(/<<-['"]?(\w+)['"]?/)
|
@@ -53,10 +67,9 @@ class Pfu::Parser
|
|
53
67
|
end
|
54
68
|
|
55
69
|
header = lines[0...(lines.index { |l| l =~ /Puppet::Parser::Functions/ })].join("\n")
|
56
|
-
args = lines[lineno-1].match(/\|\s
|
57
|
-
|
58
|
-
opts[:doc].gsub!("\n", "\n#")
|
70
|
+
args = lines[lineno-1].match(/\|\s*\*?(\w+)\s*\|/)[1]
|
59
71
|
|
72
|
+
opts[:doc] = opts[:doc].gsub("\n", "\n#") unless opts[:doc].nil?
|
60
73
|
opts[:name] = funcname.to_sym
|
61
74
|
opts[:header] = header
|
62
75
|
opts[:args] = args
|
data/lib/pfu/version.rb
CHANGED
data/templates/function.erb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-function-updater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Ford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Run this command with a space separated list of either function file paths, or
|
@@ -34,7 +34,7 @@ files:
|
|
34
34
|
- lib/puppet/functions/testing/noopts.rb
|
35
35
|
- templates/function.erb
|
36
36
|
- templates/function_spec.erb
|
37
|
-
homepage:
|
37
|
+
homepage: https://binford2k.com/2019/11/27/automagic-function-port/
|
38
38
|
licenses:
|
39
39
|
- Apache-2.0
|
40
40
|
metadata: {}
|
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
|
-
rubygems_version: 3.0.
|
56
|
+
rubygems_version: 3.0.3
|
57
57
|
signing_key:
|
58
58
|
specification_version: 4
|
59
59
|
summary: Automagically ports legacy Puppet functions to the modern API.
|