Skip to content

Commit

Permalink
Closes #21 (need to add test cases)
Browse files Browse the repository at this point in the history
  • Loading branch information
dima committed May 11, 2010
1 parent d592f7e commit 76ada93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 14 additions & 15 deletions lib/restfulx/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def serialize
def serializable_attributes
includes = @options[:include] ||= {}

associations = Hash[*@record.class.reflect_on_all_associations(:belongs_to).collect do |assoc|
[assoc.primary_key_name, {:name => assoc.name, :klass => assoc.klass}]
associations = Hash[*@record.class.reflect_on_all_associations(:belongs_to).collect do |assoc|
class_name = assoc.options.has_key?(:polymorphic) && assoc.options[:polymorphic] ? @record[assoc.options[:foreign_type]].constantize : assoc.klass
[assoc.primary_key_name, {:name => assoc.name, :klass => class_name}]
end.flatten]

serializable_names.select do |name|
Expand Down Expand Up @@ -81,6 +82,17 @@ def to_fxml(options = {}, &block)
end

module ActiveRecord
# ActiveRecord named scopes are computed *before* restfulx gem gets loaded
# this patch addresses that and makes sure +to_fxml+ calls are properly
# delegated
module NamedScope
# make sure we properly delegate +to_fxml+ calls to the proxy
class Scope
delegate :to_fxml, :to => :proxy_found
delegate :to_amf, :to => :proxy_found
end
end

# Change the xml serializer so that '?'s are stripped from attribute names.
# This makes it possible to serialize methods that end in a question mark, like 'valid?' or 'is_true?'
class XmlSerializer
Expand Down Expand Up @@ -129,17 +141,4 @@ def to_amf(options = {})
options[:serializer].serialize_errors(Hash[*@errors.to_a.flatten]).to_s
end
end
end

module ActiveRecord
# ActiveRecord named scopes are computed *before* restfulx gem gets loaded
# this patch addresses that and makes sure +to_fxml+ calls are properly
# delegated
module NamedScope
# make sure we properly delegate +to_fxml+ calls to the proxy
class Scope
delegate :to_fxml, :to => :proxy_found
delegate :to_amf, :to => :proxy_found
end
end
end
2 changes: 1 addition & 1 deletion lib/restfulx/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_executable(executable)

namespace :air do
desc "Build project swf file as an AIR application and move it into bin-debug folder"
task :build do
task :build do
compile_application(:destination => 'bin-debug', :opts => '+configname=air')
end

Expand Down

0 comments on commit 76ada93

Please sign in to comment.