Use ActiveSupport instead of extlib
[arvados.git] / lib / google / api_client / discovery / resource.rb
index 6d9d7638c3a20242966d40248eb69d82411146a4..9b757c684da02aed78a8905e1a8ea0d22fbc3e85 100644 (file)
@@ -15,7 +15,7 @@
 
 require 'addressable/uri'
 
-require 'google/inflection'
+require 'active_support/inflector'
 require 'google/api_client/discovery/method'
 
 
@@ -28,11 +28,13 @@ module Google
       ##
       # Creates a description of a particular version of a resource.
       #
-      # @param [Addressable::URI] base
+      # @param [Google::APIClient::API] api
+      #   The API this resource belongs to.
+      # @param [Addressable::URI] method_base
       #   The base URI for the service.
       # @param [String] resource_name
       #   The identifier for the resource.
-      # @param [Hash] resource_description
+      # @param [Hash] discovery_document
       #   The section of the discovery document that applies to this resource.
       #
       # @return [Google::APIClient::Resource] The constructed resource object.
@@ -43,49 +45,53 @@ module Google
         @discovery_document = discovery_document
         metaclass = (class <<self; self; end)
         self.discovered_resources.each do |resource|
-          method_name = Google::INFLECTOR.underscore(resource.name).to_sym
+          method_name = ActiveSupport::Inflector.underscore(resource.name).to_sym
           if !self.respond_to?(method_name)
             metaclass.send(:define_method, method_name) { resource }
           end
         end
-        self.methods.each do |method|
-          method_name = Google::INFLECTOR.underscore(method.name).to_sym
+        self.discovered_methods.each do |method|
+          method_name = ActiveSupport::Inflector.underscore(method.name).to_sym
           if !self.respond_to?(method_name)
             metaclass.send(:define_method, method_name) { method }
           end
         end
       end
 
+      # @return [String] unparsed discovery document for the resource
+      attr_reader :discovery_document
+
       ##
       # Returns the identifier for the resource.
       #
       # @return [String] The resource identifier.
       attr_reader :name
 
-      ##
-      # Returns the parsed section of the discovery document that applies to
-      # this resource.
-      #
-      # @return [Hash] The resource description.
-      attr_reader :description
-
       ##
       # Returns the base URI for this resource.
       #
       # @return [Addressable::URI] The base URI that methods are joined to.
       attr_reader :method_base
 
+      ##
+      # Returns a human-readable description of the resource.
+      #
+      # @return [Hash] The API description.
+      def description
+        return @discovery_document['description']
+      end
+
       ##
       # Updates the hierarchy of resources and methods with the new base.
       #
-      # @param [Addressable::URI, #to_str, String] new_base
+      # @param [Addressable::URI, #to_str, String] new_method_base
       #   The new base URI to use for the resource.
       def method_base=(new_method_base)
         @method_base = Addressable::URI.parse(new_method_base)
         self.discovered_resources.each do |resource|
           resource.method_base = @method_base
         end
-        self.methods.each do |method|
+        self.discovered_methods.each do |method|
           method.method_base = @method_base
         end
       end
@@ -95,7 +101,7 @@ module Google
       #
       # @return [Array] A list of {Google::APIClient::Resource} objects.
       def discovered_resources
-        return @resources ||= (
+        return @discovered_resources ||= (
           (@discovery_document['resources'] || []).inject([]) do |accu, (k, v)|
             accu << Google::APIClient::Resource.new(
               @api, self.method_base, k, v
@@ -109,8 +115,8 @@ module Google
       # A list of methods available on this resource.
       #
       # @return [Array] A list of {Google::APIClient::Method} objects.
-      def methods
-        return @methods ||= (
+      def discovered_methods
+        return @discovered_methods ||= (
           (@discovery_document['methods'] || []).inject([]) do |accu, (k, v)|
             accu << Google::APIClient::Method.new(@api, self.method_base, k, v)
             accu
@@ -126,7 +132,7 @@ module Google
       def to_h
         return @hash ||= (begin
           methods_hash = {}
-          self.methods.each do |method|
+          self.discovered_methods.each do |method|
             methods_hash[method.id] = method
           end
           self.discovered_resources.each do |resource|