puppet-function-updater 0.0.1 → 0.0.2

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: 43740352c17551ddd5440e4ece70ad04248b2ee9a3c64ad7a8cd13e2f6a2c8f1
4
- data.tar.gz: c515002e42faadc8fee35f37a6a76805d2cc0d44ace7d9609e494cc4590c9360
3
+ metadata.gz: c4e20e5f6989948ee8a47c6be69b5c381a0817ae8b26ccf7daac5d3e437de74b
4
+ data.tar.gz: cd83a4c1687b449691de92a67de33a9a80fd11f31411232ff41472b4735cd3b5
5
5
  SHA512:
6
- metadata.gz: a8fa785031af5cd3d22adaee5db4363bb8849ee541ef0c939cdb67d34e9715b266f83ddf708721ac4f3c23ccbdd84d999eba5c8daef97b0a326097fb26cdad2b
7
- data.tar.gz: 642f1dedcb74988a68f6c872598ac9d18f55db968a328b4a8f4a7b58f00b9d0f9e69584605f767fcaf0f94fcfb2c107e2b6001a6e7c000fd65787fc4ab603bfe
6
+ metadata.gz: d308a64a254c50864dd8b0840f42cb2feee2da57c452696b0e3069ddb602bbb35119ee3708a71801e057c51c5b3aebaaff52ebf113e0a8380f714b1e5f1f1d66
7
+ data.tar.gz: c08d5bef117c504be32a60e19b42e860d63f9e390c0708d64ef0a345985499d7caf43b2e10c8b2d2494de4b0459d908807578d961d9fc65925814f7923939e9a
@@ -3,6 +3,7 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
3
 
4
4
  require 'logger'
5
5
  require 'optparse'
6
+ require 'json'
6
7
  require 'pfu'
7
8
 
8
9
  loglevel = Logger::WARN
data/lib/pfu.rb CHANGED
@@ -10,7 +10,7 @@ class Pfu
10
10
 
11
11
  def refactor!
12
12
  @filenames.each do |path|
13
- data = Pfu::Parser.parse(path)
13
+ next unless data = Pfu::Parser.parse(path)
14
14
  data[:namespace] = @namespace
15
15
  Pfu::Generator.write(data)
16
16
  end
@@ -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
@@ -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
- funcname, opts, lineno = eval(source)
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
@@ -1,3 +1,3 @@
1
1
  class Pfu
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-function-updater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Ford