Re: [MacRuby-devel] Manage array of objects within object's class?
Hi Jeff,
I'm no guru but I wouldn't put the methods for dealing with the collection into
the model class.
You could indeed have a class array (by using the @@prefix for your variable
name) but you could not easily access it in a KVC compliant manner and
therefore could not directly bind it to an NSArrayController.
Steve
On 17 May 2013, at 19:52, Jeff Dyck wrote:
> Hey,
>
> I'm working on developing an app in MacRuby that uses HTTParty to consume a
> Web Service. I'm hoping someone can help me wrap my head around some of the
> Model - View - Controller stuff...
>
> From reading some tutorials on MacRuby (and RubyMotion), it seems that it's
> best practice to have all the HTTP requests for loading, saving and querying
> objects as part of the model, rather than in the controller (which is what
> I've done in the past)...
>
> I can wrap my head around saving and deleting objects in the Model, but
> wondering about loading objects - in particular when there are many objects
> to be loaded... If my code to load the JSON is embedded in the Model as a
> Class Method, can I also have a Class Array to store them? And if so can I
> bind that to an NSArray Controller and use that to feed my UI?
>
> IE: I have a class of 'sites' which is basically a list of schools in our
> District, and simplified looks something like:
>
> class Site
> require 'httparty'
> include HTTParty
> format :json
> base_uri 'http://webservice.address.here'
>
> attr_accessor :siteArray
> attr_accessor :siteArrayController
>
> PROPERTIES = [:id, :code, :name, :server, :location, :saved]
> PROPERTIES.each { |prop| attr_accessor prop }
>
> def self.getAllSites
> siteArray = NSMutableArray.new
>
> get('/sites').parsed_response.each do |site|
> siteArrayController.addObject(self.new(site))
> end
> end
>
> def initialize(attributes = {})
> attributes.each { |key, value|
> self.send((key.to_s + "=").to_s, value)
> }
>
> if @id.nil? then
> @saved = false
> else
> @saved = true
> end
> end
> end
>
> Basically, I would like to call from the main App Delegate something like
> Site.getAllSites, which would talk to the Web Server, load and parse the json
> and init the actual objects, adding them to the siteArray, which would in
> turn populate the UI via Bindings.
>
> So I guess my questions are:
> 1) Am I crazy trying to do it like this?
> 2) How do I define the siteArray and siteArrayController so that they are
> Class variables (rather than object variables) and can be bound to the UI?
>
> Thanks in advance for anyone who can point me in the right direction.
>
> Jeff
> ___
> MacRuby-devel mailing list
> [email protected]
> https://lists.macosforge.org/mailman/listinfo/macruby-devel
___
MacRuby-devel mailing list
[email protected]
https://lists.macosforge.org/mailman/listinfo/macruby-devel
Re: [MacRuby-devel] Manage array of objects within object's class?
Fair enough Steve, thanks for the reply - I'm still working on figuring out
this MVC thing and keeping the logic of my app separate. I suppose I could
have the code to load the JSON into a hash within the model, but keep the
actual object creation and collection outside. At least then all the methods
for talking to the server would be in one place, embedded into the model.
Jeff
On May 18, 2013, at 12:04 AM, Steve Clarke wrote:
> Hi Jeff,
>
> I'm no guru but I wouldn't put the methods for dealing with the collection
> into the model class.
>
> You could indeed have a class array (by using the @@prefix for your variable
> name) but you could not easily access it in a KVC compliant manner and
> therefore could not directly bind it to an NSArrayController.
>
> Steve
>
> On 17 May 2013, at 19:52, Jeff Dyck wrote:
>
>> Hey,
>>
>> I'm working on developing an app in MacRuby that uses HTTParty to consume a
>> Web Service. I'm hoping someone can help me wrap my head around some of the
>> Model - View - Controller stuff...
>>
>> From reading some tutorials on MacRuby (and RubyMotion), it seems that it's
>> best practice to have all the HTTP requests for loading, saving and querying
>> objects as part of the model, rather than in the controller (which is what
>> I've done in the past)...
>>
>> I can wrap my head around saving and deleting objects in the Model, but
>> wondering about loading objects - in particular when there are many objects
>> to be loaded... If my code to load the JSON is embedded in the Model as a
>> Class Method, can I also have a Class Array to store them? And if so can I
>> bind that to an NSArray Controller and use that to feed my UI?
>>
>> IE: I have a class of 'sites' which is basically a list of schools in our
>> District, and simplified looks something like:
>>
>> class Site
>> require 'httparty'
>> include HTTParty
>> format :json
>> base_uri 'http://webservice.address.here'
>>
>> attr_accessor :siteArray
>> attr_accessor :siteArrayController
>>
>> PROPERTIES = [:id, :code, :name, :server, :location, :saved]
>> PROPERTIES.each { |prop| attr_accessor prop }
>>
>> def self.getAllSites
>> siteArray = NSMutableArray.new
>>
>> get('/sites').parsed_response.each do |site|
>> siteArrayController.addObject(self.new(site))
>> end
>> end
>>
>> def initialize(attributes = {})
>> attributes.each { |key, value|
>> self.send((key.to_s + "=").to_s, value)
>> }
>>
>> if @id.nil? then
>> @saved = false
>> else
>> @saved = true
>> end
>> end
>> end
>>
>> Basically, I would like to call from the main App Delegate something like
>> Site.getAllSites, which would talk to the Web Server, load and parse the
>> json and init the actual objects, adding them to the siteArray, which would
>> in turn populate the UI via Bindings.
>>
>> So I guess my questions are:
>> 1) Am I crazy trying to do it like this?
>> 2) How do I define the siteArray and siteArrayController so that they are
>> Class variables (rather than object variables) and can be bound to the UI?
>>
>> Thanks in advance for anyone who can point me in the right direction.
>>
>> Jeff
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> https://lists.macosforge.org/mailman/listinfo/macruby-devel
>
> ___
> MacRuby-devel mailing list
> [email protected]
> https://lists.macosforge.org/mailman/listinfo/macruby-devel
___
MacRuby-devel mailing list
[email protected]
https://lists.macosforge.org/mailman/listinfo/macruby-devel
Re: [MacRuby-devel] OS X10.9 & MacRuby's future...
Francis, Ruby is very well defined language with a well defined standard. David On May 17, 2013, at 3:31 PM, Francis Chong wrote: > @david depends on your definition on full ruby. I would say standard library > is part is full ruby, where RubyMotion deliberately remove part of them > > @stephen thanks for the update, I should have tested that myself > — > Sent from Mailbox for iPhone > > > On Fri, May 17, 2013 at 8:26 PM, stephen horne wrote: > > From what I understand, the only thing missing in Rubymotion is eval() > > There's an article by Clay Allsop about meta-programming in Rubymotion at > http://clayallsopp.com/posts/rubymotion-metaprogramming/ > > I tested to see if eval() works in desktop Rubymotion apps (I read somewhere > that the reason it's not included is due to Apple restrictions on run-time > code evaluation in iOS, rather than a limit of Rubymotion), but it doesn't. > > fb > >> >> david kramf 17/05/2013 13:19 >> >> Is RubyMotion a full Ruby. Does it support reflection and metaprograming? >> Thanks, David Kramf >> >> >> >> ___ >> MacRuby-devel mailing list >> [email protected] >> https://lists.macosforge.org/mailman/listinfo/macruby-devel >> >> Francis Chong17/05/2013 12:15 >> While I'm really happy about OS X support on RubyMotion, it is not a >> replacement for MacRuby. >> >> IMHO MacRuby is far superior: >> >> It offer JIT compiler, you develop orders of magnitude faster as you dont >> need clean and rebuild every time. >> >> You have full ruby compatibility, load standard library as you wish. >> >> It loads gems and framework dynamically like what you would expected from >> regular ruby. >> >> You don't have to write new gems, or rewrite them. Many gems just work, even >> native ones could work. >> >> You can use regular technique for meta programming, and generally you don't >> enter a uncanny valley between dynamic language and static build system. >> >> Some of these limitations are inherited from RubyMotion due to iOS >> restriction, I don't see them going away anytime soon. >> >> That said, RubyMotion team is the ones who know most of MacRuby, and their >> direction is not like MacRuby in past. If you are going to develop Mac app, >> your best choice is probably go RubyMotion, or just use Objective-C. >> — >> Sent from Mailbox for iPhone >> >> >> >> ___ >> MacRuby-devel mailing list >> [email protected] >> https://lists.macosforge.org/mailman/listinfo/macruby-devel > > ___ > MacRuby-devel mailing list > [email protected] > https://lists.macosforge.org/mailman/listinfo/macruby-devel ___ MacRuby-devel mailing list [email protected] https://lists.macosforge.org/mailman/listinfo/macruby-devel
Re: [MacRuby-devel] OS X10.9 & MacRuby's future...
David Yes? I got an impression it's just matz implementation. BTW, do RubyMotion even run ruby spec? — Sent from Mailbox for iPhone On Sun, May 19, 2013 at 5:04 AM, david kramf wrote: > Francis, > Ruby is very well defined language with a well defined standard. > David > On May 17, 2013, at 3:31 PM, Francis Chong wrote: >> @david depends on your definition on full ruby. I would say standard library >> is part is full ruby, where RubyMotion deliberately remove part of them >> >> @stephen thanks for the update, I should have tested that myself >> — >> Sent from Mailbox for iPhone >> >> >> On Fri, May 17, 2013 at 8:26 PM, stephen horne wrote: >> >> From what I understand, the only thing missing in Rubymotion is eval() >> >> There's an article by Clay Allsop about meta-programming in Rubymotion at >> http://clayallsopp.com/posts/rubymotion-metaprogramming/ >> >> I tested to see if eval() works in desktop Rubymotion apps (I read somewhere >> that the reason it's not included is due to Apple restrictions on run-time >> code evaluation in iOS, rather than a limit of Rubymotion), but it doesn't. >> >> fb >> >>> >>> david kramf 17/05/2013 13:19 >>> >>> Is RubyMotion a full Ruby. Does it support reflection and metaprograming? >>> Thanks, David Kramf >>> >>> >>> >>> ___ >>> MacRuby-devel mailing list >>> [email protected] >>> https://lists.macosforge.org/mailman/listinfo/macruby-devel >>> >>> Francis Chong 17/05/2013 12:15 >>> While I'm really happy about OS X support on RubyMotion, it is not a >>> replacement for MacRuby. >>> >>> IMHO MacRuby is far superior: >>> >>> It offer JIT compiler, you develop orders of magnitude faster as you dont >>> need clean and rebuild every time. >>> >>> You have full ruby compatibility, load standard library as you wish. >>> >>> It loads gems and framework dynamically like what you would expected from >>> regular ruby. >>> >>> You don't have to write new gems, or rewrite them. Many gems just work, >>> even native ones could work. >>> >>> You can use regular technique for meta programming, and generally you don't >>> enter a uncanny valley between dynamic language and static build system. >>> >>> Some of these limitations are inherited from RubyMotion due to iOS >>> restriction, I don't see them going away anytime soon. >>> >>> That said, RubyMotion team is the ones who know most of MacRuby, and their >>> direction is not like MacRuby in past. If you are going to develop Mac app, >>> your best choice is probably go RubyMotion, or just use Objective-C. >>> — >>> Sent from Mailbox for iPhone >>> >>> >>> >>> ___ >>> MacRuby-devel mailing list >>> [email protected] >>> https://lists.macosforge.org/mailman/listinfo/macruby-devel >> >> ___ >> MacRuby-devel mailing list >> [email protected] >> https://lists.macosforge.org/mailman/listinfo/macruby-devel___ MacRuby-devel mailing list [email protected] https://lists.macosforge.org/mailman/listinfo/macruby-devel
