Class: Zucchini::Config

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

Class Method Summary collapse

Class Method Details

.appObject



22
23
24
25
26
27
28
29
30
# File 'lib/config.rb', line 22

def self.app
  device_name = ENV['ZUCCHINI_DEVICE'] || @@default_device_name
  app_path    = File.absolute_path(devices[device_name]['app'] || @@config['app'] || ENV['ZUCCHINI_APP'])

  if device_name == 'iOS Simulator' && !File.exists?(app_path)
    raise "Can't find application at path #{app_path}"
  end
  app_path
end

.base_pathObject



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

def self.base_path
  @@base_path
end

.base_path=(base_path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/config.rb', line 10

def self.base_path=(base_path)
  @@base_path = base_path
  @@config    = YAML::load_file("#{base_path}/support/config.yml")
  @@default_device_name = nil
  devices.each do |device_name, device|
    if device['default']
      raise "Default device already provided" if @@default_device_name
      @@default_device_name = device_name
    end
  end
end

.default_device_nameObject



40
41
42
# File 'lib/config.rb', line 40

def self.default_device_name
  @@default_device_name
end

.device(device_name) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/config.rb', line 44

def self.device(device_name)
  device_name ||= @@default_device_name
  raise "Neither default device nor ZUCCHINI_DEVICE environment variable was set" unless device_name
  raise "Device not listed in config.yml" unless (device = devices[device_name])
  {
    :name   => device_name,
    :udid   => device['UDID'],
    :screen => device['screen']
  }
end

.devicesObject



36
37
38
# File 'lib/config.rb', line 36

def self.devices
  @@config['devices']
end

.resolution_name(dimension) ⇒ Object



32
33
34
# File 'lib/config.rb', line 32

def self.resolution_name(dimension)
  @@config['resolutions'][dimension.to_i]
end

.server(server_name) ⇒ Object



55
56
57
# File 'lib/config.rb', line 55

def self.server(server_name)
  @@config['servers'][server_name]
end

.url(server_name, href = "") ⇒ Object



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

def self.url(server_name, href="")
  server_config = server(server_name)
  port = server_config['port'] ? ":#{server_config['port']}" : ""

  "http://#{server_config['host']}#{port}#{href}"
end