Skip to content

Commit

Permalink
hardening default option: proc/lambda executes in the instance contex…
Browse files Browse the repository at this point in the history
…t, but object with #call method doesn't
  • Loading branch information
dmgr committed Oct 20, 2021
1 parent fceab9e commit f9357b0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/active_attr/attribute_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def _attribute_default(attribute_name)
default = self.class.attributes[attribute_name][:default]

case
when default.respond_to?(:call) then instance_exec(&default)
when default.is_a?(Proc) then instance_exec(&default)
when default.respond_to?(:call) then default.call
when default.duplicable? then default.dup
else default
end
Expand Down

0 comments on commit f9357b0

Please sign in to comment.