Class: Hollandaise::Project

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

Instance Method Summary collapse

Constructor Details

#initialize(project_name) ⇒ Project

Returns a new instance of Project.



8
9
10
# File 'lib/hollandaise/project.rb', line 8

def initialize(project_name)
  @project_name = project_name
end

Instance Method Details

#browsers(*browsers) ⇒ Object



66
67
68
# File 'lib/hollandaise/project.rb', line 66

def browsers(*browsers)
  @browsers = browsers
end

#portObject



16
17
18
# File 'lib/hollandaise/project.rb', line 16

def port
  32516
end

#proxy_root(root) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/hollandaise/project.rb', line 20

def proxy_root(root)
  uri = URI(root)

  @userinfo = uri.userinfo
  @host = uri.host
  @port = uri.port

  @root = "http://localhost:#{port}#{uri.path}"
end

#root(root) ⇒ Object



12
13
14
# File 'lib/hollandaise/project.rb', line 12

def root(root)
  @root = root
end

#runObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/hollandaise/project.rb', line 74

def run
  puts "Running #{@project_name}".foreground(:green)
  with_proxy do
    urls.each do |url, name|
      puts "... #{name} (#{url})".foreground(:yellow)

      Hollandaise.chdir "#{@project_name}/#{name}" do
        browser_objects.run do |browser|
          puts "     ... #{browser.name}".foreground(:white)
          browser.run_and_take_screenshot(url, @screen_size)
        end
      end
    end
  end
end

#screen_size(size) ⇒ Object



70
71
72
# File 'lib/hollandaise/project.rb', line 70

def screen_size(size)
  @screen_size = size.split('x').collect(&:to_i)
end

#screenshot(name, uri) ⇒ Object



60
61
62
63
64
# File 'lib/hollandaise/project.rb', line 60

def screenshot(name, uri)
  @screenshots ||= []

  @screenshots << [ name, uri ]
end

#with_proxyObject



30
31
32
33
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
# File 'lib/hollandaise/project.rb', line 30

def with_proxy
  if !@host
    yield
  else
    proxy = Class.new(Rack::Proxy) do
      def initialize(userinfo, host, port)
        @userinfo, @host, @port = userinfo, host, port
      end

      def rewrite_env(env)
        env['HTTP_HOST'] = @host
        env['SERVER_PORT'] = @port
        env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64(@userinfo)}"

        env
      end
    end

    server = Thread.new do
      Rack::Handler.default.run(proxy.new(@userinfo, @host, @port), :Port => port) do |server|
        Thread.current[:server] = server
      end
    end

    yield

    server[:server].stop
  end
end