Class: Puppet::Pops::Serialization::JsonPath::Resolver Private
- Defined in:
- lib/puppet/pops/serialization/json_path.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Resolver for JSON path that uses the Puppet parser to create the AST. The path must start with ‘$’ which denotes the value that is passed into the parser. This parser can easily be extended with more elaborate resolution mechanisms involving document sets.
The parser is limited to constructs generated by the JsonPath#to_json_path method.
Class Method Summary collapse
- .singleton ⇒ Object private
Instance Method Summary collapse
-
#initialize ⇒ Resolver
constructor
private
A new instance of Resolver.
-
#resolve(context, path) ⇒ Object
private
Resolve the given path in the given context.
- #resolve_AccessExpression(ast, context, path) ⇒ Object private
- #resolve_any(ast, context, path) ⇒ Object private
- #resolve_CallMethodExpression(ast, context, path) ⇒ Object private
- #resolve_LiteralDefault(_, _, _) ⇒ Object private
- #resolve_LiteralUndef(_, _, _) ⇒ Object private
- #resolve_LiteralValue(ast, _, _) ⇒ Object private
- #resolve_NamedAccessExpression(ast, context, path) ⇒ Object private
- #resolve_Object(ast, _, path) ⇒ Object private
- #resolve_QualifiedName(ast, _, _) ⇒ Object private
- #resolve_QualifiedReference(ast, _, _) ⇒ Object private
- #resolve_ReservedWord(ast, _, _) ⇒ Object private
- #resolve_VariableExpression(ast, context, path) ⇒ Object private
Constructor Details
#initialize ⇒ Resolver
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Resolver.
38 39 40 41 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 38 def initialize @parser = Parser::Parser.new @visitor = Visitor.new(nil, 'resolve', 2, 2) end |
Class Method Details
.singleton ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 34 def self.singleton @singleton ||= self.new end |
Instance Method Details
#resolve(context, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve the given path in the given context.
48 49 50 51 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 48 def resolve(context, path) factory = @parser.parse_string(path) resolve_any(factory.model.body, context, path) end |
#resolve_AccessExpression(ast, context, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 57 def resolve_AccessExpression(ast, context, path) bad_json_path(path) unless ast.keys.size == 1 receiver = resolve_any(ast.left_expr, context, path) key = resolve_any(ast.keys[0], context, path) if receiver.is_a?(Types::PuppetObject) PCORE_TYPE_KEY == key ? receiver._pcore_type : receiver.send(key) else receiver[key] end end |
#resolve_any(ast, context, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 53 def resolve_any(ast, context, path) @visitor.visit_this_2(self, ast, context, path) end |
#resolve_CallMethodExpression(ast, context, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 109 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 106 def resolve_CallMethodExpression(ast, context, path) bad_json_path(path) unless ast.arguments.empty? resolve_any(ast.functor_expr, context, path) end |
#resolve_LiteralDefault(_, _, _) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 96 def resolve_LiteralDefault(_, _, _) 'default' end |
#resolve_LiteralUndef(_, _, _) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
92 93 94 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 92 def resolve_LiteralUndef(_, _, _) 'undef' end |
#resolve_LiteralValue(ast, _, _) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
111 112 113 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 111 def resolve_LiteralValue(ast, _, _) ast.value end |
#resolve_NamedAccessExpression(ast, context, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 68 def resolve_NamedAccessExpression(ast, context, path) receiver = resolve_any(ast.left_expr, context, path) key = resolve_any(ast.right_expr, context, path) if receiver.is_a?(Types::PuppetObject) PCORE_TYPE_KEY == key ? receiver._pcore_type : receiver.send(key) else receiver[key] end end |
#resolve_Object(ast, _, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
115 116 117 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 115 def resolve_Object(ast, _, path) bad_json_path(path) end |
#resolve_QualifiedName(ast, _, _) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 81 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 78 def resolve_QualifiedName(ast, _, _) v = ast.value 'null' == v ? nil : v end |
#resolve_QualifiedReference(ast, _, _) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 83 def resolve_QualifiedReference(ast, _, _) v = ast.cased_value 'null'.casecmp(v) == 0 ? nil : v end |
#resolve_ReservedWord(ast, _, _) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 88 def resolve_ReservedWord(ast, _, _) ast.word end |
#resolve_VariableExpression(ast, context, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
100 101 102 103 104 |
# File 'lib/puppet/pops/serialization/json_path.rb', line 100 def resolve_VariableExpression(ast, context, path) # A single '$' means root, i.e. the context. bad_json_path(path) unless EMPTY_STRING == resolve_any(ast.expr, context, path) context end |