class Licensed::Sources::Mix
Constants
- LOCKFILE
Public Instance Methods
enabled?()
click to toggle source
Returns whether a mix.lock is present
# File lib/licensed/sources/mix.rb, line 10 def enabled? File.exist?(lockfile_path) end
enumerate_dependencies()
click to toggle source
# File lib/licensed/sources/mix.rb, line 14 def enumerate_dependencies find_packages.map do |package| convert_package_to_dependency(package) end end
Private Instance Methods
check_dep_path(pkg)
click to toggle source
Check that the package has been installed in deps/.
pkg - The package information as a Hash
Returns an Array with two members; the path as a String and an Array of any errors.
# File lib/licensed/sources/mix.rb, line 55 def check_dep_path(pkg) path = dep_path(pkg[:name]) if File.directory?(path) return [path, []] else return [path, ["Not installed by `mix deps.get` in deps/"]] end end
convert_package_to_dependency(pkg)
click to toggle source
Converts a raw package representation to a dependency.
name - The name of the package as a String. pkg - The parsed package data as a Hash.
Returns a Dependency
.
# File lib/licensed/sources/mix.rb, line 38 def convert_package_to_dependency(pkg) path, errors = check_dep_path(pkg) Dependency.new( name: pkg[:name], version: pkg[:version], path: path, metadata: pkg[:metadata].merge("type" => self.class.type), errors: errors + Array(pkg[:error]) ) end
dep_path(name)
click to toggle source
Generate the absolute path to the named package.
name - The name of the package dependency as a String.
Returns a Pathname.
# File lib/licensed/sources/mix.rb, line 69 def dep_path(name) config.pwd.join("deps", name) end
find_packages()
click to toggle source
Returns the parsed mix.lock information as an Array of Hash objects.
# File lib/licensed/sources/mix.rb, line 23 def find_packages LockfileParser.read(lockfile_path) end
lockfile_path()
click to toggle source
Returns the absolute path to the mix.lock as a Pathname.
# File lib/licensed/sources/mix.rb, line 28 def lockfile_path config.pwd.join(LOCKFILE) end