lib/mutils/serialization/serialization_methods.rb in mutils-0.2.34 vs lib/mutils/serialization/serialization_methods.rb in mutils-0.2.35
- old
+ new
@@ -27,20 +27,21 @@
value = { method: type == 'method', always_include: true }
attributes_to_serialize[attr] = value
end
end
- def attribute(method_name, always_include = false)
- add_single_attribute(method_name, always_include, 'attribute')
+ def attribute(method_name, options = {})
+ add_single_attribute(method_name, options, 'attribute')
end
- def custom_method(method_name, always_include = false)
- add_single_attribute(method_name, always_include, 'method')
+ def custom_method(method_name, options = {})
+ add_single_attribute(method_name, options, 'method')
end
- def add_single_attribute(method_name, always_include, type)
+ def add_single_attribute(method_name, options, type)
self.attributes_to_serialize = {} if attributes_to_serialize.nil?
+ always_include = options[:always_include].nil? ? false : options[:always_include]
value = { method: type == 'method', always_include: always_include }
attributes_to_serialize[method_name] = value
end
def relationship(relationship_name, options = {}, option_name = 'belongs_to')
@@ -62,9 +63,10 @@
end
raise "Serializer class not defined for relationship: #{relationship_name}" unless class_exists? class_name
options[:serializer] = class_name.to_s.constantize
options[:option_name] = option_name
+ options[:label] = options[:label]
options
end
def class_exists?(class_name)
klass = class_name.to_s.constantize rescue nil