Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Slightly modified how extra serialized properties should work
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Jul 11, 2008
1 parent 4c762b3 commit 8d3d8be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
13 changes: 7 additions & 6 deletions lib/dm-serializer.rb
Expand Up @@ -27,19 +27,20 @@ def to_json(options = {})
excluded_properties = Array(options[:exclude])
exclude_read_only = options[:without_read_only_attributes] || false

propset = self.class.properties(repository.name).dup
if self.class.respond_to?(:serialize_properties)
self.class.serialize_properties(repository.name).each {|p| propset << Property.new(self.class, p, String) }
end

propset = propset.reject do |p|
propset = self.class.properties.reject do |p|
next if only_properties.include? p.name
excluded_properties.include?(p.name) || !(only_properties.empty? || only_properties.include?(p.name))
end

fields += propset.map do |property|
"#{property.name.to_json}: #{send(property.getter).to_json}"
end

if self.respond_to?(:serialize_properties)
self.serialize_properties.each do |k,v|
fields << "#{k.to_json}: #{v.to_json}"
end
end

if self.class.respond_to?(:read_only_attributes) && exclude_read_only
self.class.read_only_attributes.each do |property|
Expand Down
12 changes: 2 additions & 10 deletions spec/fixtures/cow.rb
Expand Up @@ -6,15 +6,7 @@ class Cow
property :name, String
property :breed, String

def self.serialize_properties(*args)
[:extra, :another]
end

def extra
"Extra"
end

def another
42
def serialize_properties
{:extra => "Extra", :another => 42}
end
end

0 comments on commit 8d3d8be

Please sign in to comment.