lib/restpack_serializer/serializable.rb in restpack_serializer-0.6.10 vs lib/restpack_serializer/serializable.rb in restpack_serializer-0.6.11

- old
+ new

@@ -55,15 +55,19 @@ end end end add_custom_attributes(data) - add_links(model, data) unless self.class.associations.empty? + add_links(model, data) if self.class.has_associations? data end + def to_json(model, context = {}) + as_json(model, context).to_json + end + def custom_attributes nil end private @@ -138,13 +142,17 @@ @user_defined_methods << name end end def has_user_defined_method?(method_name) - user_defined_methods = self.user_defined_methods || [] - return true if user_defined_methods.include?(method_name) - return self.superclass.try(:has_user_defined_method?, method_name) + if user_defined_methods && user_defined_methods.include?(method_name) + true + elsif superclass.respond_to?(:has_user_defined_method?) + superclass.has_user_defined_method?(method_name) + else + false + end end def memoized_has_user_defined_method?(method_name) @memoized_user_defined_methods ||= {} @@ -161,9 +169,13 @@ new.as_json(models, context) end def as_json(model, context = {}) new.as_json(model, context) + end + + def to_json(model, context = {}) + new.as_json(model, context).to_json end def serialize(models, context = {}) models = [models] unless models.kind_of?(Array)