Class: CukeModeler::Gherkin2Adapter
- Inherits:
-
Object
- Object
- CukeModeler::Gherkin2Adapter
- Defined in:
- lib/cuke_modeler/adapters/gherkin_2_adapter.rb
Overview
NOT A PART OF THE PUBLIC API An adapter that can convert the output of version 2.x of the gherkin gem into input that is consumable by this gem.
Instance Method Summary collapse
-
#adapt(parsed_ast) ⇒ Object
Adapts the given AST into the shape that this gem expects.
-
#adapt_background!(parsed_background, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given background node.
-
#adapt_comment!(parsed_comment) ⇒ Object
Adapts the AST sub-tree that is rooted at the given comment node.
-
#adapt_doc_string!(parsed_doc_string) ⇒ Object
Adapts the AST sub-tree that is rooted at the given doc string node.
-
#adapt_example!(parsed_example, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given example node.
-
#adapt_feature!(parsed_feature, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given feature node.
-
#adapt_outline!(parsed_outline, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given outline node.
-
#adapt_scenario!(parsed_scenario, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given scenario node.
-
#adapt_step!(parsed_step, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given step node.
-
#adapt_step_table!(parsed_step_table, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given table node.
-
#adapt_table_row!(parsed_table_row, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given row node.
-
#adapt_tag!(parsed_tag) ⇒ Object
Adapts the AST sub-tree that is rooted at the given tag node.
-
#create_cell_for(parsed_cell, line_number) ⇒ Object
Adapts the AST sub-tree that is rooted at the given cell node.
Instance Method Details
#adapt(parsed_ast) ⇒ Object
Adapts the given AST into the shape that this gem expects
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 9 def adapt(parsed_ast) parsed_data = {} # The entire AST is just an array with one feature and we don't want to save any child data so...an empty array parsed_data['cuke_modeler_parsing_data'] = [] # Comments are stored on child elements in gherkin 2.x comments = [] # An AST is just one feature adapt_feature!(parsed_ast.first, comments) if parsed_ast.first parsed_data['feature'] = parsed_ast.first # Adapt and store comments once they have all been gathered comments.each do |comment| adapt_comment!(comment) end parsed_data['comments'] = comments [parsed_data] end |
#adapt_background!(parsed_background, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given background node.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 56 def adapt_background!(parsed_background, gathered_comments) # Saving off the original data parsed_background['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_background)) # Removing parsed data for child elements in order to avoid duplicating data parsed_background['cuke_modeler_parsing_data']['steps'] = nil if parsed_background['comments'] parsed_background['cuke_modeler_parsing_data']['comments'] = nil gathered_comments.concat(parsed_background['comments']) end if parsed_background['steps'] parsed_background['steps'].each do |step| adapt_step!(step, gathered_comments) end end end |
#adapt_comment!(parsed_comment) ⇒ Object
Adapts the AST sub-tree that is rooted at the given comment node.
168 169 170 171 172 173 174 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 168 def adapt_comment!(parsed_comment) # Saving off the original data parsed_comment['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_comment)) parsed_comment['text'] = parsed_comment.delete('value') parsed_comment['line'] = parsed_comment.delete('line') end |
#adapt_doc_string!(parsed_doc_string) ⇒ Object
Adapts the AST sub-tree that is rooted at the given doc string node.
199 200 201 202 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 199 def adapt_doc_string!(parsed_doc_string) # Saving off the original data parsed_doc_string['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_doc_string)) end |
#adapt_example!(parsed_example, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given example node.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 137 def adapt_example!(parsed_example, gathered_comments) # Saving off the original data parsed_example['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_example)) # Removing parsed data for child elements in order to avoid duplicating data parsed_example['cuke_modeler_parsing_data']['tags'] = nil parsed_example['cuke_modeler_parsing_data']['rows'] = nil if parsed_example['comments'] parsed_example['cuke_modeler_parsing_data']['comments'] = nil gathered_comments.concat(parsed_example['comments']) end parsed_example['rows'].each do |row| adapt_table_row!(row, gathered_comments) end if parsed_example['tags'] parsed_example['tags'].each do |tag| adapt_tag!(tag) end end end |
#adapt_feature!(parsed_feature, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given feature node.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 33 def adapt_feature!(parsed_feature, gathered_comments) # Saving off the original data parsed_feature['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_feature)) # Removing parsed data for child elements in order to avoid duplicating data parsed_feature['cuke_modeler_parsing_data']['tags'] = nil parsed_feature['cuke_modeler_parsing_data']['elements'] = nil if parsed_feature['comments'] parsed_feature['cuke_modeler_parsing_data']['comments'] = nil gathered_comments.concat(parsed_feature['comments']) end adapt_child_elements!(parsed_feature, gathered_comments) if parsed_feature['tags'] parsed_feature['tags'].each do |tag| adapt_tag!(tag) end end end |
#adapt_outline!(parsed_outline, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given outline node.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 103 def adapt_outline!(parsed_outline, gathered_comments) # Saving off the original data parsed_outline['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_outline)) # Removing parsed data for child elements in order to avoid duplicating data parsed_outline['cuke_modeler_parsing_data']['tags'] = nil parsed_outline['cuke_modeler_parsing_data']['steps'] = nil parsed_outline['cuke_modeler_parsing_data']['examples'] = nil if parsed_outline['comments'] parsed_outline['cuke_modeler_parsing_data']['comments'] = nil gathered_comments.concat(parsed_outline['comments']) end if parsed_outline['tags'] parsed_outline['tags'].each do |tag| adapt_tag!(tag) end end if parsed_outline['steps'] parsed_outline['steps'].each do |step| adapt_step!(step, gathered_comments) end end if parsed_outline['examples'] parsed_outline['examples'].each do |example| adapt_example!(example, gathered_comments) end end end |
#adapt_scenario!(parsed_scenario, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given scenario node.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 76 def adapt_scenario!(parsed_scenario, gathered_comments) # Saving off the original data parsed_scenario['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_scenario)) # Removing parsed data for child elements in order to avoid duplicating data parsed_scenario['cuke_modeler_parsing_data']['tags'] = nil parsed_scenario['cuke_modeler_parsing_data']['steps'] = nil if parsed_scenario['comments'] parsed_scenario['cuke_modeler_parsing_data']['comments'] = nil gathered_comments.concat(parsed_scenario['comments']) end if parsed_scenario['tags'] parsed_scenario['tags'].each do |tag| adapt_tag!(tag) end end if parsed_scenario['steps'] parsed_scenario['steps'].each do |step| adapt_step!(step, gathered_comments) end end end |
#adapt_step!(parsed_step, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given step node.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 177 def adapt_step!(parsed_step, gathered_comments) # Saving off the original data parsed_step['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step)) # Removing parsed data for child elements in order to avoid duplicating data parsed_step['cuke_modeler_parsing_data']['rows'] = nil if parsed_step['cuke_modeler_parsing_data']['rows'] parsed_step['cuke_modeler_parsing_data']['doc_string'] = nil if parsed_step['cuke_modeler_parsing_data']['doc_string'] if parsed_step['comments'] parsed_step['cuke_modeler_parsing_data']['comments'] = nil gathered_comments.concat(parsed_step['comments']) end adapt_doc_string!(parsed_step['doc_string']) if parsed_step['doc_string'] if parsed_step['rows'] parsed_step['table'] = {'rows' => parsed_step['rows']} adapt_step_table!(parsed_step['table'], gathered_comments) end end |
#adapt_step_table!(parsed_step_table, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given table node.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 205 def adapt_step_table!(parsed_step_table, gathered_comments) # Saving off the original data parsed_step_table['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step_table['rows'])) # Removing parsed data for child elements in order to avoid duplicating data parsed_step_table['cuke_modeler_parsing_data'].clear parsed_step_table['line'] = parsed_step_table['rows'].first['line'] parsed_step_table['rows'].each do |row| adapt_table_row!(row, gathered_comments) end end |
#adapt_table_row!(parsed_table_row, gathered_comments) ⇒ Object
Adapts the AST sub-tree that is rooted at the given row node.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 221 def adapt_table_row!(parsed_table_row, gathered_comments) # Saving off the original data parsed_table_row['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_table_row)) # Removing parsed data for child elements in order to avoid duplicating data which the child elements will themselves include parsed_table_row['cuke_modeler_parsing_data']['cells'] = nil if parsed_table_row['comments'] parsed_table_row['cuke_modeler_parsing_data']['comments'] = nil gathered_comments.concat(parsed_table_row['comments']) end parsed_table_row['cells'].collect! do |cell| create_cell_for(cell, parsed_table_row['line']) end end |
#adapt_tag!(parsed_tag) ⇒ Object
Adapts the AST sub-tree that is rooted at the given tag node.
162 163 164 165 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 162 def adapt_tag!(parsed_tag) # Saving off the original data parsed_tag['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_tag)) end |
#create_cell_for(parsed_cell, line_number) ⇒ Object
Adapts the AST sub-tree that is rooted at the given cell node.
239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/cuke_modeler/adapters/gherkin_2_adapter.rb', line 239 def create_cell_for(parsed_cell, line_number) cell = {} # Saving off the original data cell['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_cell)) cell['value'] = parsed_cell cell['line'] = line_number cell end |