lib/active_remote/search.rb in active_remote-2.1.0.beta2 vs lib/active_remote/search.rb in active_remote-2.1.0.rc1

- old
+ new

@@ -12,10 +12,17 @@ define_model_callbacks :search end module ClassMethods + # :noapi: + def _active_remote_search_args(args) + warn "DEPRECATED Model._active_remote_search_args is depracted and will be remoted in Active Remote 3.0." + + validate_search_args!(args) + end + # Tries to load the first record; if it fails, an exception is raised. # # ====Examples # # # A single hash @@ -87,38 +94,39 @@ # # # Protobuf object # Tag.search(Generic::Remote::TagRequest.new(:name => 'foo')) # def search(args) - args = _active_remote_search_args(args) + args = validate_search_args!(args) response = rpc.execute(:search, args) if response.respond_to?(:records) records = serialize_records(response.records) records.each { |record| record.run_callbacks :search } end end - # :noapi: - def _active_remote_search_args(args) + # Validates the given args to ensure they are compatible + # Search args must be a hash or respond to to_hash + # + def validate_search_args!(args) unless args.is_a?(Hash) if args.respond_to?(:to_hash) args = args.to_hash else - raise "Invalid parameter: #{args}. First parameter must respond to :to_hash." + raise "Invalid parameter: #{args}. Search args must respond to :to_hash." end end args end end - # Search for the given resource. Auto-paginates (i.e. continues searching - # for records matching the given search args until all records have been - # retrieved) if no pagination options are given. - # + # :noapi: def _active_remote_search(args) + warn "DEPRECATED Model#_active_remote_search is depracted and will be remoted in Active Remote 3.0." + run_callbacks :search do rpc.execute(:search, args) end end