Sha256: 0b85de48e36492fe9909c4b68e1ce5617acfa24d3d325200c58140d4e67134b9

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module NFS
  module SUNRPC
    class Program
      attr_reader :number, :low, :high

      def initialize(number, &block)
        @number = number
        @versions = {}
        @low = @high = nil
        instance_eval(&block) if block_given?
      end

      def dup
        self.class.new(@number).tap do |p|
          @versions.each_pair do |number, version|
            p.add_version(number, version.dup)
          end
        end
      end

      def add_version(number, ver)
        if @low.nil? or number < @low
          @low = number
        end

        if @high.nil? or number > @high
          @high = number
        end

        @versions[number] = ver
      end

      def version(ver, &block)
        add_version(ver, Version.new(ver, &block))
      end

      def get_version(ver)
        @versions[ver]
      end

      def each_version(&block)
        @versions.each_value(&block)
      end

      def on_call(ver, procedure_name, &block)
        @versions[ver].on_call(procedure_name, &block)
      end

      def call(ver, procedure, arg, cred, verf)
        if !@versions.include?(ver)
          raise ProgramMismatch.new(2, 2)
        end

        @versions[ver].call(procedure, arg, cred, verf)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nfs-rb-1.0.2 lib/nfs/sunrpc/program.rb
nfs-rb-1.0.1 lib/nfs/sunrpc/program.rb
nfs-rb-1.0.0 lib/nfs/sunrpc/program.rb