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(version) ⇒ String
Line.
- #version ⇒ Object
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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/drg/tasks/gemfile_line.rb', line 23 def swap_version(full_version) comment = line =~ /#/ ? " #{line.slice!(/#.*/).strip}" : '' if line =~ /,.+\n?/ if line =~ /,\s*['"].+['"]/ line[/,\s*['"].+['"]/] = full_version else line[/,\s*/] = "#{full_version}, " line[/\n/] = "#{comment}\n" end elsif line.end_with?("\n") line.sub!("\n", "#{full_version}#{comment}\n") else line << full_version << comment << "\n" end line end |
#update(version) ⇒ String
Returns line.
13 14 15 |
# File 'lib/drg/tasks/gemfile_line.rb', line 13 def update(version) swap_version(", '#{version.to_s}'") end |
#version ⇒ Object
Note:
not used
41 42 43 |
# File 'lib/drg/tasks/gemfile_line.rb', line 41 def version line[/, (.+)\n?/, 1] end |