class Retrospec::Puppet::Type
Public Class Methods
load_type(type_file, provider_file = nil)
click to toggle source
loads the type_file and provider_file if given determines if type or provider is being used and evals the code if the provider_file is not loadable we cannot build a full context for the template to be rendered with so we use a default context instead
# File lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb, line 19 def self.load_type(type_file, provider_file = nil) if provider_file begin file = provider_file @model = OpenStruct.new(:name => File.basename(file, '.rb'), :file => file, :class_methods => [], :instance_methods => [], :properties => [], :parameters => []) require type_file require provider_file t = eval(File.read(file)) @model.parameters = t.resource_type.parameters @model.properties = t.resource_type.validproperties @model.name = t.name @model.class_methods = t.methods(false) @model.instance_methods = t.instance_methods(false) rescue LoadError => e puts "#{e.message}, generating empty file".fatal rescue NameError => e puts "#{e.message}, is this valid provider code?".fatal rescue NoMethodError => e puts "#{e.message}, is this valid provider code?".fatal rescue ::Puppet::Context::UndefinedBindingError => e puts "There was an issue with loading the provider code for #{file}, skipping".fatal end @model else begin require type_file file = type_file @model = OpenStruct.new(:name => File.basename(file, '.rb'), :file => file, :properties => [], :instance_methods => [], :parameters => [], :methods_defined => []) t = eval(File.read(file)) @model.name = t.name @model.parameters = t.parameters @model.properties = t.properties.collect(&:name) @model.instance_methods = t.instance_methods(false) @model rescue LoadError => e puts "#{e.message}, generating empty file".fatal rescue NameError => e puts "#{e.message}, is this valid type code?".fatal rescue NoMethodError => e puts "#{e.message}, is this valid type code?".fatal end end @model end
newtype(name, _options = {}, &_block)
click to toggle source
I don't know of a better way to get the name of the type
# File lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb, line 73 def self.newtype(name, _options = {}, &_block) ::Puppet::Type.type(name) end
type(name, _options = {}, &_block)
click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb, line 68 def self.type(name, _options = {}, &_block) ::Puppet::Type.type(name) end