Sha256: 8000f04b6a8b00d17f479631ef61e2e51c85493793fbe58146c67783dea72614

Contents?: true

Size: 1.91 KB

Versions: 40

Compression:

Stored size: 1.91 KB

Contents

require 'puppet/generate/models/type/property'

module Puppet
  module Generate
    module Models
      module Type
        # A model for Puppet resource types.
        class Type
          # Gets the name of the type as a Puppet string literal.
          attr_reader :name

          # Gets the doc string of the type.
          attr_reader :doc

          # Gets the properties of the type.
          attr_reader :properties

          # Gets the parameters of the type.
          attr_reader :parameters

          # Gets the title patterns of the type
          attr_reader :title_patterns

          # Gets the isomorphic member attribute of the type
          attr_reader :isomorphic

          # Gets the capability member attribute of the type
          attr_reader :capability

          # Initializes a type model.
          # @param type [Puppet::Type] The Puppet type to model.
          # @return [void]
          def initialize(type)
            @name = Puppet::Pops::Types::StringConverter.convert(type.name.to_s, '%p')
            @doc = type.doc.strip
            @properties = type.properties.map { |p| Property.new(p) }
            @parameters = type.parameters.map do |name|
              Property.new(type.paramclass(name))
            end
            @title_patterns = Hash[type.title_patterns.map do |mapping|
              [
                "/#{mapping[0].source.gsub(/\//, '\/')}/",
                mapping[1].map { |names|
                  next if names.empty?
                  raise Puppet::Error, 'title patterns that use procs are not supported.' if names.size != 1
                  Puppet::Pops::Types::StringConverter.convert(names[0].to_s, '%p')
                }
              ]
            end]
            @isomorphic = type.isomorphic?
            @capability = type.is_capability?
          end

          def render(template)
            template.result(binding)
          end
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
puppet-4.10.1 lib/puppet/generate/models/type/type.rb
puppet-4.10.1-x86-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.10.1-x64-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.10.1-universal-darwin lib/puppet/generate/models/type/type.rb
puppet-4.10.0 lib/puppet/generate/models/type/type.rb
puppet-4.10.0-x86-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.10.0-x64-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.10.0-universal-darwin lib/puppet/generate/models/type/type.rb
puppet-4.9.4 lib/puppet/generate/models/type/type.rb
puppet-4.9.4-x86-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.9.4-x64-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.9.4-universal-darwin lib/puppet/generate/models/type/type.rb
puppet-4.9.3 lib/puppet/generate/models/type/type.rb
puppet-4.9.3-x86-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.9.3-x64-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.9.3-universal-darwin lib/puppet/generate/models/type/type.rb
puppet-4.9.2 lib/puppet/generate/models/type/type.rb
puppet-4.9.2-x86-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.9.2-x64-mingw32 lib/puppet/generate/models/type/type.rb
puppet-4.9.2-universal-darwin lib/puppet/generate/models/type/type.rb