Sha256: 34ac121e153a7a7e2f8176098cda1528db592098a4446b9902fded036f1e79d4

Contents?: true

Size: 759 Bytes

Versions: 4

Compression:

Stored size: 759 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)
      name = name.to_s
      if @attributes.key?(name)
        @attributes[name]
      else
        fail NameError, "No such data member: #{name}"
      end
    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

4 entries across 4 versions & 1 rubygems

Version Path
razorpay-1.0.3 lib/razorpay/entity.rb
razorpay-1.0.2 lib/razorpay/entity.rb
razorpay-1.0.1 lib/razorpay/entity.rb
razorpay-1.0.0 lib/razorpay/entity.rb