Class: LitmusPaper::Dependency::FileContents
- Inherits:
-
Object
- Object
- LitmusPaper::Dependency::FileContents
- Defined in:
- lib/litmus_paper/dependency/file_contents.rb
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#initialize(path, regex, options = {}) ⇒ FileContents
constructor
A new instance of FileContents.
- #to_s ⇒ Object
Constructor Details
#initialize(path, regex, options = {}) ⇒ FileContents
Returns a new instance of FileContents.
4 5 6 7 8 |
# File 'lib/litmus_paper/dependency/file_contents.rb', line 4 def initialize(path, regex, = {}) @path = path @regex = regex @timeout = .fetch(:timeout, 5) end |
Instance Method Details
#available? ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/litmus_paper/dependency/file_contents.rb', line 10 def available? Timeout.timeout(@timeout) do if File.read(@path).match(@regex) true else LitmusPaper.logger.info("Available check of #{@path} failed, content did not match #{@regex.inspect}") false end end rescue Timeout::Error LitmusPaper.logger.info("Timeout reading #{@path}") false rescue => e LitmusPaper.logger.info("Error reading #{@path}: '#{e.}'") false end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/litmus_paper/dependency/file_contents.rb', line 27 def to_s "Dependency::FileContents(#{@path}, #{@regex.inspect})" end |