forceps 0.6.2 → 0.6.3

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.
@@ -116,13 +116,21 @@ module Forceps
116
116
 
117
117
  def base_local_class_for(remote_object)
118
118
  base_class = remote_object.class.base_class
119
- if remote_object.respond_to?(:type) && remote_object.type.present?
120
- local_type = remote_object.type.gsub('Forceps::Remote', '')
119
+ if has_sti_column?(remote_object)
120
+ local_type = to_local_class_name(remote_object.type)
121
121
  base_class = local_type.constantize rescue base_class
122
122
  end
123
123
  base_class
124
124
  end
125
125
 
126
+ def to_local_class_name(remote_class_name)
127
+ remote_class_name.gsub('Forceps::Remote', '')
128
+ end
129
+
130
+ def has_sti_column?(object)
131
+ object.respond_to?(:type) && object.type.present? && object.type.is_a?(String)
132
+ end
133
+
126
134
  def invoke_callbacks(callback_name, copied_object, remote_object)
127
135
  callback = callbacks_for(callback_name)[copied_object.class]
128
136
  return unless callback
@@ -135,11 +143,19 @@ module Forceps
135
143
 
136
144
  # Using setters explicitly to avoid having to mess with disabling mass protection in Rails 3
137
145
  def copy_attributes(target_object, attributes_map)
146
+ make_type_attribute_point_to_local_class_if_needed(attributes_map)
147
+
138
148
  attributes_map.each do |attribute_name, attribute_value|
139
149
  target_object.send("#{attribute_name}=", attribute_value) rescue debug("The method '#{attribute_name}=' does not exist. Different schemas in the remote and local databases?")
140
150
  end
141
151
  end
142
152
 
153
+ def make_type_attribute_point_to_local_class_if_needed(attributes_map)
154
+ if attributes_map['type'].is_a?(String)
155
+ attributes_map['type'] = to_local_class_name(attributes_map['type'])
156
+ end
157
+ end
158
+
143
159
  def disable_all_callbacks_for(base_class)
144
160
  [:create, :save, :update, :validate, :touch].each { |callback| base_class.reset_callbacks callback }
145
161
  end
@@ -1,3 +1,3 @@
1
1
  module Forceps
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
Binary file
Binary file