method
serializable_hash
v3.0.9 -
Show latest stable
- Class:
ActiveModel::Serialization
serializable_hash(options = nil)public
No documentation available.
# File activemodel/lib/active_model/serialization.rb, line 69
def serializable_hash(options = nil)
options ||= {}
only = Array.wrap(options[:only]).map(&:to_s)
except = Array.wrap(options[:except]).map(&:to_s)
attribute_names = attributes.keys.sort
if only.any?
attribute_names &= only
elsif except.any?
attribute_names -= except
end
method_names = Array.wrap(options[:methods]).inject([]) do |methods, name|
methods << name if respond_to?(name.to_s)
methods
end
(attribute_names + method_names).inject({}) { |hash, name|
hash[name] = send(name)
hash
}
end