module T::Props::ClassMethods
CAUTION: This mixin is used in hundreds of classes; we want to keep its surface area as narrow as possible and avoid polluting (and possibly conflicting with) the classes that use it.
It currently has zero instance methods; let's try to keep it that way. For ClassMethods
(below), try to add things to T::Props::Decorator
instead unless you are sure it needs to be exposed here.
Public Instance Methods
const(name, cls_or_args, args={})
click to toggle source
# File lib/types/props/_props.rb, line 139 def const(name, cls_or_args, args={}) if (cls_or_args.is_a?(Hash) && cls_or_args.key?(:immutable)) || args.key?(:immutable) Kernel.raise ArgumentError.new("Cannot pass 'immutable' argument when using 'const' keyword to define a prop") end if cls_or_args.is_a?(Hash) self.prop(name, cls_or_args.merge(immutable: true)) else self.prop(name, cls_or_args, args.merge(immutable: true)) end end
decorator()
click to toggle source
# File lib/types/props/_props.rb, line 34 def decorator @decorator ||= decorator_class.new(self) end
decorator_class()
click to toggle source
# File lib/types/props/_props.rb, line 30 def decorator_class Decorator end
extended(child)
click to toggle source
Calls superclass method
# File lib/types/props/_props.rb, line 161 def extended(child) decorator.model_inherited(child.singleton_class) super end
included(child)
click to toggle source
Calls superclass method
# File lib/types/props/_props.rb, line 151 def included(child) decorator.model_inherited(child) super end
inherited(child)
click to toggle source
Calls superclass method
# File lib/types/props/_props.rb, line 166 def inherited(child) decorator.model_inherited(child) super end
plugin(mod)
click to toggle source
Needs to be documented
# File lib/types/props/_props.rb, line 133 def plugin(mod) decorator.plugin(mod) end
plugins()
click to toggle source
# File lib/types/props/_props.rb, line 26 def plugins @plugins ||= [] end
prepended(child)
click to toggle source
Calls superclass method
# File lib/types/props/_props.rb, line 156 def prepended(child) decorator.model_inherited(child) super end
prop(name, cls, rules={})
click to toggle source
# File lib/types/props/_props.rb, line 114 def prop(name, cls, rules={}) cls = T::Utils.coerce(cls) if !cls.is_a?(Module) decorator.prop_defined(name, cls, rules) end
props()
click to toggle source
# File lib/types/props/_props.rb, line 23 def props decorator.props end
reload_decorator!()
click to toggle source
# File lib/types/props/_props.rb, line 37 def reload_decorator! @decorator = decorator_class.new(self) end
validate_prop_value(prop, val)
click to toggle source
@!method validate_prop_value
(propname, value)
Validates the value of the specified prop. This method allows the caller to
validate a value for a prop without having to set the data on the instance. Throws if invalid.
@param prop [Symbol] @param val [Object] @return [void]
# File lib/types/props/_props.rb, line 128 def validate_prop_value(prop, val) decorator.validate_prop_value(prop, val) end