Class: Generators::TDriverBehaviourGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TDriverBehaviourGenerator

Returns a new instance of TDriverBehaviourGenerator.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 26

def initialize( options )

  @templates = {}

  @found_modules_and_methods = {}

  @created_files = {}

  load_templates

  @options = options

  @already_processed_files = []

  @current_module_tests = []

  @current_module = nil

  @output = { :files => [], :classes => [], :modules => [], :attributes => [], :methods => [], :aliases => [], :constants => [], :requires => [], :includes => []}

  @errors = []

end

Class Method Details

.for(options) ⇒ Object



394
395
396
397
398
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 394

def self.for( options )

  new( options )

end

Instance Method Details

#apply_macros!(source, macros) ⇒ Object



1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1290

def apply_macros!( source, macros )
    
  macros.each_pair{ | key, value |

    while result = /(\$#{ key }\b)/.match( source )

      source = source[0..result.begin(0)-1] + value.to_s + source[result.end(0)..-1]

    end
  
  }
  
  source

end

#encode_string(string) ⇒ Object



1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1186

def encode_string( string )

  return "" if string.nil? 

  result = "%s" % string

  result.gsub!( /\&/, '&' )
  result.gsub!( /\</, '&lt;' )
  result.gsub!( /\>/, '&gt;' )
  result.gsub!( /\"/, '&quot;' )
  result.gsub!( /\'/, '&apos;' )

  result

end

#generate(files) ⇒ Object



412
413
414
415
416
417
418
419
420
421
422
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 412

def generate( files )

  # process files
  files.each{ | file |
    
    process_file( file ) unless @already_processed_files.include?( file.file_absolute_name )


  }

end

#generate_arguments_element(header, feature) ⇒ Object



1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1420

def generate_arguments_element( header, feature )

  return "" if ( feature.last[:__type] == 'reader' )

  argument_types = { "*" => "multi", "&" => "block" }
  argument_types.default = "normal"

  #return "" if ( @processing == :attributes && feature.last[:__type] == 'R' )

  feature.last[ :__type ]

  if feature.last[ :arguments ].nil? and feature.last[ :__arguments_found ] > 0

    note = ". Note that also attribute writer requires input value defined as argument." if [ 'writer', 'accessor' ].include?( @processing )

    raise_error("Error: $TYPE '#{ feature.first }' ($MODULE) doesn't have arguments(s) defined#{ note }", [ 'writer', 'accessor' ].include?( @processing ) ? 'attr_argument' : 'arguments' )

  end

  # generate arguments xml
  arguments = ( feature.last[:arguments] || {} ).collect{ | arg |

  #p arg
            
    # generate argument types template
    arg.collect{ | argument |

     argument_type = argument_types[ argument.first[0].chr ]

     argument_name = "%s" % argument.first          

     argument_name[0]="" if argument_types.has_key?( argument_name[0].chr )

     argument_type = "block_argument" if argument_type == "block" && argument_name.include?( "#" )          

     default_value_set = false 

     default_value = nil
    
     if argument.last.has_key?( :argument_type_order )

       argument_types_in_order = argument.last[:argument_type_order].collect{ | type |                      
        [ type, argument.last[:types][ type ] ]           
       }

     else         

       argument_types_in_order = argument.last[ :types ]

     end

     argument_types_in_order ||= []

     # in case of argument is not documented at all...
     if argument_types_in_order.empty?

       # set optional flag if default value given
       unless argument.last[:default].nil?

         default_value = argument.last[:default]
         default_value_set = true

       end

     end

     if argument_types_in_order.empty?

      default_value = nil
      default_value_set = false

      argument_types_in_order = [[nil, {}]]
     
     end

     types_xml = argument_types_in_order.collect{ | type |

       unless argument.last[:default].nil?

         # show warning if default value for optional argument is already set
         #raise_error( "Error: Default value for optional argument '%s' ($MODULE) is already set! ('%s' --> '%s')" % [ argument.first, default_value, type.last["default"] ] ) if default_value_set == true

         default_value = argument.last[:default]
         default_value_set = true

       end

=begin
       unless type.last["default"].nil?

         # show warning if default value for optional argument is already set
         #raise_error( "Error: Default value for optional argument '%s' ($MODULE) is already set! ('%s' --> '%s')" % [ argument.first, default_value, type.last["default"] ] ) if default_value_set == true


         default_value = type.last["default"]
         default_value_set = true

       end
=end

       if type.last["description"].nil?

        raise_error("Warning: Argument description for '%s' ($MODULE) is empty." % [ argument.first ], 'argument' )

       end

       if type.last["example"].nil?

        raise_error("Warning: Argument '%s' ($MODULE) example is empty." % [ argument.first ])

       end

       apply_macros!( @templates["behaviour.xml.argument_type"].clone, {
        
          "ARGUMENT_TYPE" => encode_string( argument_type == 'block' ? "Proc" : type.first ),
          "ARGUMENT_DESCRIPTION" => encode_string( type.last["description"] ),
          "ARGUMENT_EXAMPLE" => encode_string( type.last["example"] ),
       
        }
       )
     
     }.join

    if argument_type == "multi"
    
      default_value = "[]"
      default_value_set = true
    
    end
     
    if default_value_set

      default_value = apply_macros!( @templates["behaviour.xml.argument.default"].clone, { 
        "ARGUMENT_DEFAULT_VALUE" => encode_string( default_value || "" )
        }
      )

    else

      default_value = ""

    end

     # apply types to arguments template
     apply_macros!( @templates["behaviour.xml.argument"].clone, {
        "ARGUMENT_NAME" => encode_string( argument_name ),
        "ARGUMENT_TYPE" => encode_string( argument_type ),
        "ARGUMENT_TYPES" => types_xml,
        "ARGUMENT_DEFAULT_VALUE" => default_value.to_s,
        "ARGUMENT_OPTIONAL" => encode_string( ["multi", "block", "block_argument"].include?( argument_type ) ? "true" : default_value_set.to_s )
      }
     )
    
    }.join
  
  }.join

  apply_macros!( @templates["behaviour.xml.method.arguments"].clone, {

      "ARGUMENTS_IMPLEMENTED" => feature.last[ :__arguments_implemented ] || "0",
      "ARGUMENT_OPTIONAL_COUNT" => feature.last[ :__arguments_optional ] || "0",
      "METHOD_ARGUMENTS" => arguments

    }
  )


end

#generate_behaviour(header, *features) ⇒ Object



1838
1839
1840
1841
1842
1843
1844
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1838

def generate_behaviour( header, *features )

  methods = generate_methods_element( header, features )

  generate_behaviour_element( header, methods )

end

#generate_behaviour_element(header, methods) ⇒ Object



1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1765

def generate_behaviour_element( header, methods )

  # verify that behaviour description is defined
  unless header.has_key?(:description)

     raise_error("Warning: Behaviour description for $MODULE is empty.", 'behaviour_description' ) unless methods.empty?

  end

  # verify that behaviour name is defined
  unless header.has_key?(:behaviour)

     raise_error("Warning: Behaviour name for $MODULE is not defined.", 'behaviour_name' ) unless methods.empty?

  end

  # verify that behaviour object type(s) is defined
  unless header.has_key?(:objects)

     raise_error("Warning: Behaviour object type(s) for $MODULE is not defined.", 'behaviour_object_types' ) unless methods.empty?

  end

  # verify that behaviour sut type(s) is defined
  unless header.has_key?(:sut_type)

     raise_error("Warning: Behaviour SUT type for $MODULE is not defined.", 'behaviour_sut_type' ) unless methods.empty?

  end

  # verify that behaviour input type(s) is defined
  unless header.has_key?(:input_type)

     raise_error("Warning: Behaviour input type for $MODULE is not defined.", 'behaviour_input_type' ) unless methods.empty?

  end

  # verify that behaviour sut version(s) is defined
  unless header.has_key?(:sut_version)

     raise_error("Warning: Behaviour SUT version for $MODULE is not defined.", 'behaviour_version' ) unless methods.empty?

  end

  # verify that behaviour sut version(s) is defined
  unless header.has_key?(:requires)

     raise_error("Warning: Required plugin name is not defined for $MODULE.", 'behaviour_requires' ) unless methods.empty?

  end

  # apply header
  text = apply_macros!( @templates["behaviour.xml"].clone, { 
    "REQUIRED_PLUGIN" => encode_string( header[:requires] ),
    "BEHAVIOUR_NAME" => encode_string( header[:behaviour] ),
    "BEHAVIOUR_METHODS" => methods,
    "OBJECT_TYPE" => encode_string( header[:objects] ),
    "SUT_TYPE" => encode_string( header[:sut_type] ),
    "INPUT_TYPE" => encode_string( header[:input_type] ),
    "VERSION" => encode_string( header[:sut_version] ),
    "MODULE_NAME" => encode_string( @module_path.join("::") )
    } 
  )    

  # remove extra linefeeds
  text.gsub!( /^[\n]+/, "\n" )

  text.gsub!( /^(\s)*$/, "" )

  text

end

#generate_deprecated_element(header, feature, &block) ⇒ Object



1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1673

def generate_deprecated_element( header, feature, &block )

  if feature.last.has_key?( :deprecated )

    yield

    apply_macros!( @templates["behaviour.xml.method.deprecated"].clone, {
        "DEPRECATED_IN_VERSION_NUMBER" => encode_string( feature.last[:deprecated] )
      }
    )

  else

    ""

  end

end

#generate_exceptions_element(header, feature) ⇒ Object



1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1373

def generate_exceptions_element( header, feature )

  return "" if ( feature.last[:__type] != 'method' )

  #if feature.last[ :exceptions ].nil?
  #  raise_error("Error: $TYPE '#{ feature.first }' ($MODULE) doesn't have exceptions(s) defined", 'exceptions' )
  #end

  return "" if feature.last[ :exceptions ].nil? || feature.last[ :exceptions ].empty?

  count = 0

  # generate exceptions template
  exceptions = feature.last[ :exceptions ].collect{ | exceptions |
  
    exceptions.collect{ | exception |
    
       count += 1

       # apply types to exception template
       apply_macros!( @templates["behaviour.xml.exception"].clone, {
          "EXCEPTION_NAME" => encode_string( exception.first ),
          "EXCEPTION_DESCRIPTION" => encode_string( exception.last["description"] )
        }
       )
      
    }.join
 
  }.join

  if count > 0

    apply_macros!( @templates["behaviour.xml.method.exceptions"].clone, {

        "METHOD_EXCEPTIONS" => exceptions

      }
    )

  else

   ""

  end

end

#generate_info_element(header, feature) ⇒ Object



1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1692

def generate_info_element( header, feature )

  if feature.last.has_key?( :info )

    apply_macros!( @templates["behaviour.xml.method.info"].clone, {
        "METHOD_INFO" => encode_string( feature.last[:info] )
      }
    )

  else

    ""

  end

end

#generate_methods_element(header, features) ⇒ Object



1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1709

def generate_methods_element( header, features )

  # collect method and attribute templates
  methods = features.collect{ | feature_set |
  
    feature_set.collect{ | feature |
              
      @processing = feature.last[:__type]
                  
      arguments = generate_arguments_element( header, feature )

      returns = generate_return_values_element( header, feature )

      exceptions = generate_exceptions_element( header, feature )
                
      tables = generate_tables_element( header, feature )

      info = generate_info_element( header, feature )
                
      deprecated = generate_deprecated_element( header, feature ){
        
        arguments = ""
        returns = ""
        exceptions = ""
        tables = ""

      }

      if feature.last[:description].nil?

       raise_error("Warning: $TYPE description for '#{ feature.first }' ($MODULE) is empty.", 'description')

      end
                          
      # generate method template            
      apply_macros!( @templates["behaviour.xml.method"].clone, { 
        "METHOD_NAME" => encode_string( feature.first ),
        "METHOD_TYPE" => encode_string( feature.last[:__type] || "unknown" ),
        "NODOC" => feature.last.has_key?(:nodoc).to_s,
        "METHOD_DEPRECATED" => deprecated,
        "METHOD_DESCRIPTION" => encode_string( feature.last[:description] ),
        "METHOD_ARGUMENTS" => arguments,
        "METHOD_RETURNS" => returns,
        "METHOD_EXCEPTIONS" => exceptions,
        "METHOD_TABLES" => tables,
        "METHOD_INFO" => info # feature.last[:info]
       } 
      )

    }.join
  
  }.join


end

#generate_return_values_element(header, feature) ⇒ Object



1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1323

def generate_return_values_element( header, feature )

  return "" if ( [ 'writer' ].include?( feature.last[ :__type ] ) )

  return if feature.last[ :returns ].nil? || feature.last[ :returns ].empty?

  if feature.last[ :returns ].nil?

    raise_error("Error: $TYPE '#{ feature.first }' ($MODULE) doesn't have return value type(s) defined", 'returns' )

  end

  count = 0

  # generate return value types template
  returns = feature.last[ :returns ].collect{ | return_types |
        
    return_types.collect{ | returns |
    
       count += 1

       # apply types to returns template
       apply_macros!( @templates["behaviour.xml.returns"].clone, {
          "RETURN_VALUE_TYPE" => encode_string( returns.first ),
          "RETURN_VALUE_DESCRIPTION" => encode_string( returns.last["description"] ),
          "RETURN_VALUE_EXAMPLE" => encode_string( returns.last["example"] ),
        }
       )
      
    }.join
 
  }.join

  if count > 0

    apply_macros!( @templates["behaviour.xml.method.returns"].clone, {

        "METHOD_RETURNS" => returns

      }
    )

  else

    ""

  end
  
end

#generate_tables_element(header, features) ⇒ Object



1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1589

def generate_tables_element( header, features )

  tables = []

  unless features.last[:tables].nil? #[:tables]

    #p features.last[:tables]
    #p features.last[:tables]["content"]

    #return "" if features.last[:tables]["content"] == []
    
    tables = features.last[:tables].collect{ | table |
  
      if table["content"] == []

        raise_error("Warning: Table format incorrect in '#{ features.first }' ($MODULE)", 'table_format')

        apply_macros!( @templates["behaviour.xml.table"].clone, {
            "TABLE_NAME" => encode_string( '[!!] ERROR' ),
            "TABLE_TITLE" => encode_string( '[!!] ERROR' || "" ),
            "TABLE_DESCRIPTION" => encode_string( '[!!] ERROR' || "" )
          }
        )

      else          

        header = table[ "content" ].first.collect{ | header_item |
          apply_macros!( @templates["behaviour.xml.table.item"].clone, {
              "ITEM" => encode_string( header_item )
            }
          )
        }

        rows = table[ "content" ][ 1 .. -1 ].collect{ | row |

          row_items = row.collect{ | row_item |
          
            apply_macros!( @templates["behaviour.xml.table.item"].clone, {
                "ITEM" => encode_string( row_item )
              }
            )
          }

          apply_macros!( @templates["behaviour.xml.table.row"].clone, {

            "TABLE_ROW_ITEMS" => row_items.join("") 
          
            }
          )
                      
        }

        apply_macros!( @templates["behaviour.xml.table"].clone, {
            "TABLE_NAME" => encode_string( table[ "name" ] ),
            "TABLE_TITLE" => encode_string( table[ "title" ] || "" ),
            "TABLE_DESCRIPTION" => encode_string( table[ "description" ] || "" ),
            "TABLE_HEADER_ITEMS" => header.join(""),
            "TABLE_ROWS" => rows.join("")
          }
        )

      end

    }

  end

  if tables.count > 0

    apply_macros!( @templates["behaviour.xml.method.tables"].clone, {

        "METHOD_TABLES" => tables.join("")

      }
    )

  else

    ""

  end

end

#has_method?(target, method_name) ⇒ Boolean

verify if

Returns:

  • (Boolean)


1176
1177
1178
1179
1180
1181
1182
1183
1184
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1176

def has_method?( target, method_name )

    target.method_list.select{ | method | 
    
      method.name == method_name 
      
    }.count > 0

end

#help(topic) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
101
102
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 50

def help( topic )

  case topic

    when 'description'
<<-EXAMPLE
# == description
# This method returns "String" as return value
def my_method( arguments )
 return "string"
end
EXAMPLE

    when 'returns'
<<-EXAMPLE
# == returns
# String
#  description: example description
#  example: "string"
# 
def my_method( arguments )
 return "string"
end
EXAMPLE

    when 'arguments'
<<-EXAMPLE
# == arguments
# arg1
#  Integer
#   description: first argument can integer
#   example: 10
#  String
#   description: ... or string
#   example: "Hello"
#
# arg2
#  Array
#   description: MyArray
#   example: [1,2,3]
#   default: []
#
# *arg3
#  Array
#   description: MyMultipleArray
#   example: ['a','b','c']
#   default: []
#
# &block
#  Proc
#   description: MyMultipleArray
#   example: ['a','b','c']
#   default: []
def my_method( arg1, arg2, *arg3, &block )
  # ...
end
EXAMPLE

    when 'attr_argument'
<<-EXAMPLE
# == arguments
# value
#  Integer
#   description: first argument can integer
#   example: 10
attr_writer :my_attribute

or

# == arguments
# value
#  Integer
#   description: first argument can integer
#   example: 10
#  String
#   description: ... or string
#   example: "Hello"
attr_writer :my_attribute # ... when input value can be either Integer or String
EXAMPLE


    when 'exceptions'
<<-EXAMPLE
# == exceptions
# RuntimeError
#  description:  example exception #1
#
# ArgumentError
#  description:  example exception #2
def my_method

  # ...

end
EXAMPLE

    when 'behaviour_description'
<<-EXAMPLE
# == description
# This module contains demonstration implementation containing tags for documentation generation using gesture as an example
module MyBehaviour

  # ...

end
EXAMPLE

    when 'behaviour_name'
<<-EXAMPLE
# == behaviour
# MyPlatformSpecificBehaviour
module MyBehaviour

  # ...

end
EXAMPLE

    when 'behaviour_object_types'
<<-EXAMPLE
# == objects
# *
module MyBehaviour

  # apply behaviour to any test object, except SUT

end    

or

# == objects
# sut
module MyBehaviour

  # apply behaviour only to SUT object

end    

# == objects
# *;sut
module MyBehaviour

  # apply behaviour to any test object, including SUT

end    

or

# == objects
# MyObject
module MyBehaviour

  # apply behaviour only to objects which type is 'MyObject'

end    

or 

# == objects
# MyObject;OtherObject
module MyBehaviour

  # apply behaviour only to objects which type is 'MyObject' or 'OtherObject'
  # if more object types needed use ';' as separator.

end


EXAMPLE

    when 'behaviour_version'
<<-EXAMPLE
# == sut_version
# *
module MyBehaviour

  # any sut version 

end

or 

# == sut_version
# 1.0
module MyBehaviour

  # apply behaviour only to sut with version 1.0

end
EXAMPLE

    when 'behaviour_input_type'
<<-EXAMPLE
# == input_type
# *
module MyBehaviour

  # any input type 

end

or 

# == input_type
# touch
module MyBehaviour

  # apply behaviour only to sut which input type is 'touch'

end

or

# == input_type
# touch;key
module MyBehaviour

  # apply behaviour only to sut which input type is 'touch' or 'key'
  # if more types needed use ';' as separator.

end

EXAMPLE

    when 'behaviour_sut_type'
<<-EXAMPLE
# == sut_type
# *
module MyBehaviour

  # any input type 

end

or 

# == sut_type
# XX
module MyBehaviour

  # apply behaviour only to sut which sut type is 'XX'

end

or

# == sut_type
# XX;YY
module MyBehaviour

  # apply behaviour only to sut which sut type is 'XX' or 'YY'
  # if more types needed use ';' as separator.

end
EXAMPLE

    when 'behaviour_requires'
<<-EXAMPLE
# == requires
# *
module MyBehaviour

  # when no plugins required (TDriver internal/generic SUT behaviour)

end

or

# == requires
# testability-driver-my-plugin
module MyBehaviour

  # when plugin 'testability-driver-my-plugin' is required 

end
EXAMPLE

    when 'table_format'
    
<<-EXAMPLE
# == tables
# table_name
#  title: My table 1
#  |header1|header2|header3|
#  |1.1|1.2|1.3|
#  |2.1|2.2|2.3|
#  |3.1|3.2|3.3|
#
# another_table_name
#  title: My table 2
#  |id|value|
#  |0|true|
#  |1|false|
def my_method

  # ...

end
EXAMPLE

  when 'default_argument_value_already_given'
<<-EXAMPLE
# == arguments
# value
#  Integer
#   description: first argument can integer
#   example: 10
#   default: 1
#  String
#   description: ... or string
#   example: "Hello"
#   default: "a"
def my_method( value = 1 )

  # ...

end
EXAMPLE

  when 'default_value_mandatory_argument'        

<<-EXAMPLE
# == arguments
# value
#  Integer
#   description: first argument can integer
#   example: 10
#   default: 1
def my_method( value )

  # ...

end
EXAMPLE


  else

    'Unknown help topic "%s"' % topic

  end

end

#load_templatesObject



400
401
402
403
404
405
406
407
408
409
410
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 400

def load_templates

  Dir.glob( File.join( File.dirname( File.expand_path( __FILE__ ) ), 'templates', '*.template' ) ).each{ | file |

    name = File.basename( file ).gsub( '.template', '' )

    @templates[ name ] = open( file, 'r' ).read

  }

end

#process_arguments(arguments) ⇒ Object

def store_to_results( module_name, name, type, params )

  unless @found_modules_and_methods.has_key?( module_name )

    @found_modules_and_methods[ module_name ] = []

  end

  #p params.select{ | param | param.last == false }
  #p params.select{ | param | param.last == true }

  #exit

  count = "%s;%s" % [ params.count, params.select{ | param | param.last == true }.count ]

  @found_modules_and_methods[ module_name ] << "%s#%s#%s" % [ name, type, count ] #{ :name => name, :type => type }

end


932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 932

def process_arguments( arguments )

  return [] if arguments.to_s.empty?      

  arguments = arguments[ 1 .. -2 ] if arguments[0].chr == "(" and arguments[-1].chr ==")"

  arguments.strip!
  
  # tokenize string
  tokenizer = RubyLex.new( arguments )

  # get first token
  token = tokenizer.token

  # set previous token to nil by default
  previous_token = nil

  args = []

  capture = true
  capture_depth = []
  capture_default = false

  default_value = []

  # loop while tokens available
  while token

    if [ RubyToken::TkLBRACE, RubyToken::TkLPAREN, RubyToken::TkLBRACK ].include?( token.class )

      default_value << token.text if capture_default
    
      capture_depth << token
    
      capture = false

    elsif [ RubyToken::TkRBRACE, RubyToken::TkRPAREN, RubyToken::TkRBRACK ].include?( token.class )

      default_value << token.text if capture_default

      capture_depth.pop
      
      capture = true if capture_depth.empty?

    # argument name
    elsif capture == true

      # argument name, or part of argument default value
      if token.kind_of?( RubyToken::TkIDENTIFIER ) and ![ RubyToken::TkDOT, RubyToken::TkCOLON2 ].include?( previous_token.class )

        args << [ token.name, nil, false ]

        # &blocks and *arguments are handled as optional parameters
        if [ RubyToken::TkBITAND, RubyToken::TkMULT ].include?( previous_token.class )
         #args.last[ 1 ] = previous_token.text 
  
         args.last[ 0 ] = previous_token.text + args.last[ 0 ] 
         args.last[ -1 ] = true 

        end
        
        default_value = []
        capture_default = false

      elsif token.kind_of?( RubyToken::TkCOMMA )
      
        capture_default = false
        
      # detect optional argument
      elsif token.kind_of?( RubyToken::TkASSIGN )

        capture_default = true

        # mark arguments as optional
        args.last[ -1 ] = true

      else

        default_value << token.text if capture_default && ![ RubyToken::TkSPACE, RubyToken::TkNL ].include?( token.class )
      
      end

    else
    
      default_value << token.text if capture_default && ![ RubyToken::TkSPACE, RubyToken::TkNL ].include?( token.class )
    
    end

    unless default_value.empty? 
  
      args.last[ 1 ] = default_value.join("")

    end

    # store previous token
    previous_token = token

    # get next token
    token = tokenizer.token

  end

  args

end

#process_attributes(attributes) ⇒ Object



1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1202

def process_attributes( attributes )

  @processing = :attributes

  results = []

  attributes.each{ | attribute | 

    results << process_method( attribute )

  }

  Hash[ results ]

end

#process_comment(comment) ⇒ Object



1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1218

def process_comment( comment )

  header = {}

  current_section = nil

  return header if comment.nil? || comment.empty?

  comment.each_line{ | line |

    # remove '#' char from beginning of line
    line.slice!( 0 )

    # if next character is whitespace assume that this is valid comment line
    # NOTE: that if linefeed is required use "#<#32><#10>"
    if [ 32 ].include?( line[ 0 ] )

      # remove first character
      line.slice!( 0 )

      # if line is a section header
      if line[ 0..2 ] == "== "

        # remove section header indicator string ("== ")
        line.slice!( 0..2 )

        # remove cr/lf
        line.gsub!( /[\n\r]/, "" )

        current_section = line.to_sym

        header[ current_section ] = "nodoc" if line.to_s == "nodoc"

      else

        unless current_section.nil?

          # remove cr/lf 
          # NOTE: if crlf is required use '\n'
          line.gsub!( /[\n\r]/, "" )

          # store to header hash
          if header.has_key?( current_section )

            header[ current_section ] << "\n" << ( line.rstrip )

          else

            header[ current_section ] = line.rstrip

          end

        else

          #puts "[nodoc?] %s" % line

        end

      end

    else

      #puts "[nodoc] %s" % line

    end

  }

  header

end

#process_file(file) ⇒ Object



424
425
426
427
428
429
430
431
432
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 424

def process_file( file )

  @module_path = []
  
  @current_file = file
  
  process_modules( file.modules )    

end

#process_formatted_section(source) ⇒ Object



807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 807

def process_formatted_section( source )

  result = []

  current_argument_type = nil

  current_section = nil

  argument_index = -1

  constants_to_classes = { "nil" => "NilClass", "true" => "TrueClass", "false" => "FalseClass" }

  source.lines.to_a.each_with_index{ | line, index | 
    
    # remove cr/lf
    line.chomp!

    # remove trailing whitespaces
    line.rstrip!

    # count nesting depth
    line.match( /^(\s*)/ )

    nesting = $1.size

    # remove leading whitespaces
    line.lstrip!

    if nesting == 0

      # convert constants nil, true, false to real class names
      line = constants_to_classes[ line.downcase ] if constants_to_classes.include?( line.downcase )

      line =~ /^(.+)/i

      if !$1.nil? && (65..90).include?( $1[0] )

        #Kernel.const_get( $1 ) rescue abort( "Line %s: \"%s\" is not valid argument variable type. (e.g. OK: \"String\", \"Array\", \"Fixnum\" etc) " % [ index + 1, $1 ] ) if verify_type

        # argument type
        current_argument_type = $1 || ""

        current_section = nil

        result << { current_argument_type => {} }

        argument_index += 1

      end

     else

        raise_error("Unable add value details (line %s: \"%s\") for %s due to detail type must be defined first.\nPlease note that return value and exception type must start with capital letter (e.g. OK: \"String\" NOK: \"string\")" % [ index + 1, line, current_argument_type  ] ) if current_argument_type.nil?

        line =~ /^(.*?)\:{1}($|[\r\n\t\s]{1})(.*)$/i

        if $1.nil?

          raise_error("Unable add value details (line %s: \"%s\") for %s due to section name not defined. Sections names are written in lowercase with trailing colon and whitespace (e.g. OK: \"example: 10\", NOK: \"example:10\")" % [ index +1, line, current_argument_type ]) if $1.nil? && current_section.nil?

          # remove leading & trailing whitespaces
          section_content = line.strip

        else

          current_section = $1

          if result[ argument_index ].has_key?( current_argument_type )
            
            unless result[ argument_index ][ current_argument_type ].has_key?( current_section )

              result[ argument_index ][ current_argument_type ][ current_section ] = ""

            end

          end
      
          section_content = ( $3 || "" ).strip

        end

        if current_argument_type.nil?  

          raise_error("Unable add return value details due to variable type not defined. Argument type must be defined at pos 1 of comment. (e.g. \"# Integer\" NOK: \"#  Integer\", \"#Integer\")") 

        else
  
          # add one leading whitespace if current_section value is not empty 
          section_content = " " + section_content unless result[ argument_index ][ current_argument_type ][ current_section ].empty?

          # store section_content to current_section
          result[ argument_index ][ current_argument_type ][ current_section ] << section_content

        end

    end


  }

  result

end

#process_method(method) ⇒ Object



1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1052

def process_method( method )

  results = []

  method_header = nil

  # if this tag ("== nodoc") is found in method description, it should not be added to documentation 
  no_doc = false

  if ( method.visibility == :public && @module_path.first =~ /MobyBehaviour/ )

    params = method.kind_of?( RDoc::Attr ) ? [] : process_arguments( method.params )

    @current_method = method

    method_header = process_comment( method.comment )

    arguments_found = 0

    method_header = Hash[ method_header.collect{ | key, value |

      if key == :nodoc
                
        no_doc = true
      
      end

      if key == :arguments

        value, arguments_found = process_method_arguments_section( value, params )

      end

      if key == :returns

        value = process_formatted_section( value )

      end

      if key == :exceptions

        value = process_formatted_section( value )

      end
      
      if key == :tables
      
          value = process_table( value )
      
      end

      [ key, value ]

    }]

    method_header[ :__arguments_found ] = arguments_found        

    # if no description found for arguments, add argument names to method_header hash
    if ( params.count > 0 ) && ( method_header[ :arguments ].nil? || method_header[:arguments].empty? )
            
      #p params.count, 
      method_header[:arguments] = process_undocumented_method_arguments( params )
      
    end

    method_name = method.name.clone

    type = "method"

    if method.kind_of?( RDoc::Attr )

      case method.rw

        when "R"
          type = "reader"
          #store_to_results( @module_path.join("::"), method.name, type )
        when "W"
          type = "writer"
          method_name << "="
          #store_to_results( @module_path.join("::"), method.name + "=", type )
        when "RW"
          type = "accessor"
          #method_name << ";#{ method_name }="
          #store_to_results( @module_path.join("::"), method.name + "=", type )

      else

        raise_error( "Unknown attribute format for '#{ method.name }' ($MODULE). Expected 'R' (attr_reader), 'W' (attr_writer) or 'RW' (attr_accessor), got: '#{ method.rw }'" )

      end

      #store_to_results( @module_path.join("::"), method.name, type )

      method_header.merge!( :__type => type )

    else

      method_header.merge!( :__type => "method" )
      
    end

    #p params
    
    #sleep 0.3

    method_header.merge!( 
      :__arguments_implemented => params.count , 
      :__arguments_optional => params.select{ | param | param.last == true }.count 
    )

    #store_to_results( @module_path.join("::"), method.name, type, params )

    #no_doc ? nil : 
    [ method_name, method_header ]

  else

    nil

  end

end

#process_method_arguments_section(source, params_array) ⇒ Object



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 468

def process_method_arguments_section( source, params_array )

  result = []

  current_argument = nil

  current_argument_type = nil

  current_section = nil

  argument_index = -1

  arguments_found = 0

  source.lines.to_a.each_with_index{ | line, index | 
    
    # remove cr/lf
    line.chomp!

    # remove trailing whitespaces
    line.rstrip!

    # count nesting depth
    line.match( /^(\s*)/ )

    nesting = $1.size

    # remove leading whitespaces
    line.lstrip!

    if nesting == 0

      line =~ /^([*|&]{0,1}\w+(\#\w+?)*)$/i

      unless $1.nil?

        # argument name
        current_argument = $1 

        arguments_found += 1 unless line.include?( "#" )

        current_section = nil

        current_argument_type = nil

        result << { current_argument => { :argument_type_order => [], :types => {} } }

        argument_index += 1

      end

    else

      # is line content class name? (argument variable type)
      line =~ /^(.*)$/i

      if !$1.nil? && ( 65..90 ).include?( $1[0] ) && nesting == 1 # "Array", "String", "Integer"

        #Kernel.const_get( $1 ) rescue abort( "Line %s: \"%s\" is not valid argument variable type. (e.g. OK: \"String\", \"Array\", \"Fixnum\" etc) " % [ index +1, $1 ] )

        current_argument_type = $1

        result[ argument_index ][ current_argument ][ :argument_type_order ] << $1

        result[ argument_index ][ current_argument ][ :types ][ current_argument_type ] = {}

        #result[ argument_index ][ current_argument ][ current_argument_type ] = {}

        current_section = nil

      else

        raise_error("Unable add argument details (line %s: \"%s\") for \"%s\" due to argument variable type must be defined first.\nPlease note that argument type must start with capital letter (e.g. OK: \"String\" NOK: \"string\")" % [ index + 1, line, current_argument  ] ) if current_argument_type.nil?

        line =~ /^(.*?)\:{1}($|[\r\n\t\s]{1})(.*)$/i

        if $1.nil?

          raise_error("Unable add argument details (line %s: \"%s\") for \"%s\" due to section name not defined. Sections names are written in lowercase with trailing colon and whitespace (e.g. OK: \"example: 10\", NOK: \"example:10\")" % [ index +1, line, current_argument]) if $1.nil? && current_section.nil?

          # remove leading & trailing whitespaces
          section_content = line.strip

        else

          current_section = $1

          if result[ argument_index ][ current_argument ][ :types ].has_key?( current_argument_type )

            #unless result[ argument_index ][ current_argument ][ current_argument_type ].has_key?( current_section )
            unless result[ argument_index ][ current_argument ][ :types ][ current_argument_type ].has_key?( current_section )

              #result[ argument_index ][ current_argument ][ current_argument_type ][ current_section ] = ""
              result[ argument_index ][ current_argument ][ :types ][ current_argument_type ][ current_section ] = ""

            end
        

          end

          section_content = $3.strip

        end

        raise_error("Unable add argument details due to argument not defined. Argument name must start from pos 1 of comment. (e.g. \"# my_variable\" NOK: \"#  my_variable\", \"#myvariable\")") if current_argument.nil?  

        if result[ argument_index ][ current_argument ][ :types ].has_key?( current_argument_type )

          if result[ argument_index ][ current_argument ][ :types ][ current_argument_type ].has_key?( current_section )


            # add one leading whitespace if current_section value is not empty 
            #section_content = " " + section_content unless result[ argument_index ][ current_argument ][ current_argument_type ][ current_section ].empty?
            section_content = " " + section_content unless result[ argument_index ][ current_argument ][ :types ][ current_argument_type ][ current_section ].empty?

            # store section_content to current_section
            #result[ argument_index ][ current_argument ][ current_argument_type ][ current_section ] << section_content
            result[ argument_index ][ current_argument ][ :types ][ current_argument_type ][ current_section ] << section_content

        end 

        end

      end

    end

  }

  order = []
  
  params_array = params_array.collect{ | o | [ o.first, Hash[:default, o[1], :optional, o.last] ] }

  params_hash = Hash[ params_array ]

  default_value_already_set = []

  params_array.each{ | param |

    if ( item = result.select{ | arg | arg.keys.include?( param.first ) }.to_a).empty? # Array conversion for ruby 1.9 compatibility

      raise_error("Error: Argument '#{ param.first }' is implemented but not documented in '#{ @current_method.name }' ($MODULE).\nNote that documented argument and variable name must be identical.", [ 'writer', 'accessor' ].include?( @processing ) ? 'attr_argument' : 'arguments' ) unless param.first.to_s.include?("#")

      order << { param.first => {} }

    else

      arg = item.first
      arg_name = arg.keys.first

      # apply overriding default argument value from documentation
      arg[ arg_name ][ :argument_type_order ].each{ | type_name |

        type_hash = arg[ arg_name ][ :types ][ type_name ]

        unless type_hash["default"].nil?

          if arg[ arg_name ][ :default ].nil?

            if params_hash[  arg_name ][ :optional ] == false

              raise_error("Error: Default value given for mandatory argument #{ arg_name } (type: #{ type_name }).", 'default_value_mandatory_argument' )

            else

              arg[ arg_name ][ :default ] = type_hash["default"] 

            end

          else
            raise_error("Error: Default value already given for #{ arg_name } (type: #{ type_name }).", 'default_argument_value_already_given' )
          end
 
        end
      }
  
      # if optional parameter and no overriding value defined, add one from implementation
      if arg[ arg_name ][:default].nil?

        arg[ arg_name ][ :default ] = params_hash[ arg_name ][ :default ] if params_hash[ arg_name ][ :optional ] == true

      end

      order << arg
    
    end
  
  }
  
  # collect all argument names and add block arguments if any   
  found_keys = order.collect{ | pair | pair.keys }.flatten

  # collect all documented argument names
  documented_arguments = result.collect{ | arg | arg.keys }.flatten

  unimplemented_arguments = ( documented_arguments - found_keys )

  unless [ :attributes ].include?( @processing )

    unless unimplemented_arguments.empty?

      unimplemented_arguments.each{ | argument |

        raise_error("Error: Argument '#{ argument }' is documented but not implemented in '#{ @current_method.name }' ($MODULE).\nNote that documented argument and variable name must be identical.", [ :attributes ].include?( @processing ) ? 'attr_argument' : 'arguments' )

      }

      # remove unimplemented argument documentation
      result = result.select{ | documented_argument |

        # always add block parameters
        unimplemented_arguments.include?( documented_argument.to_a.flatten.first ) == false || documented_argument.to_a.flatten.first.include?("#")

      }.to_a # Array conversion for ruby 1.9 compatiblity

    end

  end
  
  # add missing/undocumented arguments to order list
  missing = result.collect{ | value | order << value unless found_keys.include?( value.keys.first ) }

  [ order, arguments_found ]

end

#process_methods(methods) ⇒ Object



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 452

def process_methods( methods )

  @processing = "method"

  results = []

  methods.each{ | method | 

    results << process_method( method )

  }

  Hash[ results ]

end

#process_module(_module) ⇒ Object



1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1846

def process_module( _module )

  @already_processed_files << _module.full_name

  # skip if not a behaviour module      
  return if /^MobyBehaviour.*/ !~ _module.full_name.to_s

  module_header = process_comment( _module.comment )

  # store information where module is stored
  @module_in_files = _module.in_files.collect{ | file | file.file_absolute_name }

  #unless module_header.empty?

    @current_module = _module

    # process methods
    methods = process_methods( _module.method_list )

    # process attributes
    attributes = process_attributes( _module.attributes )

    print "  ... %s" % module_header[:behaviour]

    xml = generate_behaviour( module_header, methods, attributes ) 

    xml_file_name = '%s.%s' % [ module_header[:behaviour], 'xml' ]

    begin

      if xml_file_name != '.xml' 

        if @created_files.has_key?( xml_file_name )

          xml_file_name = '%s_duplicate_name.%s' % [ module_header[:behaviour], 'xml' ]
          
          warn("Warning! One of the behaviour modules is already using name '#{ module_header[:behaviour] }', saving as #{ xml_file_name }")

          #sleep 1
      
        end

        @created_files[ xml_file_name ] = {}

        open( xml_file_name, 'w'){ | file | file << xml }

        puts ".xml"

      else

        if methods.count > 0

          xml_file_name = ( @module_path[1..-1].join("") ) + '.xml'

          warn("Warning: #{ @module_path.join("::") } does not have behaviour (module) description defined, saving as %s " % xml_file_name )
          #sleep 2

          if @created_files.has_key?( xml_file_name )

            warn("Warning! One of the behaviour modules is already using name '#{ module_header[:behaviour] }'")

            xml_file_name = ( @module_path[1..-1].join("") ) + '_duplicate_name.xml'

            #sleep 1
        
          end
          
          @created_files[ xml_file_name ] = {}

          open( xml_file_name, 'w'){ | file | file << xml }

        else

          warn("Skip: #{ @module_path.join("::") } does not have any public methods") unless @module_path.join("::") == "MobyBehaviour"

        end

        #p xml

        #warn("Skip: #{ @module_path.join("::") } XML not saved due to missing behaviour name/description ") #in #{ @module_in_files.join(", ") }")

      end

    rescue Exception => exception

      warn("Warning: Error writing file %s (%s: %s)" % [ xml_file_name, exception.class, exception.message ] )

    end

  #end

  # process if any child modules 
  process_modules( _module.modules ) unless _module.modules.empty?

end

#process_modules(modules) ⇒ Object



434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 434

def process_modules( modules )

  modules.each{ | _module | 

    unless @already_processed_files.include?( _module.full_name )

      @module_path.push( _module.name )

      process_module( _module ) 

      @module_path.pop

    end

  }

end

#process_table(source) ⇒ Object



694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 694

def process_table( source )

  result = []

  table_name = nil
  header_columns = 0

  source.lines.to_a.each_with_index{ | line, index | 

    # remove cr/lf
    line.chomp!

    # remove trailing whitespaces
    line.rstrip!

    # count nesting depth
    line.match( /^(\s*)/ )

    nesting = $1.size

    #puts "%s,%s: %s" % [ index, nesting, line ]

    # new table
    if nesting == 0

      unless line.empty?
      
        # break if for some reason first character is "="            
        return result if line[0].chr == "=" 
        
        line =~ /^(\w+)/i

        result << { "name" => $1, "content" => [] }

        table_name = $1.to_s

      else
      
        table_name = nil

      end

    else

      line.lstrip!

      if line[0].chr == '|'

        unless table_name.nil?
          
          if line[-1].chr != '|'

            raise_error( "Malformed custom table #{ result.last[ "name" ]}, line '#{ line }' ($MODULE). Line must start and end with '|' character.", "table_format" ) 

          else

            line[0] = ""
            line[-1] = ""

            columns = line.split("|")

            unless result.last[ "content" ].empty?
            
              raise_error( "Malformed custom table #{ result.last[ "name" ]}, line '#{ line }' ($MODULE). Number of columns (#{ columns.count }) does not match with header (#{ header_columns })", "table_format" ) if columns.count != header_columns 
                              
            else
              
              header_columns = columns.count
            
            end

            result.last[ "content" ] << columns
          
          end

        else

          raise_error( "Malformed custom table #{ result.last[ "name" ]} ($MODULE). Table name is missing.", "table_format" ) 

        end
      
      else
                
        unless line.empty?
                
          line =~ /^(.*?)\:{1}($|[\r\n\t\s]{1})(.*)$/i

          if $1.to_s.empty?

            raise_error( "Malformed custom table #{ result.last[ "name" ]}, line '#{ line }' ($MODULE). Table section name (e.g title) is missing.", "table_format" ) 
              
          else
  
            result.last[ $1.to_s ] = ( $3 || "" ).strip
  
          end
  
        else
      
          table_name = nil
        
        end
  
      end
      
    end
    
  }
        
  result

end

#process_undocumented_method_arguments(params) ⇒ Object



1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1038

def process_undocumented_method_arguments( params )

  params.collect{ | param |
  
    hash = {}
    hash[ :types ] = {}
    hash[ :default ] = param[1] if param[-1] == true

    { param.first.to_s => hash }
      
  }

end

#raise_error(text, topic = nil) ⇒ Object



1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
# File 'lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb', line 1306

def raise_error( text, topic = nil )

  type = ( @processing == "method" ) ? "method" : "attribute"

  text.gsub!( '$TYPE', type )

  text.gsub!( '$MODULE', @current_module.full_name )

  text = "=========================================================================================================\n" <<
    "File: #{ @module_in_files.join(", ") }\n" << text << "\n\nExample:\n\n"

  text << help( topic ) unless topic.nil?

  warn( text << "\n" )

end