Sha256: d9932afd762870d81fd1876d5dee115b207cc3b10ef4923f2f527d4c03362355

Contents?: true

Size: 867 Bytes

Versions: 12

Compression:

Stored size: 867 Bytes

Contents

class Card
  module Env
    # serializing environment (eg for delayed jobs)
    module Serialization
      def serialize
        @serialized = Serializable.instance_methods.each_with_object({}) do |attr, hash|
          hash[attr] = send attr
        end
      end

      # @param serialized_env [Hash]
      def with serialized_env
        tmp_env = serialize
        @serialized.update serialized_env
        yield
      ensure
        @serialized.update tmp_env if tmp_env
      end

      # supercede serializable methods when serialized values are available
      #
      # note - at present this must be done manually when adding serializable methods
      # in mods.
      Serializable.instance_methods.each do |attrib|
        define_method attrib do
          @serialized&.key?(attrib) ? @serialized[attrib] : super()
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
card-1.108.1 lib/card/env/serialization.rb
card-1.108.0 lib/card/env/serialization.rb
card-1.107.0 lib/card/env/serialization.rb
card-1.106.0 lib/card/env/serialization.rb
card-1.105.6 lib/card/env/serialization.rb
card-1.105.5 lib/card/env/serialization.rb
card-1.105.4 lib/card/env/serialization.rb
card-1.105.3 lib/card/env/serialization.rb
card-1.105.2.pre1 lib/card/env/serialization.rb
card-1.105.2 lib/card/env/serialization.rb
card-1.105.1 lib/card/env/serialization.rb
card-1.105.0 lib/card/env/serialization.rb