fork download
  1.  
  2. def loadFile
  3. "
  4. mod 'testmod1',
  5. :git => 'git@testing.com:reaktor/testmod1.git',
  6. :ref => 'RELEASE_1.0.0'
  7.  
  8. mod 'testmod2',
  9. :git => 'git@testing.com:reaktor/myproject-testmod2.git',
  10. :ref => 'RELEASE_2.0.10'
  11.  
  12. mod 'testmod3',
  13. :git => 'git@testing.com:reaktor/testmod3.git',
  14. :tag => 'RELEASE_10.2.3'
  15.  
  16. "
  17. end
  18.  
  19. def get_module_name_a(repo_name)
  20. input_string = loadFile
  21. regex = /mod ["'](\w*)["'],\s*$\n+(\s*):git\s*=>\s*["'].*#{repo_name}\.git["'],$\n+(\s*):ref\s*=>\s*['"](\w+|\w+\.\d+\.\d+)['"]$/
  22. result = regex.match(input_string)
  23. result[1]
  24. end
  25.  
  26. def get_module_name_b(repo_name)
  27. input_string = loadFile
  28. regex = /mod[ ]["'](\w*)["'],\s*$\n+
  29. (\s*):git\s*=>\s*["'].*#{repo_name}.git["'],$\n+
  30. (\s*):ref\s*=>\s*['"](\w+|\w+\.\d+\.\d+)['"]
  31. $/x
  32. result = regex.match(input_string)
  33. result[1]
  34. end
  35.  
  36. puts get_module_name_a('myproject-testmod2')
  37. puts get_module_name_b('myproject-testmod2')
Success #stdin #stdout 0.05s 9656KB
stdin
Standard input is empty
stdout
testmod2
testmod2