Skip to content

Commit

Permalink
hardening default option: only proc/lambda executes in the instance c…
Browse files Browse the repository at this point in the history
…ontext
  • Loading branch information
dmgr committed Oct 20, 2021
1 parent fceab9e commit 84970a4
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 84970a4

Please sign in to comment.