Sha256: 7890756d84316d5b347f31d09f3b97bdbebcbb808ff0ec166577dfb53ecd3bf5

Contents?: true

Size: 967 Bytes

Versions: 3

Compression:

Stored size: 967 Bytes

Contents

module Deluge
  module Rpc
    class Namespace
      attr_reader :name, :connection, :namespaces, :api_methods

      def initialize(name, connection)
        @name, @connection = name, connection
        @namespaces = {}
        @api_methods = []
      end

      def register_namespace(namespace)
        namespace = namespace.to_sym

        return namespaces[namespace] if namespaces.include?(namespace)

        ns = Namespace.new("#{self.name}.#{namespace}", connection)

        namespaces[namespace] = ns

        define_singleton_method(namespace) do
          ns
        end

        ns
      end

      def register_method(method)
        method = method.to_sym

        api_methods << "#{name}.#{method}"

        define_singleton_method(method) do |*args|
          call(method, *args)
        end
      end

      def call(method, *args)
        method_name = "#{name}.#{method}"

        @connection.call(method_name, *args)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
deluge-rpc-0.2.2 lib/deluge/rpc/namespace.rb
deluge-rpc-0.2.0 lib/deluge/rpc/namespace.rb
deluge-rpc-0.1.3 lib/deluge/rpc/namespace.rb