class Licensed::Sources::Composer
Constants
- DEFAULT_COMPOSER_APPLICATON_PATH
Public Instance Methods
composer_application_path()
click to toggle source
# 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()
click to toggle source
# File lib/licensed/sources/composer.rb, line 59 def composer_lock config.pwd.join("composer.lock") end
enabled?()
click to toggle source
# 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()
click to toggle source
# 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?()
click to toggle source
Returns whether to include dev packages based on the licensed configuration settings
# File lib/licensed/sources/composer.rb, line 64 def include_dev? config.dig("composer", "include_dev") == true end
package_paths()
click to toggle source
Returns the output from running ‘php composer.phar` to get package metadata
# 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()
click to toggle source
# 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