lib/alba/resource.rb in alba-0.4.0 vs lib/alba/resource.rb in alba-0.5.0

- old
+ new

@@ -31,23 +31,31 @@ serializer = case with when nil @_serializer || Alba::Serializers::DefaultSerializer when ->(obj) { obj.is_a?(Class) && obj <= Alba::Serializer } with - when Symbol - const_get(with.to_s.capitalize) - when String - const_get(with) + when Proc + inline_extended_serializer(with) + else + raise ArgumentError, 'Unexpected type for with, possible types are Class or Proc' end serializer.new(serializable_hash).serialize end def serializable_hash @_attributes.transform_values do |attribute| attribute.to_hash(@_resource) end end alias to_hash serializable_hash + + private + + def inline_extended_serializer(with) + klass = ::Alba::Serializers::DefaultSerializer.clone + klass.class_eval(&with) + klass + end end # Class methods module ClassMethods attr_accessor(*DSLS)