Class: SeleniumSpider::CommandLine
- Inherits:
-
Object
- Object
- SeleniumSpider::CommandLine
- Defined in:
- lib/selenium_spider/command_line.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(options) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ CommandLine
Returns a new instance of CommandLine.
18 19 20 21 22 23 24 25 26 |
# File 'lib/selenium_spider/command_line.rb', line 18 def initialize() @options = if @options[:command] == 'run' run elsif @options[:command] == 'generate' generate end end |
Class Method Details
.execute(options) ⇒ Object
14 15 16 |
# File 'lib/selenium_spider/command_line.rb', line 14 def self.execute() new() end |
Instance Method Details
#generate ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/selenium_spider/command_line.rb', line 46 def generate mkdir_if_not_exist './app/models/' mkdir_if_not_exist './app/paginations/' mkdir_if_not_exist './app/controllers/' gem_root = File.('../', __FILE__) generation_path = "#{gem_root}/generations" generate_class "#{generation_path}/model.rb.erb", "./app/models/#{@options[:site]}.rb" generate_class "#{generation_path}/pagination.rb.erb", "./app/paginations/#{@options[:site]}_pagination.rb" generate_class "#{generation_path}/controller.rb.erb", "./app/controllers/#{@options[:site]}_controller.rb" end |
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/selenium_spider/command_line.rb', line 28 def run if @options[:headless] headless = Headless.new(reuse: false, destroy_at_exit: true) headless.start end require "models/#{@options[:site]}" require "paginations/#{@options[:site]}_pagination" require "controllers/#{@options[:site]}_controller" class_name = @options[:site].classify + 'Controller' Object.const_get(class_name).new.run if @options[:headless] headless.destroy end end |