Sha256: 7f82ea05e934610fcd98cfebc4e10e0edff5bf843f4884da0c87bc1b263887ba

Contents?: true

Size: 821 Bytes

Versions: 2

Compression:

Stored size: 821 Bytes

Contents

# frozen_string_literal: true

require "delegate"
require "json"

require "pakyow/ui/recordable/helpers/client_remapping"

module Pakyow
  module UI
    module Recordable
      class Attribute < SimpleDelegator
        include Helpers::ClientRemapping

        def initialize(attribute)
          __setobj__(attribute)
          @calls = []
        end

        %i([] []= << delete clear add).each do |method_name|
          define_method method_name do |*args|
            super(*args).tap do
              @calls << [remap_for_client(method_name), args, [], []]
            end
          end
        end

        def to_json(*)
          @calls.to_json
        end

        # Fixes an issue using pp inside a delegator.
        #
        def pp(*args)
          Kernel.pp(*args)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pakyow-ui-1.0.0.rc2 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.0.rc1 lib/pakyow/ui/recordable/attribute.rb