Class: Ecogem::Gemfile::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/ecogem/gemfile/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency, data) ⇒ Source

Returns a new instance of Source.



9
10
11
12
# File 'lib/ecogem/gemfile/source.rb', line 9

def initialize(dependency, data)
  @dependency = dependency
  @data = data
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



7
8
9
# File 'lib/ecogem/gemfile/source.rb', line 7

def git
  @git
end

Instance Method Details

#codeObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ecogem/gemfile/source.rb', line 54

def code
  @code ||= begin
    if git?
      "path: Ecogem.git_path(#{git_source.key.inspect})"
    elsif path?
      "path: #{relative_path.inspect}"
    elsif source?
      "source: #{source.inspect}"
    end
  end
end

#git?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ecogem/gemfile/source.rb', line 14

def git?
  @data && @data.options.key?('git')
end

#git_sourceObject



46
47
48
# File 'lib/ecogem/gemfile/source.rb', line 46

def git_source
  @git_source ||= ::Ecogem::Git.new(git_uri, ref)
end

#git_uriObject



26
27
28
# File 'lib/ecogem/gemfile/source.rb', line 26

def git_uri
  @data.options['git']
end

#pathObject



30
31
32
# File 'lib/ecogem/gemfile/source.rb', line 30

def path
  @path ||= ::File.expand_path(@data.options['path'].to_s, @dependency.gemfile.dir)
end

#path?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ecogem/gemfile/source.rb', line 18

def path?
  @data && @data.options.key?('path')
end

#path_sourceObject



50
51
52
# File 'lib/ecogem/gemfile/source.rb', line 50

def path_source
  @path_source ||= ::Ecogem::Path.new(path)
end

#refObject



42
43
44
# File 'lib/ecogem/gemfile/source.rb', line 42

def ref
  @data.ref
end

#relative_pathObject



34
35
36
# File 'lib/ecogem/gemfile/source.rb', line 34

def relative_path
  @relative_path ||= ::Pathname.new(path).relative_path_from(::Pathname.new(@dependency.gemfile.dir)).to_s
end

#sourceObject



38
39
40
# File 'lib/ecogem/gemfile/source.rb', line 38

def source
  @data.options['remotes'][0]
end

#source?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ecogem/gemfile/source.rb', line 22

def source?
  @data && @data.options.key?('remotes')
end