Class: PuppetStrings::Yard::Parsers::JSON::Parser
- Inherits:
-
YARD::Parser::Base
- Object
- YARD::Parser::Base
- PuppetStrings::Yard::Parsers::JSON::Parser
- Defined in:
- lib/puppet-strings/yard/parsers/json/parser.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #enumerator ⇒ Object
-
#initialize(source, filename) ⇒ void
constructor
Initializes the parser.
-
#parse ⇒ void
Parses the source.
Constructor Details
#initialize(source, filename) ⇒ void
Initializes the parser.
12 13 14 15 16 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 12 def initialize(source, filename) @file = filename @source = source @statements = [] end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 6 def file @file end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 6 def source @source end |
Instance Method Details
#enumerator ⇒ Object
18 19 20 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 18 def enumerator @statements end |
#parse ⇒ void
This method returns an undefined value.
Parses the source
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 24 def parse begin json = JSON.parse(source) # TODO: this should compare json to a Task metadata json-schema or perform some other hueristics # to determine what type of statement it represents @statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty? rescue # rubocop:disable Style/RescueStandardError Just catch everything log.error "Failed to parse #{@file}: " @statements = [] end @statements.freeze self end |