Sha256: a19fcc76e60b524b78263fb7ad236bba17396e734b32a4a57a6011c449efc801

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

module Recurly
  # This class represents an object as it exists on the
  # Recurly servers. It is generated from a response. If you wish to
  # update or change a resource, you need to send a request to the server
  # and get a new Resource.
  class Resource
    extend Schema::SchemaFactory
    extend Schema::ResourceCaster
    include Schema::SchemaValidator

    attr_reader :attributes

    def requires_client?
      false
    end

    def ==(other_resource)
      other_resource.is_a?(Recurly::Resource) &&
        attributes == other_resource.attributes
    end

    # Hide instance variables to keep from accidental logging
    def inspect
      "#<#{self.class.name}:#{object_id}} @attributes=#{attributes}>"
    end

    def to_s
      self.inspect
    end

    def to_json
      raise NoMethodError, "to_json is not implemented for Resources. Please use Resource#attributes"
    end

    def get_response
      @response
    end

    protected

    def schema
      self.class.schema
    end

    def initialize(attributes = {})
      @attributes = attributes.clone
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
recurly-4.56.0 lib/recurly/resource.rb
recurly-4.55.0 lib/recurly/resource.rb
recurly-4.54.0 lib/recurly/resource.rb
recurly-4.53.0 lib/recurly/resource.rb
recurly-4.52.0 lib/recurly/resource.rb
recurly-4.49.0 lib/recurly/resource.rb
recurly-4.48.1 lib/recurly/resource.rb