puppet-function-updater 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5913312054d42bd2b3bfdcb744600991f0b23aa09a4763153f48f0cddb2f355
4
- data.tar.gz: 8734defb6ff4b41c8e99dcd2baad098aa58a3534d2ed4bb61ba244535d405a63
3
+ metadata.gz: '094bf95a8bf88b5e9448ae673d41dc8f00302a82c8aab047f6910786c51b28e0'
4
+ data.tar.gz: f4b3e071ff53aa311f44b5918e2820fa52290f8c1f49126aed68ad4d1dcb64d2
5
5
  SHA512:
6
- metadata.gz: a4ddd547257eca3091c81ca70f85a8ce81d371f2f409f335079cb26fc3fe263b2698cf0fe1c71d2a688662f031127b1212a27d169e9d1c6fe9054d9a3b02d83c
7
- data.tar.gz: 3b987e1bce14d1b7d4f74c459911975cadd43816b38da43e6ce70d64da5f976f98acb580f91e8276ebcb549f29c81ca807631618ce6f8558322c5f067dbaf764
6
+ metadata.gz: ee2c6b1f06b074eabfdc11c659673e37c71013e5c7a0557d9991ac124ada0031847df5bb239db2a6773d0da51a2cd05d697c968bfe7bb9097c45e2e8e61bf874
7
+ data.tar.gz: 415fc16222ad2f3796b71a99e97a471868af5e5605c2e7eea81ab5e936acdc15df15bb2cc846d34c4f9b5d4f003637ba3423795ac2dfee046447030dc41985a4
@@ -1,3 +1,6 @@
1
+ v0.0.5
2
+ * Catch a lot of weird little edge cases
3
+
1
4
  v0.0.4
2
5
  * Generate a simple spec test for the new function
3
6
  * Properly report the `require` warning as a warning
@@ -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"
@@ -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.newfunction/
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.*\|\w+\|/, '') # remove block arg string ("|args|")
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*(\w+)\s*\|/)[1]
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
@@ -1,3 +1,3 @@
1
1
  class Pfu
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -10,7 +10,7 @@
10
10
  # ---- original file header ----
11
11
  #
12
12
  # @summary
13
- # <%= opts[:doc] %>
13
+ # <%= opts[:doc] || 'Summarise what the function does here' %>
14
14
  #
15
15
  Puppet::Functions.create_function(:'<%= opts[:fullname] %>') do
16
16
  # @param <%= opts[:args] %>
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
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: 2019-11-29 00:00:00.000000000 Z
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.2
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.