Class: Jank::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/config.rb', line 7

def initialize
  # Ignore or include ENV gopath
  @include_env_gopath = nil

  # Path to go
  @go = ENV['JANK_GO'] || `which go`.chomp

  # Path to rsync
  @rsync = ENV['JANK_RSYNC'] || `which rsync`.chomp

  if @go.empty?
    STDERR.write "go not found"
    exit(1)
  end

  if @rsync.empty?
    STDERR.write "rsync not found"
    exit(1)
  end

  # Working directory
  if ENV.has_key? 'TM_DIRECTORY'
    @pwd = ENV['TM_DIRECTORY']
  else
    @pwd = Dir.pwd
  end

  # Home directory
  @home = Dir.home

  # Current Go package
  @package = nil

  # Janked Go package (might be higher in the filesystem than the current package)
  @janked_package = nil

  # Path to root of go package in gopath
  @janked_gopath = nil

  # Path to root of go package in local project
  @janked_local_path = nil

  # true if this package is to be janked into a gopath
  @janked = false

  # ENV supplied gopaths
  @gopaths = ENV['GOPATH'] || ENV['JANK_GOPATH'] || ENV['TM_GOPATH']
  if @gopaths == nil
    @gopaths = Array.new
  else
    @gopaths = @gopaths.split(/:/).select {|p| p != ''}
  end

  # Array of janked_gopaths
  @janked_gopaths = Array.new

  # The gopath that contains the working directory, null if janked
  @local_gopath = nil

  read_config_files

  @env = ENV

  if @include_env_gopath == false
    @env['GOPATH'] = @janked_gopaths.uniq.join(':')
  else
    @env['GOPATH'] = (@janked_gopaths + @gopaths).uniq.join(':')
  end
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/config.rb', line 5

def env
  @env
end

#goObject (readonly)

Returns the value of attribute go.



5
6
7
# File 'lib/config.rb', line 5

def go
  @go
end

#gopathsObject (readonly)

Returns the value of attribute gopaths.



5
6
7
# File 'lib/config.rb', line 5

def gopaths
  @gopaths
end

#homeObject (readonly)

Returns the value of attribute home.



5
6
7
# File 'lib/config.rb', line 5

def home
  @home
end

#jankedObject (readonly)

Returns the value of attribute janked.



5
6
7
# File 'lib/config.rb', line 5

def janked
  @janked
end

#janked_gopathObject (readonly)

Returns the value of attribute janked_gopath.



5
6
7
# File 'lib/config.rb', line 5

def janked_gopath
  @janked_gopath
end

#janked_gopathsObject (readonly)

Returns the value of attribute janked_gopaths.



5
6
7
# File 'lib/config.rb', line 5

def janked_gopaths
  @janked_gopaths
end

#janked_local_pathObject (readonly)

Returns the value of attribute janked_local_path.



5
6
7
# File 'lib/config.rb', line 5

def janked_local_path
  @janked_local_path
end

#janked_packgeObject (readonly)

Returns the value of attribute janked_packge.



5
6
7
# File 'lib/config.rb', line 5

def janked_packge
  @janked_packge
end

#local_gopathObject (readonly)

Returns the value of attribute local_gopath.



5
6
7
# File 'lib/config.rb', line 5

def local_gopath
  @local_gopath
end

#packageObject (readonly)

Returns the value of attribute package.



5
6
7
# File 'lib/config.rb', line 5

def package
  @package
end

#pwdObject (readonly)

Returns the value of attribute pwd.



5
6
7
# File 'lib/config.rb', line 5

def pwd
  @pwd
end

#rsyncObject (readonly)

Returns the value of attribute rsync.



5
6
7
# File 'lib/config.rb', line 5

def rsync
  @rsync
end