Class: T::Props::Private::ApplyDefaultFactory

Inherits:
ApplyDefault
  • Object
show all
Defined in:
lib/types/props/private/apply_default.rb

Constant Summary

Constants inherited from ApplyDefault

T::Props::Private::ApplyDefault::NO_CLONE_TYPES

Constants included from Helpers

Helpers::Private

Instance Attribute Summary

Attributes inherited from ApplyDefault

#setter_proc

Instance Method Summary collapse

Methods inherited from ApplyDefault

for

Methods included from Sig

#sig

Methods included from Helpers

#abstract!, #final!, #interface!, #mixes_in_class_methods, #requires_ancestor, #sealed!

Constructor Details

#initialize(cls, factory, accessor_key, setter_proc) ⇒ ApplyDefaultFactory

Returns a new instance of ApplyDefaultFactory.



149
150
151
152
153
# File 'lib/types/props/private/apply_default.rb', line 149

def initialize(cls, factory, accessor_key, setter_proc)
  @class = T.let(cls, Module)
  @factory = T.let(factory, T.any(Proc, Method))
  super(accessor_key, setter_proc)
end

Instance Method Details

#defaultObject



165
166
167
# File 'lib/types/props/private/apply_default.rb', line 165

def default
  @class.class_exec(&@factory)
end

#set_default(instance) ⇒ Object



157
158
159
160
161
# File 'lib/types/props/private/apply_default.rb', line 157

def set_default(instance)
  # Use the actual setter to validate the factory returns a legitimate
  # value every time
  instance.instance_exec(default, &@setter_proc)
end