Class: Licensed::Sources::Composer
- Inherits:
-
Source
- Object
- Source
- Licensed::Sources::Composer
show all
- Defined in:
- lib/licensed/sources/composer.rb
Constant Summary
collapse
- DEFAULT_COMPOSER_APPLICATON_PATH =
"composer.phar"
Instance Attribute Summary
Attributes inherited from Source
#config
Instance Method Summary
collapse
Methods inherited from Source
#dependencies, full_type, #ignored?, inherited, #initialize, register_source, require_matched_dependency_version, #source_config, type, type_and_version
Instance Method Details
#composer_application_path ⇒ Object
54
55
56
57
|
# File 'lib/licensed/sources/composer.rb', line 54
def composer_application_path
setting = config.dig("composer", "application_path") || DEFAULT_COMPOSER_APPLICATON_PATH
File.expand_path(setting, config.pwd)
end
|
#composer_lock ⇒ Object
59
60
61
|
# File 'lib/licensed/sources/composer.rb', line 59
def composer_lock
config.pwd.join("composer.lock")
end
|
#enabled? ⇒ Boolean
9
10
11
12
|
# File 'lib/licensed/sources/composer.rb', line 9
def enabled?
return false unless Licensed::Shell.tool_available?("php")
File.exist?(composer_lock) && File.exist?(composer_application_path)
end
|
#enumerate_dependencies ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/licensed/sources/composer.rb', line 14
def enumerate_dependencies
packages.map do |package|
Dependency.new(
name: package["name"],
version: package["version"],
path: package_paths[package["name"]],
metadata: {
"type" => Composer.type,
"name" => package["name"],
"summary" => package["description"],
"homepage" => package["homepage"]
}
)
end
end
|
#include_dev? ⇒ Boolean
Returns whether to include dev packages based on the licensed configuration settings
64
65
66
|
# File 'lib/licensed/sources/composer.rb', line 64
def include_dev?
config.dig("composer", "include_dev") == true
end
|
#package_paths ⇒ Object
Returns the output from running ‘php composer.phar` to get package metadata
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/licensed/sources/composer.rb', line 38
def package_paths
return @package_paths if defined?(@package_paths)
@package_paths = begin
output = Licensed::Shell.execute("php", composer_application_path, "show", "--format", "json", "--path", allow_failure: true)
return {} if output.to_s.empty?
path_json = JSON.parse(output)
return {} unless path_json["installed"]
path_json["installed"].each_with_object({}) do |package, hsh|
hsh[package["name"]] = package["path"]
end
end
end
|
#packages ⇒ Object
30
31
32
33
34
35
|
# File 'lib/licensed/sources/composer.rb', line 30
def packages
packages = JSON.parse(File.read(composer_lock))
return packages["packages"] unless include_dev?
packages["packages"] + packages["packages-dev"]
end
|