Merge pull request #662 from jastkand/remove-question-sign

Add auto-stripping of question mark for attributes
This commit is contained in:
Steve Klabnik
2014-09-26 10:35:43 -04:00
3 changed files with 32 additions and 4 deletions

View File

@@ -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]