Permalink
Browse files

Update site and token for autoloaded models

  • Loading branch information...
1 parent 98c95a2 commit 718d50becc63d0f0d12d22a0c706160afe2e175b @krekoten krekoten committed Sep 23, 2010
Showing with 18 additions and 7 deletions.
  1. +16 −7 lib/lighthouse.rb
  2. +2 −0 lib/lighthouse/base.rb
View
@@ -2,6 +2,7 @@
require 'rubygems'
require 'lighthouse/core_ext/uri'
+require 'active_support'
require 'active_resource'
# Ruby lib for working with the Lighthouse API's XML interface.
@@ -47,19 +48,14 @@ class Error < StandardError; end
class Change < Array; end
- self.host_format = '%s://%s%s'
- self.domain_format = '%s.lighthouseapp.com'
- self.protocol = 'http'
- self.port = ''
-
class << self
attr_accessor :password, :host_format, :domain_format, :protocol, :port
attr_reader :account, :token, :email
# Sets the account name, and updates all the resources with the new domain.
def account=(name)
resources.each do |klass|
- klass.site = klass.site_format % (host_format % [protocol, domain_format % name, ":#{port}"])
+ update_site(klass)
end
@account = name
end
@@ -73,7 +69,7 @@ def authenticate(email, password)
# Sets the API token for all the resources.
def token=(value)
resources.each do |klass|
- klass.headers['X-LighthouseToken'] = value
+ klass
end
@token = value
end
@@ -86,5 +82,18 @@ def email=(value)
def resources
@resources ||= []
end
+
+ def update_site(resource)
+ resource.site = resource.site_format % (host_format % [protocol, domain_format % account, ":#{port}"])
+ end
+
+ def update_token_header(resource)
+ resource.headers['X-LighthouseToken'] = token
+ end
end
+
+ self.host_format = '%s://%s%s'
+ self.domain_format = '%s.lighthouseapp.com'
+ self.protocol = 'http'
+ self.port = ''
end
View
@@ -7,6 +7,8 @@ class << base
end
base.site_format = '%s'
super
+ Lighthouse.update_site(base)
+ Lighthouse.update_token_header(base)
end
end
end

0 comments on commit 718d50b

Please sign in to comment.