mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
* Rename NullAdapter to SimpleAdapter
* Introduce abstract Adapter class * Organaze test structure to match convemtions
This commit is contained in:
20
lib/active_model/serializer/adapter.rb
Normal file
20
lib/active_model/serializer/adapter.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Adapter
|
||||
extend ActiveSupport::Autoload
|
||||
autoload :SimpleAdapter
|
||||
|
||||
def initialize(serializer)
|
||||
@attributes = serializer.attributes
|
||||
end
|
||||
|
||||
def serializable_hash(options = {})
|
||||
raise NotImplementedError, 'This is abstract method. Should be implemented at concrete adapter.'
|
||||
end
|
||||
|
||||
def to_json(options = {})
|
||||
raise NotImplementedError, 'This is abstract method. Should be implemented at concrete adapter.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,7 @@
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Adapter
|
||||
class NullAdapter
|
||||
def initialize(adapter)
|
||||
@attributes = adapter.attributes
|
||||
end
|
||||
|
||||
class SimpleAdapter < Adapter
|
||||
def to_json(options={})
|
||||
@attributes.each_with_object({}) do |(attr, value), h|
|
||||
h[attr] = value
|
||||
Reference in New Issue
Block a user