rpc-mapper 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,7 @@ require 'benchmark'
17
17
  require 'rpc_mapper/core_ext/kernel/singleton_class'
18
18
 
19
19
  # TRP: RPCMapper modules
20
+ require 'rpc_mapper/errors'
20
21
  require 'rpc_mapper/config_options'
21
22
  require 'rpc_mapper/associations/contains'
22
23
  require 'rpc_mapper/associations/external'
@@ -0,0 +1,16 @@
1
+ module RPCMapper
2
+
3
+ # Generic RPCMapper error
4
+ class RPCMapperError < StandardError
5
+ end
6
+
7
+ # Raised when RPCMapper cannot find records from a given id or set of ids
8
+ class RecordNotFound < RPCMapperError
9
+ end
10
+
11
+ # TODO:
12
+ # # Raised when RPCMapper cannot save a record through the mutable adapter
13
+ # class RecordNotSaved < RPCMapperError
14
+ # end
15
+
16
+ end
@@ -3,9 +3,11 @@ module RPCMapper::FinderMethods
3
3
  def find(ids_or_mode, options={})
4
4
  case ids_or_mode
5
5
  when Fixnum, String
6
- self.where(:id => ids_or_mode.to_i).first(options)
6
+ self.where(:id => ids_or_mode.to_i).first(options) || raise(RPCMapper::RecordNotFound, "Could not find record with :id = #{ids_or_mode}")
7
7
  when Array
8
- self.where(:id => ids_or_mode).all(options)
8
+ self.where(:id => ids_or_mode).all(options).tap do |result|
9
+ raise RPCMapper::RecordNotFound, "Couldn't find all records with ids (#{ids_or_mode.join(',')}) (expected #{ids_or_mode.size} records but got #{result.size})." unless result.size == ids_or_mode.size
10
+ end
9
11
  when :all
10
12
  self.all(options)
11
13
  when :first
@@ -3,7 +3,7 @@ module RPCMapper
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpc-mapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Travis Petticrew
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-01 00:00:00 -05:00
18
+ date: 2010-09-03 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -135,6 +135,7 @@ files:
135
135
  - lib/rpc_mapper/cacheable.rb
136
136
  - lib/rpc_mapper/config_options.rb
137
137
  - lib/rpc_mapper/core_ext/kernel/singleton_class.rb
138
+ - lib/rpc_mapper/errors.rb
138
139
  - lib/rpc_mapper/logger.rb
139
140
  - lib/rpc_mapper/mutable.rb
140
141
  - lib/rpc_mapper/relation/finder_methods.rb