Skip to content

Commit

Permalink
Merge pull request #101 from k-tsuchiya-jp/fix-100
Browse files Browse the repository at this point in the history
Explicitly define `:_default_attribute_values` using `class_attribute` in child class
  • Loading branch information
jrafanie authored Jan 3, 2025
2 parents 2196b23 + ab9ccba commit 1486999
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/default_value_for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,18 @@ def default_value_for(attribute, options = {}, &block)
allows_nil = opts.fetch('allows_nil', true)
end

if !method_defined?(:set_default_values)
if !singleton_methods(false).include?(:_default_attribute_values)
include(InstanceMethods)

after_initialize :set_default_values

class_attribute :_default_attribute_values
class_attribute :_default_attribute_values_not_allowing_nil

extend(DelayedClassMethods)
init_hash = true
else
init_hash = !singleton_methods(false).include?(:_default_attribute_values)
end

if init_hash
self._default_attribute_values = {}
self._default_attribute_values_not_allowing_nil = []

extend(DelayedClassMethods)
end

if block_given?
Expand Down

0 comments on commit 1486999

Please sign in to comment.