Class: Mirage::Client
- Inherits:
-
Object
- Object
- Mirage::Client
- Includes:
- HTTParty
- Defined in:
- lib/mirage/client/client.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #==(client) ⇒ Object
- #clear ⇒ Object
- #configure(&block) ⇒ Object
-
#initialize(options = {:url => "http://localhost:7001"}, &block) ⇒ Client
constructor
A new instance of Client.
- #prime ⇒ Object
- #put(*args, &block) ⇒ Object
- #requests(id = nil) ⇒ Object
- #reset ⇒ Object
- #revert ⇒ Object
- #running? ⇒ Boolean
- #save ⇒ Object
- #templates(id = nil) ⇒ Object
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 ={:url => "http://localhost:7001"}, &block if .is_a?(String) && =~ URI.regexp @url = elsif .kind_of?(Hash) && [:port] @url = "http://localhost:#{[:port]}" elsif .kind_of?(Hash) && [:url] @url = [:url] else raise "specify a valid URL or port" end @templates = Templates.new(@url) @templates.default_config &block if block end |
Instance Attribute Details
#url ⇒ Object (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 |
#clear ⇒ Object
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 |
#prime ⇒ Object
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 |
#reset ⇒ Object
31 32 33 |
# File 'lib/mirage/client/client.rb', line 31 def reset templates.default_config.reset end |
#revert ⇒ Object
53 54 55 |
# File 'lib/mirage/client/client.rb', line 53 def revert self.class.send(:put, @url, :body => "") end |
#running? ⇒ Boolean
69 70 71 |
# File 'lib/mirage/client/client.rb', line 69 def running? Mirage.running? @url end |
#save ⇒ Object
49 50 51 |
# File 'lib/mirage/client/client.rb', line 49 def save self.class.send(:put, "#{@url}/backup", :body => "") end |