summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/dsl.rb4
-rw-r--r--lib/puppet/dsl/resource_type_api.rb26
-rw-r--r--lib/puppet/parser/parser_support.rb4
3 files changed, 19 insertions, 15 deletions
diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb
index abdb78f67..97a310436 100644
--- a/lib/puppet/dsl.rb
+++ b/lib/puppet/dsl.rb
@@ -5,7 +5,3 @@ end
require 'puppet/dsl/resource_type_api'
require 'puppet/dsl/resource_api'
-
-class Object
- include Puppet::DSL::ResourceTypeAPI
-end
diff --git a/lib/puppet/dsl/resource_type_api.rb b/lib/puppet/dsl/resource_type_api.rb
index 487aab99d..ecb914189 100644
--- a/lib/puppet/dsl/resource_type_api.rb
+++ b/lib/puppet/dsl/resource_type_api.rb
@@ -1,33 +1,39 @@
require 'puppet/resource/type'
-module Puppet::DSL::ResourceTypeAPI
+class Puppet::DSL::ResourceTypeAPI
def define(name, *args, &block)
- result = mk_resource_type(:definition, name, Hash.new, block)
- result.set_arguments(munge_type_arguments(args))
- result
+ result = __mk_resource_type__(:definition, name, Hash.new, block)
+ result.set_arguments(__munge_type_arguments__(args))
+ nil
end
def hostclass(name, options = {}, &block)
- mk_resource_type(:hostclass, name, options, block)
+ __mk_resource_type__(:hostclass, name, options, block)
+ nil
end
def node(name, options = {}, &block)
- mk_resource_type(:node, name, options, block)
+ __mk_resource_type__(:node, name, options, block)
+ nil
end
- private
+ # Note: we don't want the user to call the following methods
+ # directly. However, we can't stop them by making the methods
+ # private because the user's .rb code gets instance_eval'ed on an
+ # instance of this class. So instead we name the methods using
+ # double underscores to discourage customers from calling them.
- def mk_resource_type(type, name, options, code)
+ def __mk_resource_type__(type, name, options, code)
klass = Puppet::Resource::Type.new(type, name, options)
klass.ruby_code = code if code
- Puppet::Node::Environment.new.known_resource_types.add klass
+ Thread.current[:known_resource_types].add klass
klass
end
- def munge_type_arguments(args)
+ def __munge_type_arguments__(args)
args.inject([]) do |result, item|
if item.is_a?(Hash)
item.each { |p, v| result << [p, v] }
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 41bebe420..288abb582 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -187,7 +187,9 @@ class Puppet::Parser::Parser
end
def parse_ruby_file
- require self.file
+ # Execute the contents of the file inside its own "main" object so
+ # that it can call methods in the resource type API.
+ Puppet::DSL::ResourceTypeAPI.new.instance_eval(File.read(self.file))
end
def string=(string)