Class: BrowserShooter::Configurator
- Inherits:
-
Object
- Object
- BrowserShooter::Configurator
- Defined in:
- lib/browser_shooter/configurator.rb
Instance Attribute Summary collapse
-
#suites ⇒ Object
readonly
Returns the value of attribute suites.
Class Method Summary collapse
- .build_models(config) ⇒ Object
- .filter_suites(models, opts) ⇒ Object
- .load_config(config_file_path) ⇒ Object
- .load_extensions(extensions_paths) ⇒ Object
- .setup_output_path(output_path) ⇒ Object
- .timestamp ⇒ Object
Instance Method Summary collapse
- #[](value) ⇒ Object
-
#initialize(opts) ⇒ Configurator
constructor
A new instance of Configurator.
Constructor Details
#initialize(opts) ⇒ Configurator
Returns a new instance of Configurator.
5 6 7 8 9 10 11 |
# File 'lib/browser_shooter/configurator.rb', line 5 def initialize( opts ) @config = BrowserShooter::Configurator.load_config( opts[:config_file] ) models = BrowserShooter::Configurator.build_models( @config ) @suites = BrowserShooter::Configurator.filter_suites( models, opts ) BrowserShooter::Configurator.load_extensions( @config["extensions"] ) if @config["extensions"] end |
Instance Attribute Details
#suites ⇒ Object (readonly)
Returns the value of attribute suites.
3 4 5 |
# File 'lib/browser_shooter/configurator.rb', line 3 def suites @suites end |
Class Method Details
.build_models(config) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/browser_shooter/configurator.rb', line 52 def self.build_models( config ) tests = config["tests"].map do |name, commands| test_commands = commands.split( "\n" ) BrowserShooter::Models::Test.new( name, test_commands ) end browsers = config["browsers"].map do |name, opts| BrowserShooter::Models::Browser.new( name, opts["url"], opts["type"], opts["vm"] ) end suites = config["suites"].map do |name, opts| suite_tests = tests.select{ |e| opts["tests"].include? e.name } suite_browsers = browsers.select{ |e| opts["browsers"].include? e.name } BrowserShooter::Models::Suite.new( name, suite_tests, suite_browsers ) end { :tests => tests, :browsers => browsers, :suites => suites } end |
.filter_suites(models, opts) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/browser_shooter/configurator.rb', line 17 def self.filter_suites( models, opts ) suites = [] if( opts[:suite] ) suite = models[:suites].select{ |e| e.name == opts[:suite] }.first raise ArgumentError, "Not suite found '#{opts[:suite]}'" if suite.nil? suites = [suite] elsif( opts[:test] && opts[:browsers] ) test = models[:tests].select{ |e| e.name == opts[:test] }.first raise ArgumentError, "Not test found '#{opts[:test]}'" if test.nil? browsers = models[:browsers].select{ |e| opts[:browsers].include? e.name } raise ArgumentError, "Not browsers found '#{opts[:browsers].join( "," )}'" if browsers.empty? suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers ) suites = [suite] elsif( opts[:test] ) test = models[:tests].select{ |e| e.name == opts[:test] }.first raise ArgumentError, "Not test found '#{opts[:test]}'" if test.nil? browsers = models[:browsers] suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers ) suites = [suite] else suites = models[:suites] end suites end |
.load_config(config_file_path) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/browser_shooter/configurator.rb', line 80 def self.load_config( config_file_path ) config = { "output_path" => "~/browser_shooter" } config.merge! YAML.load_file( config_file_path ) config["output_path"] = setup_output_path( config["output_path"] ) config end |
.load_extensions(extensions_paths) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/browser_shooter/configurator.rb', line 99 def self.load_extensions( extensions_paths ) extensions_paths.each do |extension_path| extension_path = File.( extension_path ) BrowserShooter::Logger.log( "Loading extension: #{extension_path}" ) Kernel.require( extension_path ) end end |
.setup_output_path(output_path) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/browser_shooter/configurator.rb', line 92 def self.setup_output_path( output_path ) output_path = File.( "#{output_path}/#{}" ) BrowserShooter::Logger.log( "output_path: #{output_path}" ) output_path end |
.timestamp ⇒ Object
107 108 109 |
# File 'lib/browser_shooter/configurator.rb', line 107 def self. Time.now.strftime("%Y%m%d%H%M%S") end |
Instance Method Details
#[](value) ⇒ Object
13 14 15 |
# File 'lib/browser_shooter/configurator.rb', line 13 def [](value) @config[value] end |