mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Merge pull request #662 from jastkand/remove-question-sign
Add auto-stripping of question mark for attributes
This commit is contained in:
@@ -79,10 +79,12 @@ end
|
||||
end
|
||||
|
||||
def attributes(*attrs)
|
||||
@_attributes.concat attrs
|
||||
|
||||
attrs.each do |attr|
|
||||
define_method attr do
|
||||
striped_attr = strip_attribute attr
|
||||
|
||||
@_attributes << striped_attr
|
||||
|
||||
define_method striped_attr do
|
||||
object.read_attribute_for_serialization attr
|
||||
end unless method_defined?(attr)
|
||||
end
|
||||
@@ -98,6 +100,14 @@ end
|
||||
|
||||
private
|
||||
|
||||
def strip_attribute(attr)
|
||||
symbolized = attr.is_a?(Symbol)
|
||||
|
||||
attr = attr.to_s.gsub(/\?\Z/, '')
|
||||
attr = attr.to_sym if symbolized
|
||||
attr
|
||||
end
|
||||
|
||||
def build_serializer_class(resource, options)
|
||||
"".tap do |klass_name|
|
||||
klass_name << "#{options[:namespace]}::" if options[:namespace]
|
||||
|
||||
Reference in New Issue
Block a user