* Rename NullAdapter to SimpleAdapter

* Introduce abstract Adapter class
* Organaze test structure to match convemtions
This commit is contained in:
Tema Bolshakov
2014-08-27 08:17:36 +04:00
parent 0c13956311
commit f00fe5595d
7 changed files with 52 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ module ActiveModel
extend ActiveSupport::Autoload
autoload :Configuration
autoload :ArraySerializer
autoload :Adapter
include Configuration
class << self

View 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

View File

@@ -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