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.



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

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.



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

def uri
  @uri
end

Instance Method Details

#cleanupObject



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

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

#configObject



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

def config
  @config ||= LibrarySourceConfig.new(config_path).validated_data
end

#config_pathObject



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

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)


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

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

#librariesObject



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

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