Module: CDQ::CDQRelationshipQuery::SetExt

Defined in:
motion/cdq/relationship_query.rb

Overview

A Core Data relationship set is extended with this module to provide scoping by forwarding messages to a CDQRelationshipQuery instance knows how to create further queries based on the underlying relationship.

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


122
123
124
125
126
127
128
# File 'motion/cdq/relationship_query.rb', line 122

def method_missing(method, *args, &block)
  if @__query__.respond_to?(method)
    @__query__.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#__query__Object

Returns the value of attribute __query__


61
62
63
# File 'motion/cdq/relationship_query.rb', line 61

def __query__
  @__query__
end

Instance Method Details

#add(obj) ⇒ Object Also known as: <<


85
86
87
# File 'motion/cdq/relationship_query.rb', line 85

def add(obj)
  @__query__.add(obj)
end

#arrayObject

This works in a special way. If we're extending a regular NSSet, it will create a new method that calls allObjects. If we're extending a NSOrderedSet, the override will not work, and we get the array method already defined on NSOrderedSet, which is actually exactly what we want.


71
72
73
# File 'motion/cdq/relationship_query.rb', line 71

def array
  self.allObjects
end

#create(opts = {}) ⇒ Object


90
91
92
# File 'motion/cdq/relationship_query.rb', line 90

def create(opts = {})
  @__query__.create(opts)
end

#each(*args, &block) ⇒ Object

duplicating a lot of common methods because it's way faster than using method_missing


81
82
83
# File 'motion/cdq/relationship_query.rb', line 81

def each(*args, &block)
  array.each(*args, &block)
end

#firstObject


75
76
77
# File 'motion/cdq/relationship_query.rb', line 75

def first
  array.first
end

#limit(*args) ⇒ Object


110
111
112
# File 'motion/cdq/relationship_query.rb', line 110

def limit(*args)
  @__query__.limit(*args)
end

#new(opts = {}) ⇒ Object


94
95
96
# File 'motion/cdq/relationship_query.rb', line 94

def new(opts = {})
  @__query__.new(opts)
end

#offset(*args) ⇒ Object


114
115
116
# File 'motion/cdq/relationship_query.rb', line 114

def offset(*args)
  @__query__.offset(*args)
end

#remove(opts = {}) ⇒ Object


98
99
100
# File 'motion/cdq/relationship_query.rb', line 98

def remove(opts = {})
  @__query__.remove(opts)
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)

118
119
120
# File 'motion/cdq/relationship_query.rb', line 118

def respond_to?(method)
  super(method) || @__query__.respond_to?(method)
end

#setObject


63
64
65
# File 'motion/cdq/relationship_query.rb', line 63

def set
  self
end

#sort_by(*args) ⇒ Object


106
107
108
# File 'motion/cdq/relationship_query.rb', line 106

def sort_by(*args)
  @__query__.sort_by(*args)
end

#where(*args) ⇒ Object


102
103
104
# File 'motion/cdq/relationship_query.rb', line 102

def where(*args)
  @__query__.where(*args)
end