Class: Composer::Package::Dumper::HashDumper
- Inherits:
- 
      Object
      
        - Object
- Composer::Package::Dumper::HashDumper
 
- Defined in:
- lib/composer/package/dumper/hash_dumper.rb
Overview
Dumps a hash from a package
PHP Authors: Konstantin Kudryashiv <[email protected]> Jordi Boggiano <[email protected]>
Ruby Authors: Ioannis Kappas <[email protected]>
Instance Method Summary collapse
Instance Method Details
#dump(package) ⇒ Object
| 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | # File 'lib/composer/package/dumper/hash_dumper.rb', line 24 def dump(package) keys = { 'binaries' => 'bin', 'type' => 'type', 'extra' => 'extra', 'installation_source' => 'installation-source', 'autoload' => 'autoload', 'dev_autoload' => 'autoload-dev', 'notification_url' => 'notification-url', 'include_paths' => 'include-path', } data = {} data['name'] = package.pretty_name data['version'] = package.pretty_version data['version_normalized'] = package.version if package.target_dir data['target-dir'] = package.target_dir end if package.source_type data['source'] = {} data['source']['type'] = package.source_type data['source']['url'] = package.source_url data['source']['reference'] = package.source_reference if mirrors = package.source_mirrors data['source']['mirrors'] = mirrors end end if package.dist_type data['dist'] = {} data['dist']['type'] = package.dist_type data['dist']['url'] = package.dist_url data['dist']['reference'] = package.dist_reference data['dist']['shasum'] = package.dist_sha1_checksum if mirrors = package.dist_mirrors data['dist']['mirrors'] = mirrors end end unless package.archive_excludes.nil? || package.archive_excludes.empty? data['archive'] = {} data['archive']['exclude'] = package.archive_excludes end Composer::Package::BasePackage::SUPPORTED_LINK_TYPES.each do |type, opts| next unless links = package.send(opts['method']) next if links.nil? next if links.is_a?(Array) && links.empty? next if links.is_a?(Hash) && links.empty? data[type] = {} unless data.key?(type) values = links.is_a?(Hash) ? links.values : links values.each do |link| data[type][link.target] = link.pretty_constraint end data[type].keys.sort.each do |k| data[type][k] = data[type].delete k end end if packages = package.suggests unless packages.nil? || packages.empty? packages.keys.sort.each do |k| packages[k] = packages.delete k end data['suggest'] = packages end end if package.release_date && !package.release_date.nil? data['time'] = package.release_date.strftime('%Y-%m-%d %H:%M:%S') end data = dump_values(package, keys, data) # if data.key?('type') && data['type'] === 'library' # data.delete('type') # end if package.is_a?(Composer::Package::CompletePackage) keys = %w{scripts license authors description homepage keywords repositories support} data = dump_values(package, keys, data) if data.key?('keywords') && is_array?(data, 'keywords') data['keywords'].sort! end if package.is_abandoned? replacement = package.replacement_package data['abandoned'] = replacement ? replacement : true end end if package.is_a?(Composer::Package::RootPackage) minimum_stability = package.minimum_stability unless minimum_stability.nil? || minimum_stability.empty? data['minimum-stability'] = minimum_stability end end if !package..nil? && package..length > 0 data['transport-options'] = package. end data end |