Class: RightScraper::Scanners::Base

Inherits:
Object
  • Object
show all
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.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Create a new Scanner. Recognizes options as given. Some options may be required, others optional. This class recognizes only :logger.

Options ===

:logger

Optional. Logger currently being used

Parameters ===

options(Hash)

scanner options



61
62
63
# File 'lib/right_scraper/scanners/base.rb', line 61

def initialize(options={})
  @logger = options.fetch(:logger, RightScraper::Logger.new)
end

Instance Method Details

#begin(resource) ⇒ Object

Begin a scan for the given resource.

Parameters ===

resource(RightScraper::Resource::Base)

resource to scan



74
75
# File 'lib/right_scraper/scanners/base.rb', line 74

def begin(resource)
end

#end(resource) ⇒ Object

Finish a scan for the given resource.

Parameters ===

resource(RightScraper::Resource::Base)

resource that just finished

scanning


82
83
# File 'lib/right_scraper/scanners/base.rb', line 82

def end(resource)
end

#finishObject

Notification that all scans for this repository have completed.



67
68
# File 'lib/right_scraper/scanners/base.rb', line 67

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



94
95
# File 'lib/right_scraper/scanners/base.rb', line 94

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



106
107
108
# File 'lib/right_scraper/scanners/base.rb', line 106

def notice_dir(relative_position)
  true
end