Class: Retrospec::Puppet::SchemaDumper
- Inherits:
-
Puppet::Pops::Model::TreeDumper
- Object
- Puppet::Pops::Model::TreeDumper
- Retrospec::Puppet::SchemaDumper
- Defined in:
- lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb
Instance Method Summary collapse
- #do_dump(o) ⇒ Object
- #dump(o) ⇒ Object
-
#dump_AccessExpression(o) ⇒ Object
x prints as (slice x y).
- #dump_AndExpression(o) ⇒ Object
- #dump_Application(o) ⇒ Object
- #dump_ArithmeticExpression(o) ⇒ Object
- #dump_Array(o) ⇒ Object
- #dump_AssignmentExpression(o) ⇒ Object
-
#dump_AttributeOperation(o) ⇒ Object
Produces (name => expr) or (name +> expr).
- #dump_AttributesOperation(o) ⇒ Object
- #dump_BlockExpression(o) ⇒ Object
- #dump_CollectExpression(o) ⇒ Object
- #dump_ComparisonExpression(o) ⇒ Object
-
#dump_ConcatenatedString(o) ⇒ Object
Interpolated strings are shown as (cat seg0 seg1 … segN).
- #dump_EppExpression(o) ⇒ Object
- #dump_ExportedQuery(o) ⇒ Object
- #dump_Expression(o) ⇒ Object
- #dump_InExpression(o) ⇒ Object
- #dump_KeyedEntry(o) ⇒ Object
- #dump_LambdaExpression(o) ⇒ Object
- #dump_LiteralBoolean(o) ⇒ Object
- #dump_LiteralDefault(o) ⇒ Object
- #dump_LiteralFloat(o) ⇒ Object
- #dump_LiteralHash(o) ⇒ Object
- #dump_LiteralInteger(o) ⇒ Object
- #dump_LiteralList(o) ⇒ Object
- #dump_LiteralRegularExpression(o) ⇒ Object
- #dump_LiteralString(o) ⇒ Object
- #dump_LiteralUndef(o) ⇒ Object
- #dump_LiteralValue(o) ⇒ Object
- #dump_MatchesExpression(o) ⇒ Object
- #dump_MatchExpression(o) ⇒ Object
- #dump_NamedAccessExpression(o) ⇒ Object
- #dump_NilClass(o) ⇒ Object
- #dump_Nop(o) ⇒ Object
- #dump_NotExpression(o) ⇒ Object
- #dump_Object(o) ⇒ Object
- #dump_OrExpression(o) ⇒ Object
-
#dump_Parameter(o) ⇒ Object
Produces parameters as name, or (= name value).
- #dump_QualifiedName(o) ⇒ Object
- #dump_QueryExpression(o) ⇒ Object
- #dump_ReservedWord(o) ⇒ Object
-
#dump_TextExpression(o) ⇒ Object
Interpolation (to string) shown as (str expr).
- #dump_UnaryMinusExpression(o) ⇒ Object
- #dump_UnfoldExpression(o) ⇒ Object
- #dump_VariableExpression(o) ⇒ Object
- #dump_VirtualQuery(o) ⇒ Object
- #indent ⇒ Object
- #is_nop?(o) ⇒ Boolean
-
#to_kwalify_type(value) ⇒ Object
convert the given class to a kwalify class, defaults to any.
-
#type_table ⇒ Object
conversion table from ruby types to kwalify types.
Instance Method Details
#do_dump(o) ⇒ Object
44 45 46 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 44 def do_dump(o) @@dump_visitor.visit_this_0(self, o) end |
#dump(o) ⇒ Object
40 41 42 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 40 def dump(o) do_dump(o) end |
#dump_AccessExpression(o) ⇒ Object
x prints as (slice x y)
99 100 101 102 103 104 105 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 99 def dump_AccessExpression o if o.keys.size <= 1 ["slice", do_dump(o.left_expr), do_dump(o.keys[0])] else ["slice", do_dump(o.left_expr), do_dump(o.keys)] end end |
#dump_AndExpression(o) ⇒ Object
151 152 153 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 151 def dump_AndExpression o ["&&", do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_Application(o) ⇒ Object
90 91 92 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 90 def dump_Application o ["application", o.name, do_dump(o.parameters), do_dump(o.body)] end |
#dump_ArithmeticExpression(o) ⇒ Object
94 95 96 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 94 def dump_ArithmeticExpression o [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_Array(o) ⇒ Object
48 49 50 51 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 48 def dump_Array o 'seq' #o.collect {|e| do_dump(e) } end |
#dump_AssignmentExpression(o) ⇒ Object
163 164 165 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 163 def dump_AssignmentExpression o [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_AttributeOperation(o) ⇒ Object
Produces (name => expr) or (name +> expr)
168 169 170 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 168 def dump_AttributeOperation o [o.attribute_name, o.operator, do_dump(o.value_expr)] end |
#dump_AttributesOperation(o) ⇒ Object
172 173 174 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 172 def dump_AttributesOperation o ['* =>', do_dump(o.expr)] end |
#dump_BlockExpression(o) ⇒ Object
255 256 257 258 259 260 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 255 def dump_BlockExpression o result = ["block", :indent] o.statements.each {|x| result << :break; result << do_dump(x) } result << :dedent << :break result end |
#dump_CollectExpression(o) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 111 def dump_CollectExpression o result = ["collect", do_dump(o.type_expr), :indent, :break, do_dump(o.query), :indent] o.operations do |ao| result << :break << do_dump(ao) end result += [:dedent, :dedent ] result end |
#dump_ComparisonExpression(o) ⇒ Object
147 148 149 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 147 def dump_ComparisonExpression o [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_ConcatenatedString(o) ⇒ Object
Interpolated strings are shown as (cat seg0 seg1 … segN)
263 264 265 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 263 def dump_ConcatenatedString o ["cat"] + o.segments.collect {|x| do_dump(x)} end |
#dump_EppExpression(o) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 120 def dump_EppExpression o result = ["epp"] # result << ["parameters"] + o.parameters.collect {|p| do_dump(p) } if o.parameters.size() > 0 if o.body result << do_dump(o.body) else result << [] end result end |
#dump_ExportedQuery(o) ⇒ Object
131 132 133 134 135 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 131 def dump_ExportedQuery o result = ["<<| |>>"] result += dump_QueryExpression(o) unless is_nop?(o.expr) result end |
#dump_Expression(o) ⇒ Object
86 87 88 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 86 def dump_Expression o do_dump(o.value) end |
#dump_InExpression(o) ⇒ Object
159 160 161 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 159 def dump_InExpression o ["in", do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_KeyedEntry(o) ⇒ Object
186 187 188 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 186 def dump_KeyedEntry o [do_dump(o.key), do_dump(o.value)] end |
#dump_LambdaExpression(o) ⇒ Object
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 199 def dump_LambdaExpression o result = ["lambda"] result << ["parameters"] + o.parameters.collect {|p| do_dump(p) } if o.parameters.size > 0 if o.body result << do_dump(o.body) else result << [] end result end |
#dump_LiteralBoolean(o) ⇒ Object
78 79 80 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 78 def dump_LiteralBoolean o 'bool' end |
#dump_LiteralDefault(o) ⇒ Object
210 211 212 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 210 def dump_LiteralDefault o ":default" end |
#dump_LiteralFloat(o) ⇒ Object
70 71 72 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 70 def dump_LiteralFloat o 'float' end |
#dump_LiteralHash(o) ⇒ Object
181 182 183 184 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 181 def dump_LiteralHash o 'map' #["{}"] + o.entries.collect {|x| do_dump(x)} end |
#dump_LiteralInteger(o) ⇒ Object
74 75 76 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 74 def dump_LiteralInteger o 'int' end |
#dump_LiteralList(o) ⇒ Object
176 177 178 179 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 176 def dump_LiteralList o 'seq' #["[]"] + o.values.collect {|x| do_dump(x)} end |
#dump_LiteralRegularExpression(o) ⇒ Object
218 219 220 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 218 def dump_LiteralRegularExpression o "/#{o.value.source}/" end |
#dump_LiteralString(o) ⇒ Object
194 195 196 197 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 194 def dump_LiteralString o 'str' #"'#{o.value}'" end |
#dump_LiteralUndef(o) ⇒ Object
214 215 216 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 214 def dump_LiteralUndef o ":undef" end |
#dump_LiteralValue(o) ⇒ Object
82 83 84 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 82 def dump_LiteralValue o type_table[o.class.to_s] || 'any' end |
#dump_MatchesExpression(o) ⇒ Object
107 108 109 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 107 def dump_MatchesExpression o [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_MatchExpression(o) ⇒ Object
190 191 192 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 190 def dump_MatchExpression o [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_NamedAccessExpression(o) ⇒ Object
226 227 228 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 226 def dump_NamedAccessExpression o [".", do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_NilClass(o) ⇒ Object
230 231 232 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 230 def dump_NilClass o 'any' end |
#dump_Nop(o) ⇒ Object
222 223 224 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 222 def dump_Nop o ":nop" end |
#dump_NotExpression(o) ⇒ Object
234 235 236 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 234 def dump_NotExpression o ['!', dump(o.expr)] end |
#dump_Object(o) ⇒ Object
36 37 38 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 36 def dump_Object o [o.class.to_s, o.to_s] end |
#dump_OrExpression(o) ⇒ Object
155 156 157 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 155 def dump_OrExpression o ["||", do_dump(o.left_expr), do_dump(o.right_expr)] end |
#dump_Parameter(o) ⇒ Object
Produces parameters as name, or (= name value)
272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 272 def dump_Parameter o name_prefix = o.captures_rest ? '*' : '' name_part = "#{name_prefix}#{o.name}" if o.value && o.type_expr {:type => do_dump(o.type_expr), :name => name_part, :default_value => do_dump(o.value)} elsif o.value {:type => nil, :name => name_part, :default_value => do_dump(o.value)} elsif o.type_expr {:type => do_dump(o.type_expr), :name => name_part, :default_value => nil} else {:type => nil, :name => name_part, :default_value => nil} end end |
#dump_QualifiedName(o) ⇒ Object
66 67 68 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 66 def dump_QualifiedName o 'any' # return any until we can lookup the value of this variable name end |
#dump_QueryExpression(o) ⇒ Object
143 144 145 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 143 def dump_QueryExpression o [do_dump(o.expr)] end |
#dump_ReservedWord(o) ⇒ Object
267 268 269 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 267 def dump_ReservedWord o [ 'reserved', o.word ] end |
#dump_TextExpression(o) ⇒ Object
Interpolation (to string) shown as (str expr)
243 244 245 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 243 def dump_TextExpression o ["str", do_dump(o.expr)] end |
#dump_UnaryMinusExpression(o) ⇒ Object
247 248 249 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 247 def dump_UnaryMinusExpression o ['-', do_dump(o.expr)] end |
#dump_UnfoldExpression(o) ⇒ Object
251 252 253 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 251 def dump_UnfoldExpression o ['unfold', do_dump(o.expr)] end |
#dump_VariableExpression(o) ⇒ Object
238 239 240 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 238 def dump_VariableExpression o do_dump(o.expr) end |
#dump_VirtualQuery(o) ⇒ Object
137 138 139 140 141 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 137 def dump_VirtualQuery o result = ["<| |>"] result += dump_QueryExpression(o) unless is_nop?(o.expr) result end |
#indent ⇒ Object
53 54 55 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 53 def indent " " * indent_count end |
#is_nop?(o) ⇒ Boolean
286 287 288 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 286 def is_nop? o o.nil? || o.is_a?(Puppet::Pops::Model::Nop) end |
#to_kwalify_type(value) ⇒ Object
convert the given class to a kwalify class, defaults to any
58 59 60 61 62 63 64 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 58 def to_kwalify_type(value) if x = dump(value) x else 'any' end end |
#type_table ⇒ Object
conversion table from ruby types to kwalify types
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb', line 11 def type_table @type_table ||= { 'Array'=>"seq", 'Hash'=>"map", 'string' => 'str', 'String'=>"str", 'Integer'=>"int", 'Float'=>"float", 'Numeric'=>"number", 'Date'=>"date", 'Time'=>"timestamp", 'Object'=>"any", 'FalseClass' => 'bool', 'TrueClass' => 'bool', 'Fixnum' => 'number', 'NilClass' => 'any', 'Puppet::Pops::Model::LiteralBoolean' => 'bool', 'Puppet::Parser::AST::Variable' => 'any', 'Puppet::Parser::AST::Boolean' => 'bool', 'Puppet::Parser::AST::String' => 'str', 'Puppet::Parser::AST::ASTHash' => 'map', 'Puppet::Parser::AST::ASTArray' => 'seq', } end |