Class: Object

Inherits:
BasicObject
Defined in:
lib/project/ext/object.rb

Instance Method Summary collapse

Instance Method Details

#appObject



96
97
98
# File 'lib/project/ext/object.rb', line 96

def app
  rmq.app
end

#callerObject

REMOVE when RubyMotion adds this



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
# File 'lib/project/ext/object.rb', line 9

def caller
  out = "caller:"

  stacktrace = Java::Lang::Thread.currentThread.getStackTrace
  stacktrace.each_with_index do |trc, i|
    klass_name = trc.className
    method_name = trc.methodName

    next if klass_name == "com.rubymotion.ReplTask"
    next if method_name == "getStackTrace" || method_name == "getThreadStackTrace"

    line_number = trc.getLineNumber
    out << "\n  "
    #out << " " * i
    if line_number < 0
      out << "    "
    else
      out << line_number.to_s.ljust(4)
    end
    out << " "
    out << method_name.to_s.ljust(30)
    out << " "
    out << klass_name.to_s
  end

  out
end

#deviceObject



100
101
102
# File 'lib/project/ext/object.rb', line 100

def device
  rmq.device
end

#find(*args) ⇒ Object

Do not alias this, strange bugs happen where classes don’t have methods



60
61
62
# File 'lib/project/ext/object.rb', line 60

def find(*args) # Do not alias this, strange bugs happen where classes don't have methods
  rmq(*args)
end

#find!(*args) ⇒ Object

Do not alias this, strange bugs happen where classes don’t have methods



64
65
66
# File 'lib/project/ext/object.rb', line 64

def find!(*args) # Do not alias this, strange bugs happen where classes don't have methods
  rmq(*args).get
end

#inspectObject



37
38
39
40
41
42
43
# File 'lib/project/ext/object.rb', line 37

def inspect
  if self.respond_to?(:id)
    "<#{short_class_name}|#{id}>"
  else
    "<#{short_class_name}|#{object_id}>"
  end
end

#mp(s, opts = {}) ⇒ Object

REMOVE when mp starts working



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/project/ext/object.rb', line 72

def mp(s, opts={})
  if opts[:debugging_only]
    return unless RMQ.debugging?
  end

  if s.nil?
    s = "<nil>"
  else
    s = s.to_s
  end
  backspace = "\b\b " * (Android::App::Application.name.length + 13)
  lines = s.split("\n")
  lines.each do |line|
    if RMQ.debugging?
      out = backspace
      out << "\e[1;#{36}m#{self.object_id}\e[0m #{self.short_class_name}".ljust(50)
      out << "  \e[1;#{34}m#{line}\e[0m"
      puts out
    else
      puts "#{backspace} \e[1;#{34}m#{line}\e[0m"
    end
  end
end

#object_idObject

REMOVE when RubyMotion adds this



4
5
6
# File 'lib/project/ext/object.rb', line 4

def object_id
  Java::Lang::System.identityHashCode(self)
end

#rmq(*working_selectors) ⇒ Object

RMQ stuff



52
53
54
55
56
57
58
# File 'lib/project/ext/object.rb', line 52

def rmq(*working_selectors)
  if (app = RMQ.app) && ((cvc = app.current_screen) || (cvc = app.current_activity))
    cvc.rmq(working_selectors)
  else
    RMQ.create_with_array_and_selectors([], working_selectors, self)
  end
end

#short_class_nameObject



45
46
47
# File 'lib/project/ext/object.rb', line 45

def short_class_name
  self.class.name.split('.').last
end