Sha256: 5f8c2fc72c365a153ac095d9342ae32c31a390411268d3942047d652d5a8465f
Contents?: true
Size: 1.65 KB
Versions: 2
Compression:
Stored size: 1.65 KB
Contents
# Stupid hack because the RubyMotion dependency detection has a bug. module BubbleWrap module Constants module_function # Looks like RubyMotion only adds UIKit constants # at compile time. If you don't use these # directly in your code, they don't get added # to Kernel and Constants.get crashes. # Examples # Constants.register UIReturnKeyDone, UIReturnKeyNext def register(*ui_constants) # do nothing, just get the constants in the code end # @param [String] base of the constant # @param [Integer, NSArray, String, Symbol] the suffix of the constant # when NSArray, will return the bitmask of all suffixes in the array # @return [Integer] the constant for this base and suffix # Examples # get("UIReturnKey", :done) => UIReturnKeyDone == 9 # get("UIReturnKey", "done") => UIReturnKeyDone == 9 # get("UIReturnKey", 9) => 9 # get("UIImagePickerControllerSourceType", ["photo_library", "camera", "saved_photos_album"]) => 3 # get("UIActivityType", [:air_drop, :print]) => ["com.apple.UIKit.activity.AirDrop", "com.apple.UIKit.activity.Print"] def get(base, *values) if values.is_a? NSArray value = values.size == 1 ? values.first : values.flatten else value = values end case value when Numeric value.to_i when NSArray unless get(base, value.first).is_a? Fixnum value.map { |v| get(base, v) } else value.reduce { |i, j| get(base, i) | get(base, j) } end else value = value.to_s.camelize Kernel.const_get("#{base}#{value}") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bubble-wrap-1.9.7 | motion/util/constants.rb |
bubble-wrap-1.9.6 | motion/util/constants.rb |