Class: Mirage::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mirage/client/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {:url => "http://localhost:7001"}, &block) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/mirage/client/client.rb', line 10

def url
  @url
end

Instance Method Details

#==(client) ⇒ Object



65
66
67
# File 'lib/mirage/client/client.rb', line 65

def == client
  client.instance_of?(Client) && self.url == client.url
end

#clearObject



61
62
63
# File 'lib/mirage/client/client.rb', line 61

def clear
  templates.delete_all
end

#configure(&block) ⇒ Object



27
28
29
# File 'lib/mirage/client/client.rb', line 27

def configure &block
  templates.default_config &block if block
end

#primeObject



45
46
47
# File 'lib/mirage/client/client.rb', line 45

def prime
  self.class.send(:put, "#{@url}/defaults", :body => "")
end

#put(*args, &block) ⇒ Object



57
58
59
# File 'lib/mirage/client/client.rb', line 57

def put *args, &block
  templates.put *args, &block
end

#requests(id = nil) ⇒ Object



40
41
42
43
# File 'lib/mirage/client/client.rb', line 40

def requests id=nil
  return Request.get "#{@url}/requests/#{id}" if id
  Requests.new(@url)
end

#resetObject



31
32
33
# File 'lib/mirage/client/client.rb', line 31

def reset
  templates.default_config.reset
end

#revertObject



53
54
55
# File 'lib/mirage/client/client.rb', line 53

def revert
  self.class.send(:put, @url, :body => "")
end

#running?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/mirage/client/client.rb', line 69

def running?
  Mirage.running? @url
end

#saveObject



49
50
51
# File 'lib/mirage/client/client.rb', line 49

def save
  self.class.send(:put, "#{@url}/backup", :body => "")
end

#templates(id = nil) ⇒ Object



35
36
37
38
# File 'lib/mirage/client/client.rb', line 35

def templates id=nil
  return Template.get("#{@url}/templates/#{id}") if id
  @templates
end