lib/alba/association.rb in alba-2.4.3 vs lib/alba/association.rb in alba-3.0.0
- old
+ new
@@ -10,11 +10,12 @@
attr_reader :name
# @param name [Symbol, String] name of the method to fetch association
# @param condition [Proc, nil] a proc filtering data
- # @param resource [Class<Alba::Resource>, nil] a resource class for the association
+ # @param resource [Class<Alba::Resource>, Proc, String, Symbol, nil]
+ # a resource class for the association, a proc returning a resource class or a name of the resource
# @param params [Hash] params override for the association
# @param nesting [String] a namespace where source class is inferred with
# @param key_transformation [Symbol] key transformation type
# @param helper [Module] helper module to include
# @param block [Block] used to define resource when resource arg is absent
@@ -50,17 +51,19 @@
end
private
def constantize(resource)
- case resource # rubocop:disable Style/MissingElse
+ case resource
when Class
resource
when Symbol, String
Object.const_get(resource)
self.class.const_cache.fetch(resource) do
self.class.const_cache[resource] = Object.const_get(resource)
end
+ else
+ raise Error, "Unexpected resource type: #{resource.class}"
end
end
def assign_resource(nesting, key_transformation, block, helper) # rubocop:disable Metrics/MethodLength
@resource = if block