Class: Pray::PackageSpec

Inherits:
Struct
  • Object
show all
Defined in:
lib/pray/package_spec.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: "", version: "", summary: nil, description: nil, authors: [], license: nil, homepage: nil, source_code_uri: nil, changelog_uri: nil, prayfile_version: nil, files: [], exports: {}, skills: {}, templates: {}, adapters: {}, targets: [], dependencies: [], metadata: {}) ⇒ PackageSpec

Returns a new instance of PackageSpec.



18
19
20
21
22
23
24
25
# File 'lib/pray/package_spec.rb', line 18

def initialize(
  name: "", version: "", summary: nil, description: nil, authors: [], license: nil,
  homepage: nil, source_code_uri: nil, changelog_uri: nil, prayfile_version: nil,
  files: [], exports: {}, skills: {}, templates: {}, adapters: {}, targets: [],
  dependencies: [], metadata: {}
)
  super
end

Instance Attribute Details

#adaptersObject

Returns the value of attribute adapters

Returns:

  • (Object)

    the current value of adapters



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def adapters
  @adapters
end

#authorsObject

Returns the value of attribute authors

Returns:

  • (Object)

    the current value of authors



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def authors
  @authors
end

#changelog_uriObject

Returns the value of attribute changelog_uri

Returns:

  • (Object)

    the current value of changelog_uri



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def changelog_uri
  @changelog_uri
end

#dependenciesObject

Returns the value of attribute dependencies

Returns:

  • (Object)

    the current value of dependencies



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def dependencies
  @dependencies
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def description
  @description
end

#exportsObject

Returns the value of attribute exports

Returns:

  • (Object)

    the current value of exports



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def exports
  @exports
end

#filesObject

Returns the value of attribute files

Returns:

  • (Object)

    the current value of files



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def files
  @files
end

#homepageObject

Returns the value of attribute homepage

Returns:

  • (Object)

    the current value of homepage



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def homepage
  @homepage
end

#licenseObject

Returns the value of attribute license

Returns:

  • (Object)

    the current value of license



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def license
  @license
end

#metadataObject

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def 
  @metadata
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def name
  @name
end

#prayfile_versionObject

Returns the value of attribute prayfile_version

Returns:

  • (Object)

    the current value of prayfile_version



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def prayfile_version
  @prayfile_version
end

#skillsObject

Returns the value of attribute skills

Returns:

  • (Object)

    the current value of skills



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def skills
  @skills
end

#source_code_uriObject

Returns the value of attribute source_code_uri

Returns:

  • (Object)

    the current value of source_code_uri



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def source_code_uri
  @source_code_uri
end

#summaryObject

Returns the value of attribute summary

Returns:

  • (Object)

    the current value of summary



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def summary
  @summary
end

#targetsObject

Returns the value of attribute targets

Returns:

  • (Object)

    the current value of targets



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def targets
  @targets
end

#templatesObject

Returns the value of attribute templates

Returns:

  • (Object)

    the current value of templates



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def templates
  @templates
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



13
14
15
# File 'lib/pray/package_spec.rb', line 13

def version
  @version
end

Class Method Details

.tree_hash_from_file_bytes(file_bytes) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/pray/package_spec.rb', line 48

def self.tree_hash_from_file_bytes(file_bytes)
  entries = file_bytes.map { |path, bytes| [path, Hashing.sha256_prefixed(bytes)] }.sort_by(&:first)
  serialized = entries.map do |path, hash|
    "file\0regular\0#{path}\0#{hash}\n"
  end.join
  Hashing.sha256_prefixed(serialized)
end

Instance Method Details

#canonicalizedObject



27
28
29
30
31
32
33
34
# File 'lib/pray/package_spec.rb', line 27

def canonicalized
  dup.tap do |copy|
    copy.files = files.sort
    copy.authors = authors.sort
    copy.targets = targets.sort
    copy.dependencies = dependencies.sort_by { |dependency| [dependency.name, dependency.constraint, dependency.optional] }
  end
end

#tree_hash_for_root(root) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pray/package_spec.rb', line 36

def tree_hash_for_root(root)
  file_bytes = {}
  files.each do |file|
    path = File.join(root, file)
    raise Error.integrity("package file missing: #{file}") unless File.exist?(path)
    raise Error.integrity("package file is a directory: #{file}") if File.directory?(path)

    file_bytes[file] = File.binread(path)
  end
  self.class.tree_hash_from_file_bytes(file_bytes)
end