class Mirage::Client

Attributes

url[R]

Public Class Methods

new(options={:url => "http://localhost:7001"}) click to toggle source
# File lib/mirage/client/client.rb, line 12
def initialize options={:url => "http://localhost:7001"}, &block
  if options.is_a?(String) && options =~ URI.regexp
    @url = options
  elsif options.kind_of?(Hash) && options[:port]
    @url = "http://localhost:#{options[:port]}"
  elsif options.kind_of?(Hash) && options[:url]
    @url = options[:url]
  else
    raise "specify a valid URL or port"
  end

  @templates = Templates.new(@url)
  @templates.default_config &block if block
end

Public Instance Methods

==(client) click to toggle source
# File lib/mirage/client/client.rb, line 65
def == client
  client.instance_of?(Client) && self.url == client.url
end
clear() click to toggle source
# File lib/mirage/client/client.rb, line 61
def clear
  templates.delete_all
end
configure(&block) click to toggle source
# File lib/mirage/client/client.rb, line 27
def configure &block
  templates.default_config &block if block
end
prime() click to toggle source
# File lib/mirage/client/client.rb, line 45
def prime
  self.class.send(:put, "#{@url}/defaults", :body => "")
end
put(*args, &block) click to toggle source
# File lib/mirage/client/client.rb, line 57
def put *args, &block
  templates.put *args, &block
end
requests(id=nil) click to toggle source
# File lib/mirage/client/client.rb, line 40
def requests id=nil
  return Request.get "#{@url}/requests/#{id}" if id
  Requests.new(@url)
end
reset() click to toggle source
# File lib/mirage/client/client.rb, line 31
def reset
  templates.default_config.reset
end
revert() click to toggle source
# File lib/mirage/client/client.rb, line 53
def revert
  self.class.send(:put, @url, :body => "")
end
running?() click to toggle source
# File lib/mirage/client/client.rb, line 69
def running?
  Mirage.running? @url
end
save() click to toggle source
# File lib/mirage/client/client.rb, line 49
def save
  self.class.send(:put, "#{@url}/backup", :body => "")
end
templates(id=nil) click to toggle source
# File lib/mirage/client/client.rb, line 35
def templates id=nil
  return Template.get("#{@url}/templates/#{id}") if id
  @templates
end