Class: DRG::Tasks::GemfileLine
- Inherits:
-
Struct
- Object
- Struct
- DRG::Tasks::GemfileLine
- Defined in:
- lib/drg/tasks/gemfile_line.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
(also: #to_int)
Returns the value of attribute index.
-
#line ⇒ Object
(also: #to_s)
Returns the value of attribute line.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#remove_version ⇒ String
Line.
-
#swap_version(full_version) ⇒ String
Line.
-
#update(new_version) ⇒ String
Line.
- #version ⇒ Object deprecated Deprecated.
Instance Attribute Details
#index ⇒ Object Also known as: to_int
Returns the value of attribute index
3 4 5 |
# File 'lib/drg/tasks/gemfile_line.rb', line 3 def index @index end |
#line ⇒ Object Also known as: to_s
Returns the value of attribute line
3 4 5 |
# File 'lib/drg/tasks/gemfile_line.rb', line 3 def line @line end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/drg/tasks/gemfile_line.rb', line 3 def name @name end |
Instance Method Details
#==(other) ⇒ Object
7 8 9 |
# File 'lib/drg/tasks/gemfile_line.rb', line 7 def ==(other) line.to_s == other.to_s end |
#remove_version ⇒ String
Returns line.
18 19 20 |
# File 'lib/drg/tasks/gemfile_line.rb', line 18 def remove_version swap_version('') end |
#swap_version(full_version) ⇒ String
Returns line.
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 |
# File 'lib/drg/tasks/gemfile_line.rb', line 32 def swap_version(full_version) code, *comments = line.split(/#/) parts = code.split(',') end_of_line = code.rstrip.end_with?(',') ? ",#{parts.last}" : '' if parts.size == 1 parts[0].chomp! parts << " #{full_version}" unless full_version.empty? else # ignore the first part, which is the gem name parts_without_gem = parts.drop(1) # reject options hash version_parts = parts_without_gem.reject { |x| x.include?(':') } # remove all but the first version part from the original parts array version_parts.drop(1).each { |version_part| parts.delete(version_part) } # find the index of it if index = parts.index(version_parts.first) # replace the current gem version (inside quotes) parts[index].sub! /['"].+['"]/, full_version else parts.insert 1, " #{full_version}" end parts.reject! { |x| x.strip.empty? } end space_after_gem = parts.first[/\s+$/].to_s space_after_gem = space_after_gem[0, (space_after_gem.size - full_version.size) - 2] if space_after_gem.size > full_version.size parts.first.rstrip! line.replace parts.join(',') line << end_of_line line << space_after_gem << "#" << comments.join if comments.any? line << "\n" unless line.end_with?("\n") line end |
#update(new_version) ⇒ String
Returns line.
13 14 15 |
# File 'lib/drg/tasks/gemfile_line.rb', line 13 def update(new_version) swap_version("'#{new_version.to_s}'") end |
#version ⇒ Object
Deprecated.
Note:
not used
67 68 69 |
# File 'lib/drg/tasks/gemfile_line.rb', line 67 def version line[/, (.+)\n?/, 1] end |