Module: Retrospec::Puppet::Functions
- Defined in:
- lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb
Class Method Summary collapse
-
.create_function(func_name, function_base = nil, &block) ⇒ Object
for puppet 4 functions.
- .dispatch(meth_name, &block) ⇒ Object
-
.find_required_methods(name, dispatched_methods = []) ⇒ Object
figures out which methods need to be present in the function so that we can create a test for them.
- .load_function(file) ⇒ Object
-
.method_missing(meth_sym, *arguments, &block) ⇒ Object
this is a catch all method that helps us discover which dsl methods are used.
Class Method Details
.create_function(func_name, function_base = nil, &block) ⇒ Object
for puppet 4 functions
14 15 16 17 18 19 20 21 22 23 |
# 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) ⇒ Object
48 49 50 51 52 |
# 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 = []) ⇒ Object
figures out which methods need to be present in the function so that we can create a test for them
40 41 42 43 44 45 46 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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) ⇒ Object
this is a catch all method that helps us discover which dsl methods are used
55 56 57 |
# 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 |