Class: Bashly::LibrarySource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil) ⇒ LibrarySource

Returns a new instance of LibrarySource.



7
8
9
10
# File 'lib/bashly/library_source.rb', line 7

def initialize(uri = nil)
  @uri = uri || File.expand_path('libraries', __dir__)
  transform_github_uri if /^github(:|-)/.match? @uri
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#cleanupObject



35
36
37
# File 'lib/bashly/library_source.rb', line 35

def cleanup
  FileUtils.rm_rf(File.join(Dir.tmpdir, 'bashly-libs-*'))
end

#configObject



16
17
18
# File 'lib/bashly/library_source.rb', line 16

def config
  @config ||= YAML.load_file config_path
end

#config_pathObject



27
28
29
30
31
32
33
# File 'lib/bashly/library_source.rb', line 27

def config_path
  @config_path ||= if File.exist?("#{path}/libraries.yml")
    "#{path}/libraries.yml"
  else
    raise "Cannot find #{path}/libraries.yml"
  end
end

#git?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/bashly/library_source.rb', line 12

def git?
  /^(git|github|github-ssh):/.match? uri
end

#librariesObject



20
21
22
23
24
25
# File 'lib/bashly/library_source.rb', line 20

def libraries
  config.to_h do |name, spec|
    upgrade_string = "#{uri};#{name}"
    [name.to_sym, Library.new(path, spec, upgrade_string: upgrade_string)]
  end
end