Class: JBundler::Config

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

Overview

allow yaml config in $HOME/.jbundlerrc and $PWD/.jbundlerrc

Constant Summary collapse

RC_FILE =
'.jbundlerrc'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jbundler/config.rb', line 33

def initialize
  if ENV.has_key? 'HOME'
    homefile = File.join(ENV['HOME'], RC_FILE)
    home_config = YAML.load_file(homefile) if File.exists?(homefile)
  else
    home_config = nil
  end
  @config = (home_config || {})
  @basedir = find_basedir( File.expand_path( '.' ) )
  @basedir ||= File.expand_path( '.' )
  file = join_basedir( RC_FILE )
  pwd_config = YAML.load_file(file) if File.exists?(file)
  @config.merge!(pwd_config || {})
end

Instance Attribute Details

#basedirObject

Returns the value of attribute basedir.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def basedir
  @basedir
end

#gemfileObject

Returns the value of attribute gemfile.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def gemfile
  @gemfile
end

#jarfileObject

Returns the value of attribute jarfile.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def jarfile
  @jarfile
end

#local_repositoryObject

Returns the value of attribute local_repository.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def local_repository
  @local_repository
end

#offlineObject

Returns the value of attribute offline.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def offline
  @offline
end

#settingsObject

Returns the value of attribute settings.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def settings
  @settings
end

#skipObject

Returns the value of attribute skip.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def skip
  @skip
end

#vendor_dirObject

Returns the value of attribute vendor_dir.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def vendor_dir
  @vendor_dir
end

#verboseObject

Returns the value of attribute verbose.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def verbose
  @verbose
end

#work_dirObject

Returns the value of attribute work_dir.



31
32
33
# File 'lib/jbundler/config.rb', line 31

def work_dir
  @work_dir
end

Instance Method Details

#absolute(file) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/jbundler/config.rb', line 69

def absolute( file )
  if file.nil? || file == File.expand_path( file )
    file
  else
    File.join( @basedir, file )
  end
end

#classpath_fileObject



131
132
133
134
# File 'lib/jbundler/config.rb', line 131

def classpath_file
  absolute( jbundler_env('JBUNDLE_CLASSPATH_FILE') ||
            '.jbundler/classpath.rb' )
end

#find_basedir(dir) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/jbundler/config.rb', line 56

def find_basedir( dir )
  f = File.join( dir, RC_FILE )
  return dir if File.exists?( f )
  f = File.join( dir, _jarfile )
  return dir if File.exists?( f )
  f = File.join( dir, _gemfile )
  return dir if File.exists?( f )
  parent = File.dirname( dir )
  if dir != ENV['HOME'] && dir != parent
    find_basedir( parent )
  end
end

#gemfile_lockObject



127
128
129
# File 'lib/jbundler/config.rb', line 127

def gemfile_lock
  "#{gemfile}.lock"
end

#jarfile_lockObject



114
115
116
# File 'lib/jbundler/config.rb', line 114

def jarfile_lock
  "#{jarfile}.lock"
end

#join_basedir(path) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/jbundler/config.rb', line 48

def join_basedir( path )
  if @basedir
    File.join( @basedir, path )
  else
    path
  end
end

#mirrorObject



171
172
173
174
175
176
177
178
179
# File 'lib/jbundler/config.rb', line 171

def mirror
  @mirror ||= jbundler_env('JBUNDLE_MIRROR')
  # nice to have no leading slash
  @mirror = @mirror.sub( /\/$/, '' ) if @mirror
  if @mirror
    warn 'mirror config is deprecated, use settings.xml instead'
  end
  @mirror
end

#proxyObject



163
164
165
166
167
168
169
# File 'lib/jbundler/config.rb', line 163

def proxy
  @proxy ||= jbundler_env('JBUNDLE_PROXY')
  if @proxy
    warn 'proxy config is deprecated, use settings.xml instead'
  end
  @proxy
end