Module: SugarCube

Defined in:
lib/version.rb,
lib/sugarcube.rb,
lib/all/sugarcube/log.rb,
lib/cocoa/sugarcube/log.rb,
lib/all/sugarcube/look_in.rb,
lib/ios/sugarcube-repl/repl.rb,
lib/osx/sugarcube-repl/repl.rb,
lib/cocoa/sugarcube-repl/repl.rb,
lib/ios/sugarcube-modal/modal.rb,
lib/cocoa/sugarcube-timer/timer.rb,
lib/ios/sugarcube-events/uicontrol.rb,
lib/cocoa/sugarcube-cocoakit/frameable.rb,
lib/cocoa/sugarcube-nsdate/date_parser.rb,
lib/cocoa/sugarcube-anonymous/anonymous.rb,
lib/ios/sugarcube-factories/uialertview.rb,
lib/ios/sugarcube-factories/uiactionsheet.rb,
lib/ios/sugarcube-animations/animation_chain.rb,
lib/ios/sugarcube-coregraphics/core_graphics.rb,
lib/cocoa/sugarcube-anonymous/anonymous_array.rb

Defined Under Namespace

Modules: CoreGraphics, DateParser, Frameable, Modal, Repl, Timer Classes: ActionSheetDelegate, AlertViewDelegate, AnimationChain, Anonymous, AnonymousArray, UIControlCallbackHelper

Constant Summary collapse

Version =
'2.0.1'

Class Method Summary collapse

Class Method Details

.flush_log(notification = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/all/sugarcube/log.rb', line 20

def flush_log(notification=nil)
  return unless @log && ! @log.empty?

  output = "SugarCube recorded the following warnings:"
  @log.uniq.each do |message|
    output << "\n"
    output << message
  end
  NSLog(output)
  @log = nil
end

.ios_only!(package) ⇒ Object



7
8
9
10
11
# File 'lib/sugarcube.rb', line 7

def ios_only!(package)
  unless App.template == :ios
    raise "The '\033[0;1msugarcube-#{package}\033[0m' package is only available on iOS."
  end
end

.log(message = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/all/sugarcube/log.rb', line 4

def log(message=nil)
  @log ||= []

  if message.nil?
    return @log
  end

  if suppress?
    log << message
  elsif log?
    stderr(message)
  end

  self
end

.log?(value = nil) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/all/sugarcube/log.rb', line 32

def log?(value=nil)
  if value.nil?
    if @logging.nil?
      @logging = (RUBYMOTION_ENV == 'development')
    end
    @logging
  else
    @logging = value
    unless @logging
      @log = nil
    end
  end
end

.look_in(where, here, here__deprecated = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/all/sugarcube/look_in.rb', line 4

def look_in(where, here, here__deprecated={})
  return here[where] if here.has_key? where
  if here__deprecated[where]
    translated = here__deprecated[where]
    SugarCube.log("The symbol #{where.inspect} has been deprecated in favor of #{translated.inspect}")
    return here[translated]
  end
  raise SugarCubeNotFoundException.new(where.inspect)
end

.osx_only!(package) ⇒ Object



13
14
15
16
17
# File 'lib/sugarcube.rb', line 13

def osx_only!(package)
  unless App.template == :osx
    raise "The '\033[0;1msugarcube-#{package}\033[0m' package is only available on OS X."
  end
end

.stderr(message) ⇒ Object



4
5
6
# File 'lib/cocoa/sugarcube/log.rb', line 4

def stderr(message)
  NSLog(message)
end

.suppress?(value = nil) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
# File 'lib/all/sugarcube/log.rb', line 46

def suppress?(value=nil)
  if value.nil?
    @suppress
  else
    @suppress = value
    unless @suppress
      @log = nil
    end
  end
end