Class List Method List File List

# Module: OSX::CoreData

Defined in:
  src/ruby/osx/objc/cocoa_macros.rb

## Overview

CoreData additions.

## Class Method Summary (collapse)

- + (Object) define_wrapper(model)

  Defines wrapper methods from given NSManagedObjectModel.

- + (Object) define_wrapper_for_entity(entity)

  Defines wrapper method from given NSEntityDescription.

## Class Method Details

### + (`Object`) define_wrapper(model)

Defines wrapper methods from given NSManagedObjectModel.

Parameters:

- model (`OSX::NSManagedObjectModel`)

    60
    61
    62
    63
    64
    65
    66
    67
    68

    # File 'src/ruby/osx/objc/cocoa_macros.rb', line 60

    def define_wrapper(model)
      unless model.isKindOfClass? OSX::NSManagedObjectModel
        raise RuntimeError, "invalid class: #{model.class}"
      end

      model.entities.each do |ent|
        CoreData.define_wrapper_for_entity(ent)
      end
    end

### + (`Object`) define_wrapper_for_entity(entity)

Defines wrapper method from given NSEntityDescription.

Parameters:

- entity (`OSX::NSEntityDescription`)

    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88

    # File 'src/ruby/osx/objc/cocoa_macros.rb', line 73

    def define_wrapper_for_entity(entity)
      klassname = entity.managedObjectClassName.to_s
      return if klassname == 'NSManagedObject'
      unless Object.const_defined?(klassname)
    	warn "define_wrapper_for_entity: class \"#{klassname}\" is not defined."
        return
      end

      attrs = entity.attributesByName.allKeys.collect {|key| key.to_s}
      rels = entity.relationshipsByName.allKeys.collect {|key| key.to_s}
      klass = Object.const_get(klassname)
      klass.instance_eval <<-EOE_AUTOWRAP,__FILE__,__LINE__+1
    	kvc_wrapper attrs
    	kvc_wrapper_reader rels
      EOE_AUTOWRAP
    end