Sha256: ac16d5ed29b5d84c0d94c9845216f7941fb4ab353305f96b5f9671e534cfedc7

Contents?: true

Size: 842 Bytes

Versions: 10

Compression:

Stored size: 842 Bytes

Contents

# frozen_string_literal: true

require "delegate"
require "json"

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

module Pakyow
  module UI
    module Recordable
      # @api private
      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

10 entries across 10 versions & 1 rubygems

Version Path
pakyow-ui-1.0.6 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.5 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.4 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.3 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.2 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.1 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.0 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.0.rc5 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.0.rc4 lib/pakyow/ui/recordable/attribute.rb
pakyow-ui-1.0.0.rc3 lib/pakyow/ui/recordable/attribute.rb