Class: GemXray::GemfileSourceParser
- Inherits:
-
Object
- Object
- GemXray::GemfileSourceParser
- Defined in:
- lib/gemxray/gemfile_source_parser.rb
Defined Under Namespace
Classes: GemInvocationRecorder, Metadata
Instance Method Summary collapse
-
#initialize(gemfile_path) ⇒ GemfileSourceParser
constructor
A new instance of GemfileSourceParser.
- #parse ⇒ Object
Constructor Details
#initialize(gemfile_path) ⇒ GemfileSourceParser
Returns a new instance of GemfileSourceParser.
19 20 21 |
# File 'lib/gemxray/gemfile_source_parser.rb', line 19 def initialize(gemfile_path) @gemfile_path = gemfile_path end |
Instance Method Details
#parse ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gemxray/gemfile_source_parser.rb', line 23 def parse lines = File.readlines(gemfile_path, chomp: false) entries = [] block_stack = [] index = 0 while index < lines.length stripped = lines[index].strip if group_block_start?(stripped) block_stack << { type: :group, groups: parse_group_names(stripped) } index += 1 next end if generic_block_start?(stripped) block_stack << { type: :block, groups: [] } index += 1 next end if stripped == "end" block_stack.pop index += 1 next end unless gem_statement_start?(lines[index]) index += 1 next end start_index = index statement_lines = [lines[index]] until syntax_complete?(statement_lines.join) index += 1 break if index >= lines.length statement_lines << lines[index] end = parse_statement(statement_lines.join, start_index + 1, current_groups(block_stack)) entries << if index += 1 end entries end |