kafo_parsers 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8674bbeb7dc2278405937a43e943375a148d0873
4
- data.tar.gz: 03da76cb953920f9943777ac664e6f084f359a2c
3
+ metadata.gz: c1a2df4e35b7096729a5d26772b6d88b8facbfd1
4
+ data.tar.gz: d0ddc6bd2ed3172db9b512f01d62646e138484fe
5
5
  SHA512:
6
- metadata.gz: d205360335c2d1df463ef1b0829ad21a9fea9255fa98cd8db1f7699f38dbf625d870e71a678034b09dea679407d3ff8f668361cef20ff35a3a261299b15216bd
7
- data.tar.gz: 4f69747d60eaecdc329a9f3e179b2747afc7825ea46e896517cdc5901b4d04dda10d075f19d23db64f8a490ca5a304e37dfae49232252479ec2284a6b8dec0b6
6
+ metadata.gz: da03223bc048295fc11d518c143b836d135dff0f9715e0865b756f0b8086082a59429b01dc9d5220068e41787788aa58f5ed8581314419ebc902e20a0eabf219
7
+ data.tar.gz: b99099b7a24d1cd34acdd7ce99e296b936f5086c141d64d11e249c4ca8005799755095fbf273680e69c7a8b0c98ab6900897888755acb9b5fb2e985277da3a9b
data/README.md CHANGED
@@ -7,6 +7,8 @@ to do is provide a path to manifest file you want to be parsed.
7
7
  The library is used in [Kafo](https://github.com/theforeman/kafo), which can
8
8
  be used to get an idea of what's possible to build on top of this library.
9
9
 
10
+ Currently puppet classes and types (definitions) are supported.
11
+
10
12
  ## Installation
11
13
 
12
14
  Add this line to your application's Gemfile:
@@ -8,6 +8,8 @@ module KafoParsers
8
8
  # have to be defined in puppet DSL and vice versa, we just gather all info
9
9
  # we can read from the whole manifest
10
10
  class PuppetModuleParser
11
+ @@puppet_initialized = false
12
+
11
13
  # You can call this method to get all supported information from a given manifest
12
14
  #
13
15
  # @param [ String ] manifest file path to parse
@@ -28,19 +30,28 @@ module KafoParsers
28
30
  def initialize(file)
29
31
  @file = file
30
32
  raise ModuleName, "File not found #{file}, check your answer file" unless File.exists?(file)
31
- Puppet.settings[:confdir] ||= '/' # just some stubbing
32
- if Puppet::Node::Environment.respond_to?(:create)
33
- env = Puppet::Node::Environment.create(:production, [], '')
34
- else
35
- env = Puppet::Node::Environment.new(:production)
33
+
34
+ unless @@puppet_initialized
35
+ if Puppet::PUPPETVERSION.to_i >= 3
36
+ Puppet.initialize_settings
37
+ else
38
+ Puppet.parse_config
39
+ end
40
+ @@puppet_initialized = true
36
41
  end
42
+
43
+ env = Puppet::Node::Environment.new
37
44
  parser = Puppet::Parser::Parser.new(env)
38
45
  parser.import(@file)
39
46
 
40
47
  # Find object corresponding to class defined in init.pp in list of hostclasses
41
- parser.environment.known_resource_types.hostclasses.each do |ast_objects|
42
- ast_type = ast_objects.last
43
- @object = ast_type if ast_type.file == file
48
+ ast_types = parser.environment.known_resource_types.hostclasses.map(&:last)
49
+ @object = ast_types.find { |ast_type| ast_type.file == file }
50
+
51
+ # Find object in list of definitions if not found among hostclasses
52
+ if @object.nil?
53
+ ast_types = parser.environment.known_resource_types.definitions.map(&:last)
54
+ @object = ast_types.find { |ast_type| ast_type.file == file }
44
55
  end
45
56
 
46
57
  parser
@@ -65,17 +76,19 @@ module KafoParsers
65
76
  # :types => { $param1 => 'boolean'},
66
77
  # :groups => { $param1 => ['Parameters', 'Advanced']},
67
78
  # :conditions => { $param1 => '$db_type == "mysql"'},
79
+ # :object_type => 'hostclass' # or definition
68
80
  # }
69
81
  def docs
70
- data = { :docs => {}, :types => {}, :groups => {}, :conditions => {} }
82
+ data = { :docs => {}, :types => {}, :groups => {}, :conditions => {}, :object_type => '' }
71
83
  if @object.nil?
72
84
  raise DocParseError, "no documentation found for manifest #{@file}, parsing error?"
73
85
  elsif !@object.doc.nil?
74
- parser = DocParser.new(@object.doc).parse
75
- data[:docs] = parser.docs
76
- data[:groups] = parser.groups
77
- data[:types] = parser.types
78
- data[:conditions] = parser.conditions
86
+ parser = DocParser.new(@object.doc).parse
87
+ data[:docs] = parser.docs
88
+ data[:groups] = parser.groups
89
+ data[:types] = parser.types
90
+ data[:conditions] = parser.conditions
91
+ data[:object_type] = @object.type.to_s
79
92
  end
80
93
  data
81
94
  end
@@ -1,3 +1,3 @@
1
1
  module KafoParsers
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kafo_parsers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-30 00:00:00.000000000 Z
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,30 +56,30 @@ dependencies:
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - <
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - <
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '0.9'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ci_reporter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.9.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.9.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: puppet
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -116,14 +116,14 @@ executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - lib/kafo_parsers/puppet_module_parser.rb
119
+ - LICENSE.txt
120
+ - README.md
121
+ - Rakefile
122
+ - lib/kafo_parsers.rb
120
123
  - lib/kafo_parsers/doc_parser.rb
121
124
  - lib/kafo_parsers/exceptions.rb
125
+ - lib/kafo_parsers/puppet_module_parser.rb
122
126
  - lib/kafo_parsers/version.rb
123
- - lib/kafo_parsers.rb
124
- - LICENSE.txt
125
- - Rakefile
126
- - README.md
127
127
  homepage: https://github.com/theforeman/kafo_parsers
128
128
  licenses:
129
129
  - GPLv3+
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.0.3
147
+ rubygems_version: 2.4.6
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Puppet module parsers