Class: Popart::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/popart/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#browsersObject

Returns the value of attribute browsers.



7
8
9
# File 'lib/popart/config.rb', line 7

def browsers
  @browsers
end

#output_directoryObject

Returns the value of attribute output_directory.



7
8
9
# File 'lib/popart/config.rb', line 7

def output_directory
  @output_directory
end

#siteObject

Returns the value of attribute site.



7
8
9
# File 'lib/popart/config.rb', line 7

def site
  @site
end

Instance Method Details

#default_browsersObject



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_directoryObject



16
17
18
# File 'lib/popart/config.rb', line 16

def default_output_directory
  './screenshots'
end

#initial_configObject



20
21
22
23
24
25
26
27
# File 'lib/popart/config.rb', line 20

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



29
30
31
32
33
34
35
36
# File 'lib/popart/config.rb', line 29

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"]
end

#set_defaultsObject



38
39
40
41
42
43
44
45
46
# File 'lib/popart/config.rb', line 38

def set_defaults
  @browsers ||= default_browsers
  @output_directory ||= default_output_directory
  set_site(@site ||= ARGV[0])

  @output_directory = Pathname.new @output_directory

  verify_output_directory
end

#set_site(site) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/popart/config.rb', line 48

def set_site site
  unless site
    STDERR.puts "You must provide a site to screenshot."
    exit
  end

  @site = URI site
end

#verify_output_directoryObject



58
59
60
61
62
63
# File 'lib/popart/config.rb', line 58

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