Class: RightScraper::Scanners::Base
- Inherits:
-
Object
- Object
- RightScraper::Scanners::Base
- Defined in:
- lib/right_scraper/scanners/base.rb
Overview
Base class for scanning filesystems. Subclasses should override #notice and may override #new, #begin, #end and #notice_dir.
Overriding #new is useful for getting additional arguments. Overriding #begin allows you to do processing before the scan of a given resource begins; overriding #end allows you to do processing after it completes.
Most processing will occur in #notice, which notifies you that a file has been detected, and in #notice_dir. In #notice you are handed the relative position of the file from the start of the resource; so if you were scanning /a/resource
and noticed a file b/c
, #notice would be called with "b/c"
, even though the full pathname is /a/resource/b/c
. If you decide you need the actual data, #notice takes a block which will return that data to you if you yield
.
In #notice_dir you are handed the relative position of a directory. The return value determines whether you find the directory worth recursing into, or not–as an example, when looking for the metadata.json
file it is never necessary to descend past the topmost directory of the resource, but the same is not true when building a manifest.
Direct Known Subclasses
CookbookFilenameScanner, CookbookManifest, CookbookMetadata, CookbookS3Upload
Instance Method Summary collapse
-
#begin(resource) ⇒ Object
Begin a scan for the given resource.
-
#end(resource) ⇒ Object
Finish a scan for the given resource.
-
#finish ⇒ Object
Notification that all scans for this repository have completed.
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
-
#notice(relative_position) ⇒ Object
Notice a file during scanning.
-
#notice_dir(relative_position) ⇒ Object
Notice a directory during scanning.
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
57 58 59 60 61 |
# File 'lib/right_scraper/scanners/base.rb', line 57 def initialize(={}) unless @logger = [:logger] raise ::ArgumentError, ':logger is required' end end |
Instance Method Details
#begin(resource) ⇒ Object
Begin a scan for the given resource.
Parameters ===
- resource(RightScraper::Resource::Base)
-
resource to scan
72 73 |
# File 'lib/right_scraper/scanners/base.rb', line 72 def begin(resource) end |
#end(resource) ⇒ Object
Finish a scan for the given resource.
Parameters ===
- resource(RightScraper::Resource::Base)
-
resource that just finished
scanning
80 81 |
# File 'lib/right_scraper/scanners/base.rb', line 80 def end(resource) end |
#finish ⇒ Object
Notification that all scans for this repository have completed.
65 66 |
# File 'lib/right_scraper/scanners/base.rb', line 65 def finish end |
#notice(relative_position) ⇒ Object
Notice a file during scanning.
Block ===
Return the data for this file. We use a block because it may not always be necessary to read the data.
Parameters ===
- relative_position(String)
-
relative pathname for pathname from root of resource
92 93 |
# File 'lib/right_scraper/scanners/base.rb', line 92 def notice(relative_position) end |
#notice_dir(relative_position) ⇒ Object
Notice a directory during scanning. Returns true if the scanner should recurse into the directory (the default behavior)
Parameters ===
- relative_position(String)
-
relative pathname for the directory from root of resource
Returns ===
- Boolean
-
should the scanning recurse into the directory
104 105 106 |
# File 'lib/right_scraper/scanners/base.rb', line 104 def notice_dir(relative_position) true end |