active_remote 1.5.2 → 1.5.4

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.
@@ -34,8 +34,9 @@ module ActiveRemote
34
34
  define_model_callbacks :initialize, :only => :after
35
35
 
36
36
  def initialize(*)
37
+ @attributes ||= {}
38
+
37
39
  run_callbacks :initialize do
38
- @attributes ||= {}
39
40
  super
40
41
  end
41
42
  end
@@ -7,6 +7,8 @@ module ActiveRemote
7
7
  def self.included(klass)
8
8
  klass.class_eval do
9
9
  include ActiveModel::Dirty
10
+
11
+ attr_accessor :_active_remote_track_changes
10
12
  end
11
13
  end
12
14
 
@@ -39,15 +41,20 @@ module ActiveRemote
39
41
  end
40
42
  end
41
43
 
42
- # Override #serialize_records so that we can clear changes after
44
+ # Override #serialize_records so that we can skip dirty tracking while
43
45
  # initializing records returned from a search.
44
46
  #
45
- def serialize_records(*)
46
- if serialized_records = super
47
- serialized_records.each do |record|
48
- record.previous_changes.try(:clear)
49
- record.changed_attributes.try(:clear)
50
- end
47
+ def serialize_records
48
+ return nil unless last_response.respond_to?(:records)
49
+
50
+ last_response.records.map do |record|
51
+ remote = self.class.new
52
+
53
+ remote._active_remote_track_changes = false
54
+ remote.assign_attributes(record.to_hash)
55
+ remote._active_remote_track_changes = true
56
+
57
+ remote
51
58
  end
52
59
  end
53
60
 
@@ -55,18 +62,24 @@ module ActiveRemote
55
62
  # ActiveModel::Dirty.
56
63
  #
57
64
  def write_attribute(name, value)
58
- __send__("#{name}_will_change!") unless value == self[name]
65
+ __send__("#{name}_will_change!") if _active_remote_track_changes? && value != self[name]
59
66
  super
60
67
  end
61
68
  alias_method :[]=, :write_attribute
62
69
 
63
70
  private
64
71
 
72
+ # Wether or not changes are currently being tracked for this class.
73
+ #
74
+ def _active_remote_track_changes?
75
+ @_active_remote_track_changes != false
76
+ end
77
+
65
78
  # Override ActiveAttr's attribute= method so we can provide support for
66
79
  # ActiveModel::Dirty.
67
80
  #
68
81
  def attribute=(name, value)
69
- __send__("#{name}_will_change!") unless value == self[name]
82
+ __send__("#{name}_will_change!") if _active_remote_track_changes? && value != self[name]
70
83
  super
71
84
  end
72
85
 
@@ -1,3 +1,3 @@
1
1
  module ActiveRemote
2
- VERSION = "1.5.2"
2
+ VERSION = "1.5.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_attr
@@ -221,7 +221,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
221
  version: '0'
222
222
  segments:
223
223
  - 0
224
- hash: -883417827179456580
224
+ hash: -651201959748601196
225
225
  required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  none: false
227
227
  requirements:
@@ -230,10 +230,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  segments:
232
232
  - 0
233
- hash: -883417827179456580
233
+ hash: -651201959748601196
234
234
  requirements: []
235
235
  rubyforge_project:
236
- rubygems_version: 1.8.24
236
+ rubygems_version: 1.8.25
237
237
  signing_key:
238
238
  specification_version: 3
239
239
  summary: Active Record for your platform