mirror of
https://github.com/ditkrg/jsonapi-deserializable.git
synced 2026-01-22 13:56:50 +00:00
Cleanup. (#2)
This commit is contained in:
parent
446102275c
commit
a816fa56dd
@ -24,23 +24,25 @@ module JSONAPI
|
||||
deserialize!
|
||||
end
|
||||
|
||||
def to_h
|
||||
def to_hash
|
||||
@hash
|
||||
end
|
||||
alias to_h to_hash
|
||||
|
||||
private
|
||||
|
||||
def deserialize!
|
||||
@hash = {}
|
||||
return unless @document.key?('data')
|
||||
if @data.is_a?(Array)
|
||||
deserialize_has_many!
|
||||
else
|
||||
elsif @data.nil? || @data.is_a?(Hash)
|
||||
deserialize_has_one!
|
||||
end
|
||||
end
|
||||
|
||||
def deserialize_has_one!
|
||||
return unless self.class.has_one_block && @document.key?('data')
|
||||
return unless self.class.has_one_block
|
||||
id = @data && @data['id']
|
||||
type = @data && @data['type']
|
||||
instance_exec(@document, id, type, &self.class.has_one_block)
|
||||
|
||||
@ -6,13 +6,12 @@ module JSONAPI
|
||||
include ResourceDSL
|
||||
|
||||
class << self
|
||||
attr_accessor :type_block, :id_block
|
||||
attr_accessor :attr_blocks
|
||||
attr_accessor :has_one_rel_blocks, :has_many_rel_blocks
|
||||
attr_accessor :type_block, :id_block, :attr_blocks,
|
||||
:has_one_rel_blocks, :has_many_rel_blocks
|
||||
end
|
||||
|
||||
self.attr_blocks = {}
|
||||
self.has_one_rel_blocks = {}
|
||||
self.has_one_rel_blocks = {}
|
||||
self.has_many_rel_blocks = {}
|
||||
|
||||
def self.inherited(klass)
|
||||
@ -38,9 +37,10 @@ module JSONAPI
|
||||
deserialize!
|
||||
end
|
||||
|
||||
def to_h
|
||||
def to_hash
|
||||
@hash
|
||||
end
|
||||
alias to_h to_hash
|
||||
|
||||
private
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user