lib/nano_store/finder.rb
def find(*arg)
      if arg[0].is_a?(Hash)
        # hash style
        options = arg[0]
        if arg[1] && arg[1].is_a?(Hash)
          sort_options = arg[1][:sort] || {}
        else
          sort_options = {}
        end
      elsif arg[0] && arg[1] && arg[2]
        # standard way to find
        options = {arg[0] => {arg[1] => arg[2]}}
        if arg[4] && arg[4].is_a?(Hash)
          sort_options = arg[4][:sort] || {}
        else
          sort_options = {}
        end
      elsif arg.empty?
        options = {}
        sort_options = {}
      else
        raise "unexpected parameters #{arg}"
      end
      search = NSFNanoSearch.searchWithStore(self.store)

      expressions = expressions_with_options(options)
      search.expressions = expressions

      sort_descriptors = sort_descriptor_with_options(sort_options)
      search.sort = sort_descriptors
      search.filterClass = self.bare_class_name

      error_ptr = Pointer.new(:id)
      searchResults = search.searchObjectsWithReturnType(NSFReturnObjects, error:error_ptr)
      raise NanoStoreError, error_ptr[0].description if error_ptr[0]

      if searchResults.is_a?(NSDictionary)
        searchResults.values
      else
        searchResults
      end
    end
# find model by criteria
#
# Return array of models
#
# Examples:
#   User.find(:name, NSFEqualTo, "Bob") # => [<User#1>]
#   User.find(:name => "Bob") # => [<User#1>]
#   User.find(:name => {NSFEqualTo => "Bob"}) # => [<User#1>]
#
find model by criteria
Return array of models


find model by criteria Return array of models
def find(*arg)
      if arg[0].is_a?(Hash)
        options = arg[0]
        if arg[1] && arg[1].is_a?(Hash)
          sort_options = arg[1][:sort] || {}
        else
          sort_options = {}
        end
      elsif arg[0] && arg[1] && arg[2]
        options = {arg[0] => {arg[1] => arg[2]}}
        if arg[4] && arg[4].is_a?(Hash)
          sort_options = arg[4][:sort] || {}
        else
          sort_options = {}
        end
      elsif arg.empty?
        options = {}
        sort_options = {}
      else
        raise "unexpected parameters #{arg}"
      end
      search = NSFNanoSearch.searchWithStore(self.store)
      expressions = expressions_with_options(options)
      search.expressions = expressions
      sort_descriptors = sort_descriptor_with_options(sort_options)
      search.sort = sort_descriptors
      search.filterClass = self.bare_class_name
      error_ptr = Pointer.new(:id)
      searchResults = search.searchObjectsWithReturnType(NSFReturnObjects, error:error_ptr)
      raise NanoStoreError, error_ptr[0].description if error_ptr[0]
      if searchResults.is_a?(NSDictionary)
        searchResults.values
      else
        searchResults
      end
    end
def find ( * arg ) if arg [ 0 ] . is_a? ( Hash ) options = arg [ 0 ] if arg [ 1 ] && arg [ 1 ] . is_a? ( Hash ) sort_options = arg [ 1 ] [ :sort ] || { } else sort_options = { } end elsif arg [ 0 ] && arg [ 1 ] && arg [ 2 ] options = { arg [ 0 ] => { arg [ 1 ] => arg [ 2 ] } } if arg [ 4 ] && arg [ 4 ] . is_a? ( Hash ) sort_options = arg [ 4 ] [ :sort ] || { } else sort_options = { } end elsif arg . empty? options = { } sort_options = { } else raise "unexpected parameters #{arg}" end search = NSFNanoSearch . searchWithStore ( self . store ) expressions = expressions_with_options ( options ) search . expressions = expressions sort_descriptors = sort_descriptor_with_options ( sort_options ) search . sort = sort_descriptors search . filterClass = self . bare_class_name error_ptr = Pointer . new ( :id ) searchResults = search . searchObjectsWithReturnType ( NSFReturnObjects , error : error_ptr ) raise NanoStoreError , error_ptr [ 0 ] . description if error_ptr [ 0 ] if searchResults . is_a? ( NSDictionary ) searchResults . values else searchResults end end
find model by criteria
Return array of models
find model by criteria Return array of models
# hash style # standard way to find
arg