Since RubyCocoa 0.11.0 there is a set of Cocoa subclasses which try to be the glue between Cocoa Bindings and ActiveRecord.
Allowing you to create a CoreData like application, but instead using ActiveRecord as a backend.
There's a sample which illustrates the use of this in sample/MailDemo/MailDemoActiveRecordBindings.
I try to add documentation to the source code while I write it, so you should be able to get at least some info from it.
To create html documentation, from the root of the rubycocoa source directory do:
This should create a directory on your desktop with the html files.
(See http://railsmanual.org/class/ActiveRecord%3A%3ABase#establish_connection∞ for more examples.)
Allowing you to create a CoreData like application, but instead using ActiveRecord as a backend.
There's a sample which illustrates the use of this in sample/MailDemo/MailDemoActiveRecordBindings.
I try to add documentation to the source code while I write it, so you should be able to get at least some info from it.
To create html documentation, from the root of the rubycocoa source directory do:
$ rdoc framework/src/ruby/osx/objc/active_record.rb --op ~/Desktop/ActiveRecordBindings
This should create a directory on your desktop with the html files.
Includes
- ActiveRecordProxy is a subclass of NSObject which wraps an instance of a ActiveRecord::Base instance, allowing it to be used with bindings
- ActiveRecordSetController is a subclass of NSArrayController which adds support for the deletion of records
- ActiveRecordTableView is a subclass of NSTableView which adds an instance method called scaffold_columns_for(), which creates the columns needed for a given model (ActiveRecord::Base subclass)
Tips
How to connect to db's?
For instance, if you would like to connect to a mysql db, simply use the following code to connect.(See http://railsmanual.org/class/ActiveRecord%3A%3ABase#establish_connection∞ for more examples.)
# Connect to the database
ActiveRecord::Base.establish_connection({
:adapter => 'mysql',
:host => 'localhost',
:username => 'user',
:password => 'pass',
:database => 'db'
})
ActiveRecord::Base.establish_connection({
:adapter => 'mysql',
:host => 'localhost',
:username => 'user',
:password => 'pass',
:database => 'db'
})
TODO
- A simple ActiveRecordConnector method which loads the db config from a yaml file similar to the way it's done in rails.
- ActiveResource support/sample.
- Automatically create proxy classes, by using self.inherited in ActiveRecord::Base. (Done in revision 1816)
- Support for polymorphic associations.
- See if using a complete db schema, rather than migrations, results in a better/faster way of deploying an application.
- a good set of generation scripts that will create the files for a new model or migration, we actually need such a facility in RubyCocoa itself anyway. Until then you can get a simple generation script here∞. One thing that it lacks is the option to add a ActiveRecordSetController to the nib file.
- sample: maybe a model with acts_as_ferret
- an Xcode project template that generates an application preconfigured to use this (as the CoreData templates already do).
- tests: actually instantiate and use ActiveRecordSetControllers
External references
- http://www.superalloy.nl/blog/?p=21∞ Introduction to ActiveRecordBindings
- http://www.superalloy.nl/blog/?p=30∞ Added migrations support