Class: DRG::Tasks::GemfileLine

Inherits:
Struct
  • Object
show all
Defined in:
lib/drg/tasks/gemfile_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#indexObject Also known as: to_int

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



3
4
5
# File 'lib/drg/tasks/gemfile_line.rb', line 3

def index
  @index
end

#lineObject Also known as: to_s

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



3
4
5
# File 'lib/drg/tasks/gemfile_line.rb', line 3

def line
  @line
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of 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_versionString

Returns line.

Returns:

  • (String)

    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.

Returns:

  • (String)

    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.

Parameters:

  • version (String)

    is the new value for the gem (add/replace)

Returns:

  • (String)

    line



13
14
15
# File 'lib/drg/tasks/gemfile_line.rb', line 13

def update(version)
  swap_version(", '#{version.to_s}'")
end

#versionObject

Note:

not used



41
42
43
# File 'lib/drg/tasks/gemfile_line.rb', line 41

def version
  line[/, (.+)\n?/, 1]
end