Skip to content

Commit

Permalink
Explicitly define :_default_attribute_values using `class_attribute…
Browse files Browse the repository at this point in the history
…` in child class.

Fix FooBarWidget#100
  • Loading branch information
koji.tsuchiya committed Dec 26, 2024
1 parent 2196b23 commit ab9ccba
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 ab9ccba

Please sign in to comment.