class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler::LazyLiteralEvaluator

Lazily evaluates a Pops object, ignoring any objects that cannot be converted to a literal value. Based on the Puppet Literal Evaluator Ref - github.com/puppetlabs/puppet/blob/ba4d1a1aba0095d3c70b98fea5c67434a4876a61/lib/puppet/pops/evaluator/literal_evaluator.rb

Literal values for: String (not containing interpolation) Numbers Booleans Undef (produces nil) Array Hash QualifiedName Default (produced :default) Regular Expression (produces ruby regular expression) QualifiedReference e.g. File, FooBar AccessExpression

Anything else is ignored

Public Class Methods

new() click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 138
def initialize
  @literal_visitor = ::Puppet::Pops::Visitor.new(self, 'literal', 0, 0)
end

Public Instance Methods

literal(ast) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 142
def literal(ast)
  @literal_visitor.visit_this_0(self, ast)
end
literal_AccessExpression(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 153
def literal_AccessExpression(o)
  # Extract the raw text of the Access Expression
  PuppetStrings::Yard::Util.ast_to_text(o)
end
literal_ConcatenatedString(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 204
def literal_ConcatenatedString(o)
  # use double quoted string value if there is no interpolation
  throw :not_literal unless o.segments.size == 1 && o.segments[0].is_a?(Model::LiteralString)
  o.segments[0].value
end
literal_Factory(o) click to toggle source

—– The following methods are the same as the original Literal_evaluator

# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 164
def literal_Factory(o)
  literal(o.model)
end
literal_LiteralBoolean(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 188
def literal_LiteralBoolean(o)
  o.value
end
literal_LiteralDefault(_o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 196
def literal_LiteralDefault(_o)
  :default
end
literal_LiteralHash(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 214
def literal_LiteralHash(o)
  o.entries.each_with_object({}) do |entry, result|
    result[literal(entry.key)] = literal(entry.value)
  end
end
literal_LiteralList(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 210
def literal_LiteralList(o)
  o.values.map { |v| literal(v) }
end
literal_LiteralNumber(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 180
def literal_LiteralNumber(o)
  o.value
end
literal_LiteralRegularExpression(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 200
def literal_LiteralRegularExpression(o)
  o.value
end
literal_LiteralString(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 172
def literal_LiteralString(o)
  o.value
end
literal_LiteralUndef(_o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 192
def literal_LiteralUndef(_o)
  nil
end
literal_Object(o) click to toggle source

TODO: Fix the rubocop violations in this file between the following rubocop:disable/enable lines rubocop:disable Naming/MethodName —– The following methods are different/additions from the original Literal_evaluator

# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 149
def literal_Object(o)
  # Ignore any other object types
end
literal_Program(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 168
def literal_Program(o)
  literal(o.body)
end
literal_QualifiedName(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 176
def literal_QualifiedName(o)
  o.value
end
literal_QualifiedReference(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 158
def literal_QualifiedReference(o)
  # Extract the raw text of the Qualified Reference
  PuppetStrings::Yard::Util.ast_to_text(o)
end
literal_UnaryMinusExpression(o) click to toggle source
# File lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb, line 184
def literal_UnaryMinusExpression(o)
  -1 * literal(o.expr)
end