-
Notifications
You must be signed in to change notification settings - Fork 0
/
jour.rb
86 lines (68 loc) · 1.61 KB
/
jour.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module Jour
def self.included(base)
base.extend ClassMethods
base.class_eval do
attr_accessor :text
end
end
def setService(service)
@service = service
setup if respond_to?(:setup)
end
def service
@service
end
module ClassMethods
def service_name(name=nil)
@service_name = name if name
@service_name
end
def newWithService(service)
obj = self.new
puts "starting #{self.class} with #{service.type}"
obj.setService(service)
return obj
end
def nib_name(nib_name=nil)
self.nib_path NSBundle.mainBundle.pathForResource(nib_name, :ofType=>'nib')
end
def nib_path(nib_path=nil)
if nib_path
@nib_path = nib_path
else
@nib_path
end
end
end
def view?
begin
view
true
rescue
false
end
end
def view
unless @view
raise "no nib path set... set the class nib path first" unless self.class.nib_path
@vc = NSViewController.alloc.initWithNibName(nil,:bundle=>nil)
nib = NSNib.alloc.initWithContentsOfURL(NSURL.fileURLWithPath(self.class.nib_path))
nib.instantiateNibWithOwner_topLevelObjects(@vc, nil)
puts "nib... #{@vc}"
@vc.representedObject = self
@view = @vc.view
end
@view
end
def children; [] end
def leaf; true end
# service resolution
def netServiceDidResolveAddress(service)
puts "resolved address"
resolved! if respond_to?(:resolved!)
end
def netService_didNotResolve(service,reason)
puts "netService_didNotResolve #{service_key(service)}"
p reason
end
end