Class: Rebundler::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rebundler/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Parser

Returns a new instance of Parser.



25
26
27
28
29
30
31
32
33
# File 'lib/rebundler/parser.rb', line 25

def initialize(content)
  @content = content
  @frozen_string_literal = false
  @directives = []
  @gem_sets = [GemSet.new(default: true)]
  @comments = []

  parse!
end

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments.



7
8
9
# File 'lib/rebundler/parser.rb', line 7

def comments
  @comments
end

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/rebundler/parser.rb', line 7

def content
  @content
end

#directivesObject (readonly)

Returns the value of attribute directives.



7
8
9
# File 'lib/rebundler/parser.rb', line 7

def directives
  @directives
end

#frozen_string_literalObject (readonly)

Returns the value of attribute frozen_string_literal.



7
8
9
# File 'lib/rebundler/parser.rb', line 7

def frozen_string_literal
  @frozen_string_literal
end

#gem_setsObject (readonly)

Returns the value of attribute gem_sets.



7
8
9
# File 'lib/rebundler/parser.rb', line 7

def gem_sets
  @gem_sets
end

Class Method Details

.from_file(path) ⇒ Object

Raises:



9
10
11
12
13
# File 'lib/rebundler/parser.rb', line 9

def self.from_file(path)
  raise Rebundler::Error, "File not found: #{path}" unless File.exist?(path)

  new(File.read(path))
end

.from_string(content) ⇒ Object



15
16
17
# File 'lib/rebundler/parser.rb', line 15

def self.from_string(content)
  new(content)
end

Instance Method Details

#format(overwrite_comments: false) ⇒ Object



19
20
21
# File 'lib/rebundler/parser.rb', line 19

def format(overwrite_comments: false)
  Formatter.new(self).format(overwrite_comments:)
end