Class: GemfileLocker::GemfileProcessor
- Inherits:
-
Object
- Object
- GemfileLocker::GemfileProcessor
- Defined in:
- lib/gemfile_locker/gemfile_processor.rb
Constant Summary collapse
- GEM_LINE_REGEX =
/ ^ (?<prefix>\s*gem\s*["']) (?<name>[^'"]+) (?<name_quote>['"]) (?<version_section> (?<version_prefix>\s*,\s*['"]) (?<version>[^'"]*) (?<version_quote>['"]) )? (?<suffix>,?.*)? $ /x- GEM_MATCH_FIELDS =
%i( prefix name name_quote version_prefix version version_quote suffix ).freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #call(string) ⇒ Object
-
#initialize(options = {}) ⇒ GemfileProcessor
constructor
A new instance of GemfileProcessor.
- #process_gem(_name, _data) ⇒ Object
- #process_gems(string) ⇒ Object
- #set_gem_version(data, version) ⇒ Object
- #skip_gem?(data) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ GemfileProcessor
Returns a new instance of GemfileProcessor.
28 29 30 |
# File 'lib/gemfile_locker/gemfile_processor.rb', line 28 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/gemfile_locker/gemfile_processor.rb', line 26 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/gemfile_locker/gemfile_processor.rb', line 26 def path @path end |
Instance Method Details
#call(string) ⇒ Object
32 33 34 35 36 |
# File 'lib/gemfile_locker/gemfile_processor.rb', line 32 def call(string) process_gems(string) do |data| process_gem(data) unless skip_gem?(data) end end |
#process_gem(_name, _data) ⇒ Object
56 57 58 |
# File 'lib/gemfile_locker/gemfile_processor.rb', line 56 def process_gem(_name, _data) raise 'Abstract method' end |
#process_gems(string) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/gemfile_locker/gemfile_processor.rb', line 46 def process_gems(string) string.gsub(GEM_LINE_REGEX) do match = Regexp.last_match data = GEM_MATCH_FIELDS.map { |x| [x, match[x]] }.to_h result = yield data result ||= data GEM_MATCH_FIELDS.map { |x| result[x] }.join end end |
#set_gem_version(data, version) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gemfile_locker/gemfile_processor.rb', line 60 def set_gem_version(data, version) data = data.dup if version data[:version_prefix] ||= ", #{data[:name_quote] || "'"}" data[:version_quote] ||= data[:name_quote] || "'" data[:version] = version else %i( version_prefix version version_quote ).each { |x| data.delete(x) } end data end |
#skip_gem?(data) ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/gemfile_locker/gemfile_processor.rb', line 38 def skip_gem?(data) if [:only] ![:only].include?(data[:name]) elsif [:except] [:except].include?(data[:name]) end end |