Sha256: 62145dfd307aa96f8a922700741c31814089ff6009e7abad67eaf7c266285adc

Contents?: true

Size: 403 Bytes

Versions: 3

Compression:

Stored size: 403 Bytes

Contents

require "ostruct"

module OpConnect
  class Object < SimpleDelegator
    def initialize(attributes)
      super to_ostruct(attributes)
    end

    private

    def to_ostruct(obj)
      if obj.is_a?(Hash)
        OpenStruct.new(obj.map { |key, value| [key, to_ostruct(value)] }.to_h)
      elsif obj.is_a?(Array)
        obj.map { |o| to_ostruct(o) }
      else
        obj
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
op_connect-0.1.3 lib/op_connect/object.rb
op_connect-0.1.2 lib/op_connect/object.rb
op_connect-0.1.1 lib/op_connect/object.rb