module MotionDataWrapper::Relation::FinderMethods
Public Instance Methods
all()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 5 def all to_a end
count()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 9 def count return to_a.count if fetchOffset > 0 old_result_type = self.resultType self.resultType = NSCountResultType count = to_a[0] self.resultType = old_result_type return count end
destroy_all()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 18 def destroy_all all.map &:destroy end
empty?()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 22 def empty? self.count == 0 end
except(query_part)
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 26 def except(query_part) case query_part.to_sym when :where self.predicate = nil when :order self.sortDescriptors = nil when :limit self.fetchLimit = 0 else raise ArgumentError, "unsupport query part '#{query_part}'" end self end
exists?()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 40 def exists? !empty? end
first()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 44 def first take end
first!()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 48 def first! take! end
last()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 52 def last self.fetchOffset = self.count - 1 unless self.count < 1 take end
last!()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 57 def last! last or raise RecordNotFound end
limit(l)
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 61 def limit(l) l = l.to_i raise ArgumentError, "limit '#{l}' cannot be less than zero. Use zero for no limit." if l < 0 self.fetchLimit = l self end
offset(o)
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 68 def offset(o) o = o.to_i raise ArgumentError, "offset '#{o}' cannot be less than zero." if o < 0 self.fetchOffset = o self end
order(column, opts={})
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 75 def order(column, opts={}) descriptors = sortDescriptors.nil? ? [] : sortDescriptors.mutableCopy descriptors << NSSortDescriptor.sortDescriptorWithKey(column.to_s, ascending:opts.fetch(:ascending, true)) self.sortDescriptors = descriptors self end
pluck(column)
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 82 def pluck(column) self.resultType = NSDictionaryResultType attribute_description = entity.attributesByName[column] raise ArgumentError, "#{column} not a valid column name" if attribute_description.nil? self.propertiesToFetch = [attribute_description] to_a.collect { |r| r[column] } end
take()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 92 def take limit(1).to_a[0] end
take!()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 96 def take! take or raise RecordNotFound end
uniq()
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 100 def uniq self.returnsDistinctResults = true self end
where(format, *args)
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 105 def where(format, *args) new_predicate = NSPredicate.predicateWithFormat(format.gsub("?", "%@"), argumentArray:args) if self.predicate self.predicate = NSCompoundPredicate.andPredicateWithSubpredicates([predicate, new_predicate]) else self.predicate = new_predicate end self end
with_context(ctx)
click to toggle source
# File lib/motion_data_wrapper/relation/finder_methods.rb, line 117 def with_context(ctx) @ctx = ctx self end