RestPack / restpack_serializer

Model serialization, paging, side-loading and filtering
MIT License
175 stars 43 forks source link

wrong constant lookup up multi word relations #68

Closed leword closed 10 years ago

leword commented 10 years ago

we have role serializer:

class RoleSerializer
  include RestPack::Serializer
  attributes :id, :name, :purpose
  can_include :role_scopes
end

and a role_scope_seriazlier:

class RoleScopeSerializer
  include RestPack::Serializer
  attributes :id, :description
end

when we to include role_scopes in the role seralization:

RoleSerializer.page({id: 23, includes: 'role_scopes'})

it throws NameError: uninitialized constant RoleScopeserializer.

Which comes from this method:

class RestPack::Serializer::Factory
  # ...
  def self.classify(identifier)
    begin
      "#{identifier}Serializer".classify.constantize.new
    rescue
      "#{identifier.to_s.singularize.to_sym}Serializer".classify.constantize.new
    end

"role_scopeSerializer".classify turns into "RoleScopeserializer". All that's needed is to change "Serializer" into "_Serializer" in both clauses.

GavinJoyce commented 10 years ago

https://github.com/RestPack/restpack_serializer/pull/79