Sha256: 1f2fcdd8fbc3dea79d775e740b9930a28dc5bdcd314c43cd33b31e38023879a6

Contents?: true

Size: 412 Bytes

Versions: 14

Compression:

Stored size: 412 Bytes

Contents

require "ostruct"

module Paddle
  class Object < OpenStruct
    def initialize(attributes)
      super to_ostruct(attributes)
    end

    def to_ostruct(obj)
      if obj.is_a?(Hash)
        OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
      elsif obj.is_a?(Array)
        obj.map { |o| to_ostruct(o) }
      else # Assumed to be a primitive value
        obj
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
paddle-2.2.0 lib/paddle/object.rb
paddle-2.1.4 lib/paddle/object.rb
paddle-2.1.3 lib/paddle/object.rb
paddle-2.1.2 lib/paddle/object.rb
paddle-2.1.1 lib/paddle/object.rb
paddle-2.1.0 lib/paddle/object.rb
paddle-2.0.0 lib/paddle/object.rb
paddle-1.1.2 lib/paddle/object.rb
paddle-1.1.1 lib/paddle/object.rb
paddle-1.1.0 lib/paddle/object.rb
paddlerb-0.1.4 lib/paddle/object.rb
paddlerb-0.1.3 lib/paddle/object.rb
paddlerb-0.1.2 lib/paddle/object.rb
paddlerb-0.1.1 lib/paddle/object.rb