module Retrospec::Puppet::Functions
Public Class Methods
create_function(func_name, function_base = nil, &block)
click to toggle source
for puppet 4 functions
# File lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb, line 14 def self.create_function(func_name, function_base = nil, &block) # the bundled version of puppet with this gem is quite old and is preventing me from creating a function # to get the actual properties of it. For now we can just skip the creation and stub enough functions # to get at the data. However, if we just eval the file we can probably bypass all this code and use class # methods instead #require 'puppet/pops' #f = ::Puppet::Functions.create_function(func_name, function_base, &block) block.call @model.name = func_name end
dispatch(meth_name, &block)
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb, line 48 def self.dispatch(meth_name, &block) @params = [] # reset the variable args = block.call @model.dispatched_methods[meth_name] = {:name => meth_name, :args => args} end
find_required_methods(name, dispatched_methods=[])
click to toggle source
figures out which methods need to be present in the function so that we can create a test for them
# File lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb, line 40 def self.find_required_methods(name, dispatched_methods=[]) if dispatched_methods.empty? [name] else dispatched_methods end end
load_function(file)
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb, line 25 def self.load_function(file) begin ::Puppet.initialize_settings rescue # do nothing otherwise calling init twice raises an error end @model = OpenStruct.new(:name => File.basename(file, '.rb'), :dispatched_methods => {}, :required_methods => []) f = eval(File.read(file)) @model.required_methods = find_required_methods(@model.name, @model.dispatched_methods.keys) @model end
method_missing(meth_sym, *arguments, &block)
click to toggle source
this is a catch all method that helps us discover which dsl methods are used
# File lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb, line 55 def self.method_missing(meth_sym, *arguments, &block) @params << {:name => meth_sym, :args => arguments} end