Class: Gondler::Gomfile

Inherits:
Object
  • Object
show all
Defined in:
lib/gondler/gomfile.rb

Defined Under Namespace

Classes: NotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Gomfile

Returns a new instance of Gomfile.

Raises:



5
6
7
8
9
10
11
# File 'lib/gondler/gomfile.rb', line 5

def initialize(path)
  raise NotFound, path unless File.exist?(path)
  @packages = []
  @itself = nil

  load(path)
end

Instance Attribute Details

#packagesObject (readonly)

Returns the value of attribute packages.



12
13
14
# File 'lib/gondler/gomfile.rb', line 12

def packages
  @packages
end

Instance Method Details

#autodetectObject



68
69
70
71
72
73
74
# File 'lib/gondler/gomfile.rb', line 68

def autodetect
  deps = `go list -f '{{join .Deps "\\n"}}' ./...`.strip.split(/\n+/)

  deps.each do |dep|
    gom(dep) unless dep.include?('.')
  end
end

#gom(name, options = {}) ⇒ Object Also known as: package



45
46
47
48
49
50
51
# File 'lib/gondler/gomfile.rb', line 45

def gom(name, options = {})
  options[:group] = @now_group if @now_group
  options[:os] = @now_os if @now_os

  package = Gondler::Package.new(name, options)
  @packages.push(package) if package.installable?
end

#group(*groups) ⇒ Object



54
55
56
57
58
59
# File 'lib/gondler/gomfile.rb', line 54

def group(*groups)
  @now_group = groups
  yield if block_given?
ensure
  @now_group = nil
end

#itself(name) ⇒ Object



14
15
16
# File 'lib/gondler/gomfile.rb', line 14

def itself(name)
  @itself = name
end

#itself_packageObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gondler/gomfile.rb', line 18

def itself_package
  if !@itself && Gondler.env.orig_path
    realpath = proc do |path|
      if File.respond_to?(:realpath) # 1.9+
        File.realpath(path)
      else
        path
      end
    end

    orig_src = realpath[File.join(Gondler.env.orig_path, 'src')]
    dir = realpath[File.dirname(@path)]
    if dir.start_with?(orig_src)
      @itself = dir[orig_src.size.succ .. -1]
    end
  end

  if @itself
    Gondler::Package.new(@itself, :path => '.')
  end
end

#load(path) ⇒ Object



40
41
42
43
# File 'lib/gondler/gomfile.rb', line 40

def load(path)
  @path = File.expand_path(path)
  instance_eval(File.read(path))
end

#os(*oss) ⇒ Object



61
62
63
64
65
66
# File 'lib/gondler/gomfile.rb', line 61

def os(*oss)
  @now_os = oss
  yield if block_given?
ensure
  @now_os = nil
end