Sha256: 355e7a9b036e231fa479270ba695d28bad6c4a2b763dcdcbf70a724a291f22e0

Contents?: true

Size: 829 Bytes

Versions: 5

Compression:

Stored size: 829 Bytes

Contents

require 'json'

module Razorpay
  # Entity class is the base class for all Razorpay objects
  # This saves data in a hash internally, and makes it available
  # via direct methods
  class Entity
    def initialize(attributes)
      @attributes = attributes
    end

    # This method fakes attr_reader, but uses
    # the @attributes hash as the source, instead of
    # instance variables
    def method_missing(name)
      if @attributes.key? name.to_s
        @attributes[name.to_s]
      else
        super
      end
    end

    def respond_to_missing?(method_name, include_private = false)
      @attributes.key?(method_name.to_s) || super
    end

    # Public: Convert the Entity object to JSON
    # Returns the JSON representation of the Entity (as a string)
    def to_json
      @attributes.to_json
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
razorpay-2.2.0 lib/razorpay/entity.rb
razorpay-2.1.0 lib/razorpay/entity.rb
razorpay-2.1.0.pre lib/razorpay/entity.rb
razorpay-2.0.1 lib/razorpay/entity.rb
razorpay-2.0.0 lib/razorpay/entity.rb