jonathanpenn / MotionData

A naive example of a migratable RubyMotion/CoreData wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A naive example of a migratable RubyMotion/CoreData wrapper

The following models define a schema that is immediatly available during development:

class Author < Base
  has_many :articles, :class => 'Article'

  property :name, String, :required => true
end

class Article < Base
  belongs_to :author, :class => 'Author'

  property :title,     String,  :required => true
  property :body,      String,  :required => true
  property :published, Boolean, :default  => false
end

NOTE: the association macros don't actually do anything yet.

The Schema instance can dump this definition, which looks like:

Schema.define_version('1.0') do |s|

  s.add_entity do |e|
    e.name = 'Article'
    e.managedObjectClassName = 'Article'
    e.add_property :published, Boolean, {:default=>false}
    e.add_property :title, String, {:required=>true}
    e.add_property :body, String, {:required=>true}
  end

  s.add_entity do |e|
    e.name = 'Author'
    e.managedObjectClassName = 'Author'
    e.add_property :name, String, {:required=>true}
  end

end

As you can see it has a version, this is the app’s release version. These dumps would be created on each new release of the app and would then allow for easy migrations with code that can be found in @mdiep’s CoreDataInCode example.

About

A naive example of a migratable RubyMotion/CoreData wrapper


Languages

Language:Ruby 100.0%