Class: Deluge::Rpc::Namespace
- Inherits:
-
Object
- Object
- Deluge::Rpc::Namespace
- Defined in:
- lib/deluge/rpc/namespace.rb
Instance Attribute Summary collapse
-
#api_methods ⇒ Object
readonly
Returns the value of attribute api_methods.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Instance Method Summary collapse
- #call(method, *args) ⇒ Object
-
#initialize(name, connection) ⇒ Namespace
constructor
A new instance of Namespace.
- #register_method(method) ⇒ Object
- #register_namespace(namespace) ⇒ Object
Constructor Details
#initialize(name, connection) ⇒ Namespace
Returns a new instance of Namespace.
6 7 8 9 10 |
# File 'lib/deluge/rpc/namespace.rb', line 6 def initialize(name, connection) @name, @connection = name, connection @namespaces = {} @api_methods = [] end |
Instance Attribute Details
#api_methods ⇒ Object (readonly)
Returns the value of attribute api_methods.
4 5 6 |
# File 'lib/deluge/rpc/namespace.rb', line 4 def api_methods @api_methods end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
4 5 6 |
# File 'lib/deluge/rpc/namespace.rb', line 4 def connection @connection end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/deluge/rpc/namespace.rb', line 4 def name @name end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
4 5 6 |
# File 'lib/deluge/rpc/namespace.rb', line 4 def namespaces @namespaces end |
Instance Method Details
#call(method, *args) ⇒ Object
38 39 40 41 42 |
# File 'lib/deluge/rpc/namespace.rb', line 38 def call(method, *args) method_name = "#{name}.#{method}" @connection.call(method_name, *args) end |
#register_method(method) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/deluge/rpc/namespace.rb', line 28 def register_method(method) method = method.to_sym api_methods << "#{name}.#{method}" define_singleton_method(method) do |*args| call(method, *args) end end |
#register_namespace(namespace) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/deluge/rpc/namespace.rb', line 12 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 |