Class: InvocaGems::GemfileLine

Inherits:
Object
  • Object
show all
Defined in:
lib/invoca_gems/gemfile_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemfile, line, index) ⇒ GemfileLine

Returns a new instance of GemfileLine.



5
6
7
8
9
10
11
12
# File 'lib/invoca_gems/gemfile_line.rb', line 5

def initialize(gemfile, line, index)
  @gemfile = gemfile
  @line = line
  @index = index
  @prefix = @line.match(/\A(\s*)gem/)[1]

  instance_eval(line)
end

Instance Attribute Details

#gem_gitObject (readonly)

Returns the value of attribute gem_git.



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

def gem_git
  @gem_git
end

#gem_githubObject (readonly)

Returns the value of attribute gem_github.



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

def gem_github
  @gem_github
end

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



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

def gem_name
  @gem_name
end

#gem_optionsObject (readonly)

Returns the value of attribute gem_options.



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

def gem_options
  @gem_options
end

#gem_refObject (readonly)

Returns the value of attribute gem_ref.



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

def gem_ref
  @gem_ref
end

#gem_versionObject (readonly)

Returns the value of attribute gem_version.



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

def gem_version
  @gem_version
end

#gemfileObject (readonly)

Returns the value of attribute gemfile.



2
3
4
# File 'lib/invoca_gems/gemfile_line.rb', line 2

def gemfile
  @gemfile
end

#indexObject (readonly)

Returns the value of attribute index.



2
3
4
# File 'lib/invoca_gems/gemfile_line.rb', line 2

def index
  @index
end

#lineObject (readonly)

Returns the value of attribute line.



2
3
4
# File 'lib/invoca_gems/gemfile_line.rb', line 2

def line
  @line
end

Instance Method Details

#gem(name, *args) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/invoca_gems/gemfile_line.rb', line 18

def gem(name, *args)
  @gem_name    = name
  @gem_options = args.last.is_a?(Hash) ? args.pop.dup : {}
  @gem_version = args.first || ">= 0"
  @gem_branch  = @gem_options[:branch] || 'master'
  @gem_ref     = @gem_options.delete(:ref)
  @gem_git     = @gem_options.delete(:git)
  @gem_github  = @gem_options.delete(:github)
end

#save!Object



14
15
16
# File 'lib/invoca_gems/gemfile_line.rb', line 14

def save!
  gemfile.save!(self)
end

#update_as_github(gem_version, uri, sha) ⇒ Object

TODO - Perfer branch before ref. TODO - handle local branch…



38
39
40
41
42
43
44
45
46
# File 'lib/invoca_gems/gemfile_line.rb', line 38

def update_as_github(gem_version, uri, sha)
  @line = [
    "#{@prefix}gem ",
    "'#{gem_name}',".ljust(24),
    " '#{gem_version}', ".ljust(11),
    "git: '#{uri}',".ljust(56),
    "ref: '#{sha}'"
  ].join('')
end

#update_as_path(path) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/invoca_gems/gemfile_line.rb', line 28

def update_as_path(path)
  @line = [
    "#{@prefix}gem ",
    "'#{gem_name}',".ljust(24),
    " path: '#{path}'"
  ].join('')
end