Class: Licensed::Source::Stack
- Inherits:
-
Object
- Object
- Licensed::Source::Stack
- Defined in:
- lib/licensed/source/stack.rb
Instance Method Summary collapse
- #dependencies ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(config) ⇒ Stack
constructor
A new instance of Stack.
- #list_packages_command ⇒ Object
- #package_info(package_id) ⇒ Object
- #package_info_command(package_id) ⇒ Object
- #packages ⇒ Object
- #safe_homepage(homepage) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(config) ⇒ Stack
Returns a new instance of Stack.
4 5 6 |
# File 'lib/licensed/source/stack.rb', line 4 def initialize(config) @config = config end |
Instance Method Details
#dependencies ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/licensed/source/stack.rb', line 16 def dependencies @dependencies ||= packages.map do |(name, version)| package_id = "#{name}-#{version}" package = package_info package_id if package.empty? next if @config.ignored?('type' => type, 'name' => name) raise "couldn't locate #{package_id} with ghc-pkg" end path = package["haddock-html"] || File.join(@config.pwd, "vendor", name) Dependency.new(path, { "type" => type, "name" => package["name"] || name, "version" => package["version"] || version, "summary" => package["synopsis"], "homepage" => safe_homepage(package["homepage"]) }) end.compact end |
#enabled? ⇒ Boolean
12 13 14 |
# File 'lib/licensed/source/stack.rb', line 12 def enabled? @config.enabled?(type) && File.exist?(@config.pwd.join("stack.yaml")) end |
#list_packages_command ⇒ Object
48 49 50 |
# File 'lib/licensed/source/stack.rb', line 48 def list_packages_command `stack list-dependencies --no-include-base` end |
#package_info(package_id) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/licensed/source/stack.rb', line 52 def package_info(package_id) package_info_command(package_id).lines.each_with_object({}) do |line, info| key, value = line.split(':', 2).map(&:strip) next unless key && value info[key] = value end end |
#package_info_command(package_id) ⇒ Object
61 62 63 |
# File 'lib/licensed/source/stack.rb', line 61 def package_info_command(package_id) `stack exec -- ghc-pkg field #{package_id} name,version,synopsis,homepage,haddock-html 2>/dev/null` end |
#packages ⇒ Object
44 45 46 |
# File 'lib/licensed/source/stack.rb', line 44 def packages list_packages_command.lines.map(&:split) end |
#safe_homepage(homepage) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/licensed/source/stack.rb', line 37 def safe_homepage(homepage) return unless homepage # use https and remove url fragment homepage.gsub(/http:/, "https:") .gsub(/#[^?]*\z/, "") end |
#type ⇒ Object
8 9 10 |
# File 'lib/licensed/source/stack.rb', line 8 def type "stack" end |