Class: GemfileLocker::GemfileProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/gemfile_locker/gemfile_processor.rb

Direct Known Subclasses

Locker, Unlocker

Defined Under Namespace

Classes: Rewriter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GemfileProcessor

Returns a new instance of GemfileProcessor.



23
24
25
# File 'lib/gemfile_locker/gemfile_processor.rb', line 23

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/gemfile_locker/gemfile_processor.rb', line 21

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'lib/gemfile_locker/gemfile_processor.rb', line 21

def path
  @path
end

Instance Method Details

#call(string) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/gemfile_locker/gemfile_processor.rb', line 27

def call(string)
  buffer = Parser::Source::Buffer.new('(Gemfile)')
  buffer.source = string
  parser = Parser::CurrentRuby.new
  ast = parser.parse(buffer)
  Rewriter.new.rewrite(buffer, ast) do |gem_entry|
    process_gem(gem_entry) unless skip_gem?(gem_entry)
  end
end

#process_gem(_name, _data) ⇒ Object



45
46
47
# File 'lib/gemfile_locker/gemfile_processor.rb', line 45

def process_gem(_name, _data)
  raise 'Abstract method'
end

#skip_gem?(gem_entry) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/gemfile_locker/gemfile_processor.rb', line 37

def skip_gem?(gem_entry)
  if options[:only]
    !options[:only].include?(gem_entry.name)
  elsif options[:except]
    options[:except].include?(gem_entry.name)
  end
end