rubymotion/BubbleWrap — pull request #201 by rbeene (2013-03-31 17:10:08+00:00)
Title: WIP: Convenience Wrapper for UIAlertView

Although this PR is not ready to be brought in, I'm submitting it to generate some discussion as to the usefulness as well as the approach. I wasn't sure where to put all these so I made a new directory under motion called 'wrappers'. This is very generic, but could be used as a catch-all for these small convenience wrappers.

In this PR, UIAlertView can be made with simply writing the following

@alert = BW::Alert.new("Title", "Message")
@alert.show

Underneath the hood, an instance of BW::Wrappers:::Alert is created which only holds the native UIAlertView object. Leveraging a module "native_attributes", I can specify which methods get delegated to the native object. Additionally, this method converts the native camelized version to a snake case version so it can be called in a more familiar ruby style.

native_attributes :show, :title, :message, :numberOfButtons, ....

In the above case, a method "number_of_buttons" is defined which calls to native.numberOfButtons.

Also in the native_attributes module is "aliased_native_attributes". This would allow the mapping of a shorter method name to the native version using a hash syntax:

aliased_native_attributes short_method_name: :veryLongMethodNameInObjectiveC

Feedback greatly appreciated.