Class: Puppet::DSL::ResourceTypeAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/dsl/resource_type_api.rb

Instance Method Summary collapse

Instance Method Details

#__mk_resource_type__(type, name, options, code) ⇒ Object

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.



26
27
28
29
30
31
32
33
34
# File 'lib/puppet/dsl/resource_type_api.rb', line 26

def __mk_resource_type__(type, name, options, code)
  klass = Puppet::Resource::Type.new(type, name, options)

  klass.ruby_code = code if code

  Thread.current[:known_resource_types].add klass

  klass
end

#__munge_type_arguments__(args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet/dsl/resource_type_api.rb', line 36

def __munge_type_arguments__(args)
  args.inject([]) do |result, item|
    if item.is_a?(Hash)
      item.each { |p, v| result << [p, v] }
    else
      result << item
    end
    result
  end
end

#define(name, *args, &block) ⇒ Object



4
5
6
7
8
# File 'lib/puppet/dsl/resource_type_api.rb', line 4

def define(name, *args, &block)
  result = __mk_resource_type__(:definition, name, Hash.new, block)
  result.set_arguments(__munge_type_arguments__(args))
  nil
end

#hostclass(name, options = {}, &block) ⇒ Object



10
11
12
13
# File 'lib/puppet/dsl/resource_type_api.rb', line 10

def hostclass(name, options = {}, &block)
  __mk_resource_type__(:hostclass, name, options, block)
  nil
end

#node(name, options = {}, &block) ⇒ Object



15
16
17
18
# File 'lib/puppet/dsl/resource_type_api.rb', line 15

def node(name, options = {}, &block)
  __mk_resource_type__(:node, name, options, block)
  nil
end