lib/acfs/service.rb in acfs-0.15.0 vs lib/acfs/service.rb in acfs-0.16.0
- old
+ new
@@ -4,11 +4,10 @@
# Service object.
#
class Service
attr_accessor :options
- class_attribute :base_url
include Service::Middleware
def initialize(options = {})
@options = options
@@ -23,8 +22,24 @@
url = self.class.base_url.to_s
url += "/#{(options[:path] || resource_class.name.pluralize.underscore).to_s}"
url += "/#{options[:suffix].to_s}" if options[:suffix]
url
+ end
+
+ class << self
+
+ def identity(identity = nil)
+ @identity = identity.to_s.to_sym unless identity.nil?
+ @identity ||= name.to_sym
+ end
+
+ def base_url
+ unless (base = Acfs::Configuration.current.locate identity)
+ raise ArgumentError, "#{identity} not configured. Add `locate '#{identity.to_s.underscore}', 'http://service.url/'` to your configuration."
+ end
+
+ base.to_s
+ end
end
end
end