rpc-mapper 0.1.0 → 0.1.1

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.
@@ -5,6 +5,8 @@ module RPCMapper::Adapters
5
5
  class RestfulHTTPAdapter < RPCMapper::Adapters::AbstractAdapter
6
6
  register_as :restful_http
7
7
 
8
+ attr_reader :last_response
9
+
8
10
  def write(object)
9
11
  params = build_params_from_attributes(object)
10
12
  object.new_record? ? post_http(object, params) : put_http(object, params)
@@ -54,7 +54,7 @@ class RPCMapper::Base
54
54
  public
55
55
 
56
56
  delegate :find, :first, :all, :search, :apply_finder_options, :to => :scoped
57
- delegate :select, :group, :order, :joins, :where, :having, :limit, :offset, :from, :to => :scoped
57
+ delegate :select, :group, :order, :joins, :where, :having, :limit, :offset, :from, :fresh, :to => :scoped
58
58
 
59
59
  def new_from_data_store(hash)
60
60
  if hash.nil?
@@ -14,9 +14,10 @@ module RPCMapper::Cacheable
14
14
  def fetch_records_with_caching(options={})
15
15
  key = Digest::MD5.hexdigest(self.to_s + options.to_a.sort { |a,b| a.to_s.first <=> b.to_s.first }.inspect)
16
16
  cache_hit = self.cacheable.read(key)
17
+ get_fresh = options.delete(:fresh)
17
18
 
18
- if cache_hit
19
- self.read_adapter.log(options, "CACHE")
19
+ if cache_hit && !get_fresh
20
+ self.read_adapter.log(options, "CACHE #{self.class.name}")
20
21
  cache_hit.each { |fv| fv.fresh = false.freeze }
21
22
  cache_hit
22
23
  else
@@ -8,9 +8,8 @@ module RPCMapper
8
8
  class RecordNotFound < RPCMapperError
9
9
  end
10
10
 
11
- # TODO:
12
- # # Raised when RPCMapper cannot save a record through the mutable adapter
13
- # class RecordNotSaved < RPCMapperError
14
- # end
11
+ # Raised when RPCMapper cannot save a record through the write_adapter and save! or update_attributes! was used
12
+ class RecordNotSaved < RPCMapperError
13
+ end
15
14
 
16
15
  end
@@ -27,13 +27,21 @@ module RPCMapper::Persistence
27
27
  write_adapter.write(self)
28
28
  end
29
29
 
30
+ def save!
31
+ save or raise RPCMapper::RecordNotSaved
32
+ end
33
+
30
34
  def update_attributes(attributes)
31
35
  self.attributes = attributes
32
36
  save
33
37
  end
34
38
 
39
+ def update_attributes!(attributes)
40
+ update_attributes(attributes) or raise RPCMapper::RecordNotSaved
41
+ end
42
+
35
43
  def destroy
36
- write_adapter.delete(self)
44
+ write_adapter.delete(self) unless self.new_record?
37
45
  end
38
46
  alias :delete :destroy
39
47
 
@@ -37,7 +37,7 @@ module RPCMapper::FinderMethods
37
37
  relation = clone
38
38
  return relation unless options
39
39
 
40
- [:joins, :limit, :offset, :order, :select, :group, :having, :from].each do |finder|
40
+ [:joins, :limit, :offset, :order, :select, :group, :having, :from, :fresh].each do |finder|
41
41
  relation = relation.send(finder, options[finder]) if options[finder]
42
42
  end
43
43
 
@@ -1,7 +1,8 @@
1
1
  module RPCMapper::QueryMethods
2
2
  # TRP: Define each of the variables the query options will be stored in.
3
3
  attr_accessor :select_values, :group_values, :order_values, :joins_values, :where_values,
4
- :having_values, :limit_value, :offset_value, :from_value, :raw_sql_value
4
+ :having_values, :limit_value, :offset_value, :from_value, :raw_sql_value,
5
+ :fresh_value
5
6
 
6
7
  def select(*args)
7
8
  if block_given?
@@ -43,6 +44,10 @@ module RPCMapper::QueryMethods
43
44
  clone.tap { |r| r.from_value = table }
44
45
  end
45
46
 
47
+ def fresh(val=true)
48
+ clone.tap { |r| r.fresh_value = val }
49
+ end
50
+
46
51
  def sql(raw_sql)
47
52
  clone.tap { |r| r.raw_sql_value = raw_sql }
48
53
  end
@@ -5,7 +5,7 @@ require 'rpc_mapper/relation/finder_methods'
5
5
  # => http://github.com/rails/rails
6
6
  # Used to achieve the chainability of scopes -- methods are delegated back and forth from BM::Base and BM::Relation
7
7
  class RPCMapper::Relation
8
- SINGLE_VALUE_METHODS = [:limit, :offset, :from]
8
+ SINGLE_VALUE_METHODS = [:limit, :offset, :from, :fresh]
9
9
  MULTI_VALUE_METHODS = [:select, :group, :order, :joins, :where, :having]
10
10
 
11
11
  FINDER_OPTIONS = SINGLE_VALUE_METHODS + MULTI_VALUE_METHODS + [:conditions, :search, :sql]
@@ -3,7 +3,7 @@ module RPCMapper
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 0
6
+ TINY = 1
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Travis Petticrew