Due to the way the serialization mechanism is written, attributes in a serializer cannot be named either model or options, because these methods are already defined on CacheCrispies::Base. No warning or error is thrown either.
The following example demonstrates this:
#!/usr/bin/env ruby
require "cache_crispies"
class MySerializer < CacheCrispies::Base
key :my_serializer
serialize :id
serialize :options do |model, options|
# the passed `model` will not be the model, but rather the instance
# of the serializer. To retrieve the model, we have to call
# `model.model`.
model.model.options
end
end
model = OpenStruct.new(id: "my_id", options: { my_option: true })
puts MySerializer.new(model, {}).as_json
=> {:id=>"my_id", :options=>{}}
Due to the way the serialization mechanism is written, attributes in a serializer cannot be named either
model
oroptions
, because these methods are already defined onCacheCrispies::Base
. No warning or error is thrown either.The following example demonstrates this:
The logic that exhibits this can be found on https://github.com/codenoble/cache-crispies/blob/master/lib/cache_crispies/hash_builder.rb#L63.