puppet-strings 2.2.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +87 -1
  3. data/CONTRIBUTING.md +32 -2
  4. data/README.md +81 -17
  5. data/lib/puppet-strings.rb +5 -3
  6. data/lib/puppet-strings/describe.rb +2 -0
  7. data/lib/puppet-strings/json.rb +4 -0
  8. data/lib/puppet-strings/markdown.rb +13 -9
  9. data/lib/puppet-strings/markdown/base.rb +30 -3
  10. data/lib/puppet-strings/markdown/data_type.rb +36 -0
  11. data/lib/puppet-strings/markdown/data_types.rb +43 -0
  12. data/lib/puppet-strings/markdown/defined_type.rb +2 -0
  13. data/lib/puppet-strings/markdown/defined_types.rb +3 -1
  14. data/lib/puppet-strings/markdown/function.rb +9 -7
  15. data/lib/puppet-strings/markdown/functions.rb +3 -1
  16. data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
  17. data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
  18. data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
  19. data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
  20. data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
  21. data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
  22. data/lib/puppet-strings/markdown/resource_type.rb +21 -2
  23. data/lib/puppet-strings/markdown/resource_types.rb +3 -1
  24. data/lib/puppet-strings/markdown/table_of_contents.rb +4 -1
  25. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +18 -6
  26. data/lib/puppet-strings/markdown/templates/data_type.erb +101 -0
  27. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  28. data/lib/puppet-strings/markdown/templates/function.erb +10 -1
  29. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  30. data/lib/puppet-strings/markdown/templates/resource_type.erb +35 -13
  31. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  32. data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
  33. data/lib/puppet-strings/tasks.rb +2 -0
  34. data/lib/puppet-strings/tasks/generate.rb +5 -2
  35. data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
  36. data/lib/puppet-strings/version.rb +3 -1
  37. data/lib/puppet-strings/yard.rb +19 -0
  38. data/lib/puppet-strings/yard/code_objects.rb +4 -0
  39. data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
  40. data/lib/puppet-strings/yard/code_objects/class.rb +5 -3
  41. data/lib/puppet-strings/yard/code_objects/data_type.rb +102 -0
  42. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +60 -0
  43. data/lib/puppet-strings/yard/code_objects/defined_type.rb +5 -3
  44. data/lib/puppet-strings/yard/code_objects/function.rb +9 -6
  45. data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
  46. data/lib/puppet-strings/yard/code_objects/plan.rb +5 -3
  47. data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
  48. data/lib/puppet-strings/yard/code_objects/task.rb +3 -1
  49. data/lib/puppet-strings/yard/code_objects/type.rb +49 -5
  50. data/lib/puppet-strings/yard/handlers.rb +4 -0
  51. data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
  52. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
  53. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
  54. data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
  55. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
  56. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
  57. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
  58. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
  59. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
  60. data/lib/puppet-strings/yard/handlers/ruby/base.rb +7 -2
  61. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +409 -0
  62. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -9
  63. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
  64. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +6 -3
  65. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +25 -12
  66. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +6 -3
  67. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +18 -1
  68. data/lib/puppet-strings/yard/parsers.rb +2 -0
  69. data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -1
  70. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
  71. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +11 -2
  72. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +29 -0
  73. data/lib/puppet-strings/yard/tags.rb +4 -0
  74. data/lib/puppet-strings/yard/tags/enum_tag.rb +14 -0
  75. data/lib/puppet-strings/yard/tags/factory.rb +18 -0
  76. data/lib/puppet-strings/yard/tags/overload_tag.rb +5 -2
  77. data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
  78. data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
  79. data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
  80. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  81. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
  82. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
  83. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
  84. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  85. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  86. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  87. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  88. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  89. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
  90. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  91. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  92. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  93. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  94. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  95. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  96. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  97. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  98. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
  99. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  100. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  101. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  102. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
  103. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  104. data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
  105. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
  106. data/lib/puppet-strings/yard/util.rb +7 -4
  107. data/lib/puppet/application/strings.rb +2 -0
  108. data/lib/puppet/face/strings.rb +7 -4
  109. data/lib/puppet/feature/rgen.rb +2 -0
  110. data/lib/puppet/feature/yard.rb +2 -0
  111. metadata +35 -45
  112. data/Gemfile +0 -38
  113. data/HISTORY.md +0 -218
  114. data/JSON.md +0 -802
  115. data/Rakefile +0 -98
  116. data/codecov.yml +0 -3
  117. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  118. data/spec/acceptance/emit_json_options.rb +0 -71
  119. data/spec/acceptance/generate_markdown_spec.rb +0 -49
  120. data/spec/acceptance/lib/util.rb +0 -163
  121. data/spec/acceptance/running_strings_generate.rb +0 -54
  122. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  123. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  124. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  125. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  126. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  127. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
  128. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  129. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
  130. data/spec/fixtures/unit/markdown/output.md +0 -508
  131. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -542
  132. data/spec/spec_helper.rb +0 -46
  133. data/spec/spec_helper_acceptance.rb +0 -28
  134. data/spec/unit/puppet-strings/describe_spec.rb +0 -141
  135. data/spec/unit/puppet-strings/json_spec.rb +0 -283
  136. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  137. data/spec/unit/puppet-strings/markdown_spec.rb +0 -296
  138. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  139. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -116
  140. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  141. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  142. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  143. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
  144. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
  145. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -235
  146. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -295
  147. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
  148. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  149. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
  150. data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -1,46 +0,0 @@
1
- if ENV['COVERAGE'] == 'yes'
2
- require 'simplecov'
3
- require 'simplecov-console'
4
- require 'codecov'
5
-
6
- SimpleCov.formatters = [
7
- SimpleCov::Formatter::HTMLFormatter,
8
- SimpleCov::Formatter::Console,
9
- SimpleCov::Formatter::Codecov,
10
- ]
11
- SimpleCov.start do
12
- track_files 'lib/**/*.rb'
13
-
14
- add_filter '/spec'
15
- end
16
- end
17
-
18
- require 'mocha'
19
- require 'rspec'
20
- require 'json_spec'
21
- require 'puppet/version'
22
- require 'puppet-strings'
23
- require 'puppet-strings/markdown'
24
- require 'puppet-strings/markdown/base'
25
- require 'puppet-strings/yard'
26
-
27
- # Explicitly set up YARD once
28
- PuppetStrings::Yard.setup!
29
-
30
- # Enable testing of Puppet functions if running against 4.1+
31
- TEST_PUPPET_FUNCTIONS = Puppet::Util::Package.versioncmp(Puppet.version, "4.1.0") >= 0
32
-
33
- # Enable testing of Puppet language functions declared with return type if running against 4.8+
34
- TEST_FUNCTION_RETURN_TYPE = Puppet::Util::Package.versioncmp(Puppet.version, "4.8.0") >= 0
35
-
36
- # Enable testing of Plans if Puppet version is greater than 5.0.0
37
- TEST_PUPPET_PLANS = Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") >= 0
38
-
39
- RSpec.configure do |config|
40
- config.mock_with :mocha
41
-
42
- config.before(:each) do
43
- # Always clear the YARD registry before each example
44
- YARD::Registry.clear
45
- end
46
- end
@@ -1,28 +0,0 @@
1
- require 'beaker-rspec/spec_helper'
2
- require 'beaker-rspec/helpers/serverspec'
3
- $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'acceptance/lib'))
4
- require 'util'
5
-
6
- unless ENV['RS_PROVISION'] == 'no'
7
- install_puppet
8
- end
9
-
10
- RSpec.configure do |c|
11
- # Readable test descriptions
12
- c.formatter = :documentation
13
-
14
- # Configure all nodes in nodeset
15
- c.before :suite do
16
- extend PuppetStrings::Acceptance::CommandUtils
17
- hosts.each do |host|
18
- scp_to(host, Dir.glob('puppet-strings*.gem').first, 'puppet-strings.gem')
19
- install_ca_certs(host)
20
- on host, "#{gem_command(host)} install yard"
21
- on host, "#{gem_command(host)} install rgen"
22
- on host, "#{gem_command(host)} install puppet-strings.gem"
23
-
24
- scp_to(host, Dir.glob('spec/fixtures/acceptance/modules/test/pkg/username-test*.gz').first, 'test.tar.gz')
25
- on host, puppet('module', 'install', 'test.tar.gz')
26
- end
27
- end
28
- end
@@ -1,141 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/describe'
3
- require 'tempfile'
4
-
5
- #TODO:
6
- #basic describe
7
- #params from other files (e.g. file content)
8
- #--providers - list providers in detail
9
- #X--list - list all providers summary
10
- #--meta - List all metaparameters
11
- #--short - only list params
12
-
13
- describe PuppetStrings::Describe do
14
- before :each do
15
- # Populate the YARD registry with both Puppet and Ruby source
16
-
17
-
18
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
19
- Puppet::Type.newtype(:database) do
20
- desc 'An example database server resource type.'
21
- end
22
- SOURCE
23
-
24
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
25
- Puppet::ResourceApi.register_type(
26
- name: 'apt_key',
27
- docs: <<-EOS,
28
- @summary Example resource type using the new API.
29
- @raise SomeError
30
- This type provides Puppet with the capabilities to manage GPG keys needed
31
- by apt to perform package validation. Apt has it's own GPG keyring that can
32
- be manipulated through the `apt-key` command.
33
- @example here's an example
34
- apt_key { '6F6B15509CF8E59E6E469F327F438280EF8D349F':
35
- source => 'http://apt.puppetlabs.com/pubkey.gpg'
36
- }
37
-
38
- **Autorequires**:
39
- If Puppet is given the location of a key file which looks like an absolute
40
- path this type will autorequire that file.
41
- EOS
42
- )
43
- SOURCE
44
-
45
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
46
- Puppet::Type.type(:file).newproperty(:content) do
47
- include Puppet::Util::Checksums
48
- include Puppet::DataSync
49
-
50
- attr_reader :actual_content
51
-
52
- desc <<-'EOT'
53
- The desired contents of a file, as a string. This attribute is mutually
54
- exclusive with `source` and `target`.
55
- EOT
56
- end
57
- SOURCE
58
-
59
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
60
- Puppet::Type.newtype(:file) do
61
- include Puppet::Util::Checksums
62
- include Puppet::Util::Backups
63
- include Puppet::Util::SymbolicFileMode
64
-
65
- @doc = "Manages files, including their content, ownership, and permissions.
66
-
67
- The `file` type can manage normal files, directories, and symlinks; the
68
- type should be specified in the `ensure` attribute."
69
-
70
- newparam(:path) do
71
- desc <<-'EOT'
72
- The path to the file to manage. Must be fully qualified.
73
-
74
- On Windows, the path should include the drive letter and should use `/` as
75
- the separator character (rather than `\\`).
76
- EOT
77
- isnamevar
78
- end
79
-
80
- end
81
- SOURCE
82
-
83
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
84
- Puppet::Type.type(:file).newproperty(:source) do
85
- include Puppet::Util::Checksums
86
- include Puppet::DataSync
87
-
88
- attr_reader :actual_content
89
-
90
- desc <<-'EOT'
91
- The desired contents of a file, as a string. This attribute is mutually
92
- exclusive with `source` and `target`.
93
- EOT
94
- end
95
- SOURCE
96
- end
97
-
98
- describe 'rendering DESCRIBE to stdout' do
99
- it 'should output the expected describe content for the list of types' do
100
- output = <<-DATA
101
- These are the types known to puppet:
102
- apt_key - This type provides Puppet with the capabiliti ...
103
- database - An example database server resource type.
104
- file - Manages files, including their content, owner ...
105
- DATA
106
- expect{ PuppetStrings::Describe.render(nil, true) }.to output(output).to_stdout
107
- end
108
- it 'should output the expected describe content for a type' do
109
- output = <<-DATA
110
-
111
- file
112
- ====
113
- Manages files, including their content, ownership, and permissions.
114
-
115
- The `file` type can manage normal files, directories, and symlinks; the
116
- type should be specified in the `ensure` attribute.
117
-
118
- Parameters
119
- ----------
120
-
121
- - **content**
122
- The desired contents of a file, as a string. This attribute is mutually
123
- exclusive with `source` and `target`.
124
-
125
- - **path**
126
- The path to the file to manage. Must be fully qualified.
127
-
128
- On Windows, the path should include the drive letter and should use `/` as
129
- the separator character (rather than `\\`).
130
-
131
- - **source**
132
- The desired contents of a file, as a string. This attribute is mutually
133
- exclusive with `source` and `target`.
134
-
135
- Providers
136
- ---------
137
- DATA
138
- expect{ PuppetStrings::Describe.render(['file']) }.to output(output).to_stdout
139
- end
140
- end
141
- end
@@ -1,283 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/json'
3
- require 'tempfile'
4
-
5
- describe PuppetStrings::Json do
6
- before :each do
7
- # Populate the YARD registry with both Puppet and Ruby source
8
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
9
- # A simple class.
10
- # @todo Do a thing
11
- # @note Some note
12
- # @param param1 First param.
13
- # @param param2 Second param.
14
- # @param param3 Third param.
15
- class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
16
- }
17
-
18
- # A simple defined type.
19
- # @param param1 First param.
20
- # @param param2 Second param.
21
- # @param param3 Third param.
22
- define dt(Integer $param1, $param2, String $param3 = hi) {
23
- }
24
- SOURCE
25
-
26
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet) if TEST_PUPPET_PLANS
27
- # A simple plan.
28
- # @param param1 First param.
29
- # @param param2 Second param.
30
- # @param param3 Third param.
31
- plan plann(String $param1, $param2, Integer $param3 = 1) {
32
- }
33
- SOURCE
34
-
35
- # Only include Puppet functions for 4.1+
36
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet) if TEST_PUPPET_FUNCTIONS
37
- # A simple function.
38
- # @param param1 First param.
39
- # @param param2 Second param.
40
- # @param param3 Third param.
41
- # @return [Undef] Returns nothing.
42
- function func(Integer $param1, $param2, String $param3 = hi) {
43
- }
44
- SOURCE
45
-
46
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :json)
47
- {
48
- "description": "Allows you to backup your database to local file.",
49
- "input_method": "stdin",
50
- "parameters": {
51
- "database": {
52
- "description": "Database to connect to",
53
- "type": "Optional[String[1]]"
54
- },
55
- "user": {
56
- "description": "The user",
57
- "type": "Optional[String[1]]"
58
- },
59
- "password": {
60
- "description": "The password",
61
- "type": "Optional[String[1]]"
62
- },
63
- "sql": {
64
- "description": "Path to file you want backup to",
65
- "type": "String[1]"
66
- }
67
- }
68
- }
69
- SOURCE
70
-
71
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
72
- Puppet::Parser::Functions.newfunction(:func3x, doc: <<-DOC
73
- An example 3.x function.
74
- @param [String] first The first parameter.
75
- @param second The second parameter.
76
- @return [Undef] Returns nothing.
77
- DOC
78
- ) do |*args|
79
- end
80
-
81
- # An example 4.x function.
82
- Puppet::Functions.create_function(:func4x) do
83
- # The first overload.
84
- # @param param1 The first parameter.
85
- # @param param2 The second parameter.
86
- # @param param3 The third parameter.
87
- # @return Returns nothing.
88
- dispatch :foo do
89
- param 'Integer', :param1
90
- param 'Any', :param2
91
- optional_param 'Array[String]', :param3
92
- return_type 'Undef'
93
- end
94
-
95
- # @param param The first parameter.
96
- # @param block The block parameter.
97
- # @return Returns a string.
98
- dispatch :other do
99
- param 'Boolean', :param
100
- block_param
101
- return_type 'String'
102
- end
103
- end
104
-
105
- # An example 4.x function with only one signature.
106
- Puppet::Functions.create_function(:func4x_1) do
107
- # @param param1 The first parameter.
108
- # @return [Undef] Returns nothing.
109
- dispatch :foobarbaz do
110
- param 'Integer', :param1
111
- end
112
- end
113
-
114
- Puppet::Type.type(:database).provide :linux do
115
- desc 'An example provider on Linux.'
116
- confine kernel: 'Linux'
117
- confine osfamily: 'RedHat'
118
- defaultfor :kernel => 'Linux'
119
- defaultfor :osfamily => 'RedHat', :operatingsystemmajrelease => '7'
120
- has_feature :implements_some_feature
121
- has_feature :some_other_feature
122
- commands foo: '/usr/bin/foo'
123
- end
124
-
125
- Puppet::Type.newtype(:database) do
126
- desc 'An example database server resource type.'
127
- feature :encryption, 'The provider supports encryption.', methods: [:encrypt]
128
- ensurable do
129
- desc 'What state the database should be in.'
130
- defaultvalues
131
- aliasvalue(:up, :present)
132
- aliasvalue(:down, :absent)
133
- defaultto :up
134
- end
135
-
136
- newparam(:address) do
137
- isnamevar
138
- desc 'The database server name.'
139
- end
140
-
141
- newparam(:encryption_key, required_features: :encryption) do
142
- desc 'The encryption key to use.'
143
- end
144
-
145
- newparam(:encrypt, :parent => Puppet::Parameter::Boolean) do
146
- desc 'Whether or not to encrypt the database.'
147
- defaultto false
148
- end
149
-
150
- newproperty(:file) do
151
- desc 'The database file to use.'
152
- end
153
-
154
- newproperty(:log_level) do
155
- desc 'The log level to use.'
156
- newvalue(:debug)
157
- newvalue(:warn)
158
- newvalue(:error)
159
- defaultto 'warn'
160
- end
161
- end
162
-
163
- Puppet::ResourceApi.register_type(
164
- name: 'apt_key',
165
- docs: <<-EOS,
166
- @summary Example resource type using the new API.
167
- @raise SomeError
168
- This type provides Puppet with the capabilities to manage GPG keys needed
169
- by apt to perform package validation. Apt has it's own GPG keyring that can
170
- be manipulated through the `apt-key` command.
171
- @example here's an example
172
- apt_key { '6F6B15509CF8E59E6E469F327F438280EF8D349F':
173
- source => 'http://apt.puppetlabs.com/pubkey.gpg'
174
- }
175
-
176
- **Autorequires**:
177
- If Puppet is given the location of a key file which looks like an absolute
178
- path this type will autorequire that file.
179
- EOS
180
- attributes: {
181
- ensure: {
182
- type: 'Enum[present, absent]',
183
- desc: 'Whether this apt key should be present or absent on the target system.'
184
- },
185
- id: {
186
- type: 'Variant[Pattern[/\A(0x)?[0-9a-fA-F]{8}\Z/], Pattern[/\A(0x)?[0-9a-fA-F]{16}\Z/], Pattern[/\A(0x)?[0-9a-fA-F]{40}\Z/]]',
187
- behaviour: :namevar,
188
- desc: 'The ID of the key you want to manage.',
189
- },
190
- # ...
191
- created: {
192
- type: 'String',
193
- behaviour: :read_only,
194
- desc: 'Date the key was created, in ISO format.',
195
- },
196
- },
197
- autorequires: {
198
- file: '$source', # will evaluate to the value of the `source` attribute
199
- package: 'apt',
200
- },
201
- )
202
- SOURCE
203
- end
204
-
205
- RSpec.shared_examples "correct JSON" do
206
- it 'should include data for Puppet Classes' do
207
- puppet_class_json = YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash).to_json
208
-
209
- expect(json_output).to include_json(puppet_class_json)
210
- end
211
-
212
- it 'should include data for Puppet Defined Types' do
213
- defined_types_json = YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash).to_json
214
-
215
- expect(json_output).to include_json(defined_types_json)
216
- end
217
-
218
- it 'should include data for Puppet Resouce Types' do
219
- resource_types_json = YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash).to_json
220
-
221
- expect(json_output).to include_json(resource_types_json)
222
- end
223
-
224
- it 'should include data for Puppet Providers' do
225
- providers_json = YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash).to_json
226
-
227
- expect(json_output).to include_json(providers_json)
228
- end
229
-
230
- it 'should include data for Puppet Functions', if: TEST_PUPPET_FUNCTIONS do
231
- puppet_functions_json = YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash).to_json
232
-
233
- expect(json_output).to include_json(puppet_functions_json)
234
- end
235
-
236
- it 'should include data for Puppet Tasks' do
237
- puppet_tasks_json = YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash).to_json
238
-
239
- expect(json_output).to include_json(puppet_tasks_json)
240
- end
241
-
242
- it 'should include data for Puppet Plans', if: TEST_PUPPET_PLANS do
243
- puppet_plans_json = YARD::Registry.all(:puppet_plan).sort_by!(&:name).map!(&:to_hash).to_json
244
-
245
- expect(json_output).to include_json(puppet_plans_json)
246
- end
247
- end
248
-
249
- describe 'rendering JSON to a file' do
250
- let(:json_output) do
251
- json_output = nil
252
-
253
- Tempfile.open('json') do |file|
254
- PuppetStrings::Json.render(file.path)
255
-
256
- json_output = File.read(file.path)
257
- end
258
-
259
- json_output
260
- end
261
-
262
- include_examples "correct JSON"
263
- end
264
-
265
- describe 'rendering JSON to stdout' do
266
- let(:json_output) { @json_output }
267
-
268
- before(:each) do
269
- output = StringIO.new
270
-
271
- old_stdout = $stdout
272
- $stdout = output
273
-
274
- PuppetStrings::Json.render(nil)
275
-
276
- $stdout = old_stdout
277
-
278
- @json_output = output.string
279
- end
280
-
281
- include_examples "correct JSON"
282
- end
283
- end