Class: RightScraper::Resources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/right_scraper/resources/base.rb

Overview

Localized representation of a resource. Contains the resource contents, and the metadata as a hash. A resource at its core is any abstraction that is statically represented by a set of files and directories and metadata.

The JSON metadata for the resource is in #metadata, and the manifest is in #manifest.

Direct Known Subclasses

Cookbook, Workflow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, pos) ⇒ Base

Create a new resource from the given parameters.

Parameters

repo(Repositories::Base)

Repository containing this resource



55
56
57
58
# File 'lib/right_scraper/resources/base.rb', line 55

def initialize(repo, pos)
  @repository = repo
  @pos = pos
end

Instance Attribute Details

#manifestObject

(Hash) Manifest for resource. A hash of path => SHA-1 digests.



46
47
48
# File 'lib/right_scraper/resources/base.rb', line 46

def manifest
  @manifest
end

#metadataObject

(Hash) Metadata from the resource.



43
44
45
# File 'lib/right_scraper/resources/base.rb', line 43

def 
  @metadata
end

#posObject

(String) Position in the repository.



49
50
51
# File 'lib/right_scraper/resources/base.rb', line 49

def pos
  @pos
end

#repositoryObject (readonly)

(Repositories::Base) Repository the resource was fetched from.



40
41
42
# File 'lib/right_scraper/resources/base.rb', line 40

def repository
  @repository
end

Instance Method Details

#resource_hashObject

Resource hash

Return

hash(String)

Hexadecimal value that uniquely identifies this resource



64
65
66
# File 'lib/right_scraper/resources/base.rb', line 64

def resource_hash
  Digest::SHA1.hexdigest("#{PROTOCOL_VERSION}\000#{@repository.checkout_hash}\000#{@pos}")
end