Sha256: ed6ca6b6fefc956a96fc1a4e4fbe45e4a86d5a5fe595858a3fc0bfa950b079c4

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module CDQ

  class CDQObject; end
  class CDQQuery < CDQObject; end
  class CDQPartialPredicate < CDQObject; end
  class CDQTargetedQuery < CDQQuery; end

  extend self

  def cdq(obj = nil)
    obj ||= self

    @@base_object ||= CDQObject.new

    case obj
    when Class
      if obj.isSubclassOfClass(NSManagedObject)
        entity_description = @@base_object.models.current.entitiesByName[obj.name]
        if entity_description.nil?
          raise "Cannot find an entity named #{obj.name}"
        end
        CDQTargetedQuery.new(entity_description, obj)
      else
        @@base_object
      end
    when String
      entity_description = @@base_object.models.current.entitiesByName[obj]
      target_class = NSClassFromString(entity_description.managedObjectClassName)
      if entity_description.nil?
        raise "Cannot find an entity named #{obj}"
      end
      CDQTargetedQuery.new(entity_description, target_class)
    when Symbol
      CDQPartialPredicate.new(obj, CDQQuery.new)
    when CDQObject
      obj
    when NSManagedObject
      CDQObjectProxy.new(obj)
    when Array
      if obj.first.class.isSubclassOfClass(NSManagedObject)
        CDQCollectionProxy.new(obj, obj.first.entity)
      else
        @@base_object
      end
    else
      @@base_object
    end
  end

  def self.pollute(klass)
  end

end

class UIResponder
  include CDQ
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cdq-0.1.1 motion/cdq.rb