Sha256: 8da352b05912e516533054f5b778b66c0ea7bd5039f20dd5959d8d59ee438ba4

Contents?: true

Size: 1.32 KB

Versions: 64

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'asana'

# Monkeypatches Asana::Resources::Resource so that Ruby marshalling and
# unmarshalling works on Asana resource classes.  Currently, it will
# work unless you call an accessor method, which triggers Asana's
# client library Resource class' method_missing() to "cache" the
# result by creating a singleton method.  Unfortunately, singleton
# methods break marshalling, which is not smart enough to know that it
# is not necessary to marshall them as they will simply be recreated
# when needed.

module Asana
  # Monkeypatches:
  #
  # https://github.com/Asana/ruby-asana/blob/master/lib/asana
  module Resources
    # Public: The base resource class which provides some sugar over common
    # resource functionality.
    class Resource
      # @return [Hash]
      def marshal_dump
        { 'data' => @_data,
          'client' => @_client }
      end

      # @param data [Hash]
      #
      # @return [void]
      def marshal_load(data)
        # @sg-ignore
        # @type [Asana::Client]
        @_client = data.fetch('client')
        # @sg-ignore
        # @type [Hash]
        @_data = data.fetch('data')
        @_data.each do |k, v|
          if respond_to?(k)
            variable = :"@#{k}"
            instance_variable_set(variable, v)
          end
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
checkoff-0.161.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.160.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.159.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.158.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.157.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.156.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.155.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.154.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.153.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.152.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.151.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.150.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.149.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.148.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.147.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.145.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.139.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.138.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.137.0 lib/checkoff/monkeypatches/resource_marshalling.rb
checkoff-0.136.0 lib/checkoff/monkeypatches/resource_marshalling.rb