Class: Wraith::Validate
- Inherits:
-
Object
- Object
- Wraith::Validate
- Includes:
- Logging
- Defined in:
- lib/wraith/validate.rb
Instance Attribute Summary collapse
-
#wraith ⇒ Object
readonly
Returns the value of attribute wraith.
Instance Method Summary collapse
- #docs_prompt ⇒ Object
-
#initialize(config, options = {}) ⇒ Validate
constructor
A new instance of Validate.
- #validate(mode = false) ⇒ Object
- #validate_base_shots_exist ⇒ Object
- #validate_basic_properties ⇒ Object
- #validate_capture_mode ⇒ Object
- #validate_history_mode ⇒ Object
- #validate_mode_properties(mode) ⇒ Object
- #validate_spider_mode ⇒ Object
Methods included from Logging
Constructor Details
Instance Attribute Details
#wraith ⇒ Object (readonly)
Returns the value of attribute wraith.
7 8 9 |
# File 'lib/wraith/validate.rb', line 7 def wraith @wraith end |
Instance Method Details
#docs_prompt ⇒ Object
75 76 77 |
# File 'lib/wraith/validate.rb', line 75 def docs_prompt "See the docs at http://bbc-news.github.io/wraith/" end |
#validate(mode = false) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/wraith/validate.rb', line 13 def validate(mode = false) list_debug_information if wraith.verbose validate_basic_properties validate_mode_properties(mode) if mode # if we get this far, we've only had warnings at worst, not errors. "Config validated. No serious issues found." end |
#validate_base_shots_exist ⇒ Object
69 70 71 72 73 |
# File 'lib/wraith/validate.rb', line 69 def validate_base_shots_exist unless File.directory?(wraith.history_dir) logger.error "You need to run `wraith history` at least once before you can run `wraith latest`!" end end |
#validate_basic_properties ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/wraith/validate.rb', line 21 def validate_basic_properties fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil? fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil? # @TODO validate fuzz is not nil, etc end |
#validate_capture_mode ⇒ Object
47 48 49 50 51 52 |
# File 'lib/wraith/validate.rb', line 47 def validate_capture_mode fail InvalidDomainsError, "`wraith capture` requires exactly two domains. #{docs_prompt}" if wraith.domains.length != 2 logger.warn "You have specified a `history_dir` in your config, but this is"\ " used in `history` mode, NOT `capture` mode. #{docs_prompt}" if wraith.history_dir end |
#validate_history_mode ⇒ Object
54 55 56 57 58 59 |
# File 'lib/wraith/validate.rb', line 54 def validate_history_mode fail MissingRequiredPropertyError, "You must specify a `history_dir` to run"\ " Wraith in history mode. #{docs_prompt}" unless wraith.history_dir fail InvalidDomainsError, "History mode requires exactly one domain. #{docs_prompt}" if wraith.domains.length != 1 end |
#validate_mode_properties(mode) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wraith/validate.rb', line 31 def validate_mode_properties(mode) case mode when "capture" validate_capture_mode when "history" validate_history_mode when "latest" validate_history_mode validate_base_shots_exist when "spider" validate_spider_mode else logger.warn "Wraith doesn't know how to validate mode '#{mode}'. Continuing..." end end |
#validate_spider_mode ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/wraith/validate.rb', line 61 def validate_spider_mode fail MissingRequiredPropertyError, "You must specify an `imports` YML"\ " before running `wraith spider`. #{docs_prompt}" unless wraith.imports #fail PropertyOutOfContextError, "Tried running `wraith spider` but you have already"\ # " specified paths in your YML. #{docs_prompt}" if wraith.paths end |