Class: NetService

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-net-service/net_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NetService

Returns a new instance of NetService.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/motion-net-service/net_service.rb', line 2

def initialize(options = {})
  default_options = {
    domain: "",
    search_type: "_http._tcp.",
  }
  options.merge!(default_options)

  if options[:net_service]
    @net_service = options[:net_service]
  else
    @net_service = NSNetService.alloc.initWithDomain(
      options[:domain],
      type: options[:search_type],
      name: options[:name],
      port: options[:port]
    )
  end

  @net_service.setDelegate(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/motion-net-service/net_service.rb', line 45

def method_missing(method, *args)
  if @net_service.respond_to? method
    @net_service.send(method, *args)
  else
    super
  end
end

Class Method Details

.from_ns_net_service(ns_net_service) ⇒ Object



23
24
25
# File 'lib/motion-net-service/net_service.rb', line 23

def self.from_ns_net_service(ns_net_service)
  new(:net_service => ns_net_service)
end

Instance Method Details

#publishObject



27
28
29
# File 'lib/motion-net-service/net_service.rb', line 27

def publish
  @net_service.publish
end

#resolve(timeout = 1, &block) ⇒ Object



31
32
33
34
# File 'lib/motion-net-service/net_service.rb', line 31

def resolve(timeout = 1, &block)
  on_did_resolve_address(&block) if block
  @net_service.resolveWithTimeout(timeout)
end