Class: Popart::Config
- Inherits:
-
Object
- Object
- Popart::Config
- Defined in:
- lib/popart/config.rb
Instance Attribute Summary collapse
-
#browsers ⇒ Object
Returns the value of attribute browsers.
-
#output_directory ⇒ Object
Returns the value of attribute output_directory.
-
#site ⇒ Object
Returns the value of attribute site.
-
#thread_count ⇒ Object
Returns the value of attribute thread_count.
Instance Method Summary collapse
- #default_browsers ⇒ Object
- #default_output_directory ⇒ Object
- #default_thread_count ⇒ Object
- #initial_config ⇒ Object
- #load_from_file(filename) ⇒ Object
- #set_defaults ⇒ Object
- #set_site(site) ⇒ Object
- #verify_output_directory ⇒ Object
Instance Attribute Details
#browsers ⇒ Object
Returns the value of attribute browsers.
7 8 9 |
# File 'lib/popart/config.rb', line 7 def browsers @browsers end |
#output_directory ⇒ Object
Returns the value of attribute output_directory.
7 8 9 |
# File 'lib/popart/config.rb', line 7 def output_directory @output_directory end |
#site ⇒ Object
Returns the value of attribute site.
7 8 9 |
# File 'lib/popart/config.rb', line 7 def site @site end |
#thread_count ⇒ Object
Returns the value of attribute thread_count.
7 8 9 |
# File 'lib/popart/config.rb', line 7 def thread_count @thread_count end |
Instance Method Details
#default_browsers ⇒ Object
9 10 11 12 13 14 |
# File 'lib/popart/config.rb', line 9 def default_browsers [ {"browserName" => 'Chrome', "platform" => "Windows 10", "version" => "latest"}, {"browserName" => 'Firefox', "platform" => "Windows 10", "version" => "latest"} ] end |
#default_output_directory ⇒ Object
16 17 18 |
# File 'lib/popart/config.rb', line 16 def default_output_directory './screenshots' end |
#default_thread_count ⇒ Object
20 21 22 |
# File 'lib/popart/config.rb', line 20 def default_thread_count 5 end |
#initial_config ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/popart/config.rb', line 24 def initial_config fn = ARGV[1] ||= './config.json' path = Pathname.new fn load_from_file path if path.exist? set_defaults end |
#load_from_file(filename) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/popart/config.rb', line 33 def load_from_file filename filedata = File.read filename config_hash = YAML.load(filedata) @browsers = [config_hash["browsers"]].flatten @output_directory = config_hash["output_directory"] @site = config_hash["site"] @thread_count = config_hash["thread_count"] end |
#set_defaults ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/popart/config.rb', line 43 def set_defaults @browsers ||= default_browsers @output_directory ||= default_output_directory @thread_count ||= default_thread_count set_site(@site ||= ARGV[0]) @output_directory = Pathname.new @output_directory verify_output_directory end |
#set_site(site) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/popart/config.rb', line 54 def set_site site unless site STDERR.puts "You must provide a site to screenshot." exit end @site = URI site end |
#verify_output_directory ⇒ Object
64 65 66 67 68 69 |
# File 'lib/popart/config.rb', line 64 def verify_output_directory unless @output_directory.exist? STDERR.puts "#{@output_directory} doesn't seem to exist; creating it." Dir.mkdir @output_directory end end |