Class: T::Props::Private::ApplyDefault
- Inherits:
-
Object
- Object
- T::Props::Private::ApplyDefault
- Defined in:
- lib/types/props/private/apply_default.rb
Direct Known Subclasses
ApplyDefaultFactory, ApplyEmptyArrayDefault, ApplyEmptyHashDefault, ApplyFixedDefault
Constant Summary collapse
- NO_CLONE_TYPES =
T.let([TrueClass, FalseClass, NilClass, Symbol, Numeric, T::Enum].freeze, T::Array[Module])
Constants included from Helpers
Instance Attribute Summary collapse
-
#setter_proc ⇒ Object
readonly
Returns the value of attribute setter_proc.
Class Method Summary collapse
Instance Method Summary collapse
- #default ⇒ Object
-
#initialize(accessor_key, setter_proc) ⇒ ApplyDefault
constructor
A new instance of ApplyDefault.
- #set_default(instance) ⇒ Object
Methods included from Sig
Methods included from Helpers
abstract!, final!, interface!, mixes_in_class_methods, requires_ancestor, sealed!
Constructor Details
#initialize(accessor_key, setter_proc) ⇒ ApplyDefault
Returns a new instance of ApplyDefault.
17 18 19 20 |
# File 'lib/types/props/private/apply_default.rb', line 17 def initialize(accessor_key, setter_proc) @accessor_key = T.let(accessor_key, Symbol) @setter_proc = T.let(setter_proc, SetterFactory::SetterProc) end |
Instance Attribute Details
#setter_proc ⇒ Object (readonly)
Returns the value of attribute setter_proc.
13 14 15 |
# File 'lib/types/props/private/apply_default.rb', line 13 def setter_proc @setter_proc end |
Class Method Details
.for(cls, rules) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/types/props/private/apply_default.rb', line 34 def self.for(cls, rules) accessor_key = rules.fetch(:accessor_key) setter = rules.fetch(:setter_proc) if rules.key?(:factory) ApplyDefaultFactory.new(cls, rules.fetch(:factory), accessor_key, setter) elsif rules.key?(:default) default = rules.fetch(:default) case default when *NO_CLONE_TYPES return ApplyPrimitiveDefault.new(default, accessor_key, setter) when String if default.frozen? return ApplyPrimitiveDefault.new(default, accessor_key, setter) end when Array if default.empty? && default.class == Array return ApplyEmptyArrayDefault.new(accessor_key, setter) end when Hash if default.empty? && default.default.nil? && T.unsafe(default).default_proc.nil? && default.class == Hash return ApplyEmptyHashDefault.new(accessor_key, setter) end end ApplyComplexDefault.new(default, accessor_key, setter) else nil end end |
Instance Method Details
#default ⇒ Object
24 |
# File 'lib/types/props/private/apply_default.rb', line 24 def default; end |
#set_default(instance) ⇒ Object
28 |
# File 'lib/types/props/private/apply_default.rb', line 28 def set_default(instance); end |