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
Creates the tests, browsers and suites arrays.
-
.filter_suites(models, opts) ⇒ Object
If special filter options has been defined in the _command options_ the suites are filtered to only play with the filtered ones.
-
.load_config(config_file_path) ⇒ Object
Load the config.yml file and return it in a Hash format.
- .load_extensions(extensions_paths) ⇒ Object
- .setup_output_path(output_path) ⇒ Object
Instance Method Summary collapse
-
#[](value) ⇒ Object
The hash version of the config.yml is available here.
-
#initialize(opts) ⇒ Configurator
constructor
Takes the digested command options and create and filter the models.
Constructor Details
#initialize(opts) ⇒ Configurator
Takes the digested command options and create and filter the models
6 7 8 9 10 11 12 |
# File 'lib/browser_shooter/configurator.rb', line 6 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
Creates the tests, browsers and suites arrays.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/browser_shooter/configurator.rb', line 34 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 = BrowserShooter::Utils.find_by_names( tests, opts["tests"] ) suite_browsers = BrowserShooter::Utils.find_by_names( browsers, opts["browsers"] ) BrowserShooter::Models::Suite.new( name, suite_tests, suite_browsers ) end { :tests => tests, :browsers => browsers, :suites => suites } end |
.filter_suites(models, opts) ⇒ Object
If special filter options has been defined in the _command options_ the suites are filtered to only play with the filtered ones.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/browser_shooter/configurator.rb', line 64 def self.filter_suites( models, opts ) suites = [] if( opts[:suite] ) suite = BrowserShooter::Utils.find_by_name( models[:suites], opts[:suite] ) suites = [suite] elsif( opts[:test] && opts[:browsers] ) test = BrowserShooter::Utils.find_by_name( models[:tests], opts[:test] ) browsers = BrowserShooter::Utils.find_by_names( models[:browsers], opts[:browsers] ) suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers ) suites = [suite] elsif( opts[:test] ) test = BrowserShooter::Utils.find_by_name( models[:tests], opts[:test] ) 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
Load the config.yml file and return it in a Hash format
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/browser_shooter/configurator.rb', line 20 def self.load_config( config_file_path ) config = { "output_path" => "~/browser_shooter", "timeout" => 40 } config.merge! YAML.load_file( config_file_path ) config["output_path"] = setup_output_path( config["output_path"] ) config end |
.load_extensions(extensions_paths) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/browser_shooter/configurator.rb', line 101 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
94 95 96 97 98 99 |
# File 'lib/browser_shooter/configurator.rb', line 94 def self.setup_output_path( output_path ) output_path = File.( "#{output_path}/#{BrowserShooter::Utils.}" ) BrowserShooter::Logger.log( "output_path: #{output_path}" ) output_path end |
Instance Method Details
#[](value) ⇒ Object
The hash version of the config.yml is available here
15 16 17 |
# File 'lib/browser_shooter/configurator.rb', line 15 def [](value) @config[value] end |