Sha256: 6a25d245d4a85357e9fdc875028e760c3b770ef6c669a3f9ed2d06af026604ea

Contents?: true

Size: 707 Bytes

Versions: 128

Compression:

Stored size: 707 Bytes

Contents

module Protobuf
  module Field
    class ExtensionFields < Array
      ##
      # Constructor
      #
      def initialize
        @ranges = []
      end

      ##
      # Public Instance Methods
      #

      # Append a range to the list of ranges.
      def add_range(range = (0..-1))
        @ranges << range
      end

      # Set value at tag location, if tag is in a valid range.
      def []=(key, value)
        raise RangeError, "#{key} is not in #{@ranges.join(', ')}" unless include_tag?(key)
        super
      end

      # Check if the given tag exists in any of the defined ranges.
      def include_tag?(tag)
        @ranges.any? { |range| range.include?(tag) }
      end
    end
  end
end

Version data entries

128 entries across 128 versions & 1 rubygems

Version Path
protobuf-2.0.3 lib/protobuf/field/extension_fields.rb
protobuf-2.0.2 lib/protobuf/field/extension_fields.rb
protobuf-2.0.1 lib/protobuf/field/extension_fields.rb
protobuf-2.0.0 lib/protobuf/field/extension_fields.rb
protobuf-2.0.0.rc6 lib/protobuf/field/extension_fields.rb
protobuf-2.0.0.rc5 lib/protobuf/field/extension_fields.rb
protobuf-2.0.0.rc4 lib/protobuf/field/extension_fields.rb
protobuf-2.0.0.rc3 lib/protobuf/field/extension_fields.rb