You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working in a little Sinatra app and found that after deserializing with the Resource class defined I here, I can't seem to get to the attributes because the to_h method give me nothing.
The get_jsonapi method was defined elsewhere and does the http call and returns the response data that lives under "data" key.
As you can see, the deserializer properly pulls the attribute out but does not fill the @hash attribute so the to_h doesn't give me any data back.
# in a console
> jsonapi=get_jsonapi("studios/1890-bryant-street-studios.json")=>{"id"=>"3","type"=>"studio","attributes"=>{"name"=>"1890 Bryant Street Studios","street_address"=>"1890 bryant st","city"=>"New Ginaberg","map_url"=>"http://maps.google.com/maps?q=1890+bryant+st%2C+New+Ginaberg%2C+Kansas%2C+87776","url"=>"/studios/1890-bryant-street-studios","slug"=>"1890-bryant-street-studios"},"relationships"=>{"artists"=>{"meta"=>{"count"=>27}}}}
> studio=JSONAPI::Deserializable::Resource.new(jsonapi)=>#<JSONAPI::Deserializable::Resource:0x00007fc8663fcab0@attributes={"name"=>"1890 Bryant Street Studios","street_address"=>"1890 bryant st","city"=>"New Ginaberg","map_url"=>"http://maps.google.com/maps?q=1890+bryant+st%2C+New+Ginaberg%2C+Kansas%2C+87776","url"=>"/studios/1890-bryant-street-studios","slug"=>"1890-bryant-street-studios"},@data={"id"=>"3","type"=>"studio","attributes"=>{"name"=>"1890 Bryant Street Studios","street_address"=>"1890 bryant st","city"=>"New Ginaberg","map_url"=>"http://maps.google.com/maps?q=1890+bryant+st%2C+New+Ginaberg%2C+Kansas%2C+87776","url"=>"/studios/1890-bryant-street-studios","slug"=>"1890-bryant-street-studios"},"relationships"=>{"artists"=>{"meta"=>{"count"=>27}}}},@hash={},@id="3",@relationships={"artists"=>{"meta"=>{"count"=>27}}},@reverse_mapping={},@root="/data",@type="studio">
> studio.to_h=>{}
Am I mis-using things? Or is this a bug?
I did a tiny bit of digging and it seems that in resource.rb where you define
I found that if I make a little thing I can subclass from, and I define the default_attr_block the same way it's defined in the deserializable/resource/dsl.rb in this gem, things work out.
Hi
I'm working in a little Sinatra app and found that after deserializing with the
Resource
class defined I here, I can't seem to get to the attributes because theto_h
method give me nothing.The
get_jsonapi
method was defined elsewhere and does the http call and returns the response data that lives under "data" key.As you can see, the deserializer properly pulls the attribute out but does not fill the
@hash
attribute so theto_h
doesn't give me any data back.Am I mis-using things? Or is this a bug?
I did a tiny bit of digging and it seems that in
resource.rb
where you definethe
block
is actuallynil
. Is that expected? Am I supposed to define adefault_attr_block
?The text was updated successfully, but these errors were encountered: