Module: Robro::UserScripts
- Defined in:
- lib/robro/user_scripts.rb
Defined Under Namespace
Classes: Base
Class Method Summary collapse
- .all ⇒ Object
- .all_commands ⇒ Object
- .execute(command, uri, *args) ⇒ Object
- .find_for(uri:) ⇒ Object
Class Method Details
.all ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/robro/user_scripts.rb', line 5 def self.all Dir.glob('userscripts/*.rb').map do |file| require File.(file) class_name = File.basename(file, '.rb').camelize const_get class_name end end |
.all_commands ⇒ Object
13 14 15 16 |
# File 'lib/robro/user_scripts.rb', line 13 def self.all_commands user_scripts = UserScripts.all.map(&:new) user_scripts.map(&:supported_url_commands).flatten.uniq end |
.execute(command, uri, *args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/robro/user_scripts.rb', line 23 def self.execute(command, uri, *args) us = find_for uri: uri raise "No user scripts found for URI: #{uri}" if us.nil? Robro.logger.info "Opening URL: #{uri}" Robro.browser.visit uri Robro.logger.info "User script: '#{us.class}' will process commnand '#{command}'" us.send(command, uri) end |
.find_for(uri:) ⇒ Object
18 19 20 21 |
# File 'lib/robro/user_scripts.rb', line 18 def self.find_for(uri:) user_scripts = UserScripts.all.map(&:new) user_scripts.find { |us| uri.host.start_with? *(us.supported_urls) } end |