lib/seed_helper.rb in seed_helper-1.8.0 vs lib/seed_helper.rb in seed_helper-1.9.0

- old
+ new

@@ -16,14 +16,18 @@ # @param [Class] resource_class: The class to create the resource in. EG: User # @param [Hash] identifiable_attributes: A hash of attributes and values that can be used to # identify the given resource. EG: {email: "jordan@example.com"} # @param [Hash] additional_attributes: A hash of attributes and values that don't identify # the given resource, but should be assigned to the new resource. - def self.find_or_create_resource(resource_class, identifiable_attributes, additional_attributes={}) + def self.find_or_create_resource(resource_class, identifiable_attributes, additional_attributes={}, &constructor) if resource = find_resource(resource_class, identifiable_attributes) resource_already_exists(resource) else - resource = resource_class.new(identifiable_attributes.merge(additional_attributes)) + if constructor.present? + resource = constructor.call + else + resource = resource_class.new(identifiable_attributes.merge(additional_attributes)) + end create_resource(resource) end return resource end