Module: T::Props::ClassMethods

Extended by:
Helpers, Sig
Defined in:
lib/types/props/_props.rb

Overview

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.

Constant Summary

Constants included from Helpers

Helpers::Private

Instance Method Summary collapse

Methods included from Sig

sig

Methods included from Helpers

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

Instance Method Details

#const(name, cls_or_args, **args) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/types/props/_props.rb', line 136

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

#decoratorObject



34
35
36
# File 'lib/types/props/_props.rb', line 34

def decorator
  @decorator ||= decorator_class.new(self)
end

#decorator_classObject



30
31
32
# File 'lib/types/props/_props.rb', line 30

def decorator_class
  Decorator
end

#extended(child) ⇒ Object



158
159
160
161
# File 'lib/types/props/_props.rb', line 158

def extended(child)
  decorator.model_inherited(child.singleton_class)
  super
end

#included(child) ⇒ Object



148
149
150
151
# File 'lib/types/props/_props.rb', line 148

def included(child)
  decorator.model_inherited(child)
  super
end

#inherited(child) ⇒ Object



163
164
165
166
# File 'lib/types/props/_props.rb', line 163

def inherited(child)
  decorator.model_inherited(child)
  super
end

#plugin(mod) ⇒ Object

Needs to be documented



130
131
132
# File 'lib/types/props/_props.rb', line 130

def plugin(mod)
  decorator.plugin(mod)
end

#pluginsObject



26
27
28
# File 'lib/types/props/_props.rb', line 26

def plugins
  @plugins ||= []
end

#prepended(child) ⇒ Object



153
154
155
156
# File 'lib/types/props/_props.rb', line 153

def prepended(child)
  decorator.model_inherited(child)
  super
end

#prop(name, cls, **rules) ⇒ Object



113
114
115
116
# File 'lib/types/props/_props.rb', line 113

def prop(name, cls, **rules)
  cls = T::Utils.coerce(cls) if !cls.is_a?(Module)
  decorator.prop_defined(name, cls, rules)
end

#propsObject



23
24
25
# File 'lib/types/props/_props.rb', line 23

def props
  decorator.props
end

#reload_decorator!Object



37
38
39
# File 'lib/types/props/_props.rb', line 37

def reload_decorator!
  @decorator = decorator_class.new(self)
end

#validate_prop_value(prop, val) ⇒ void

This method returns an undefined 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.

Parameters:

  • prop (Symbol)
  • val (Object)


125
126
127
# File 'lib/types/props/_props.rb', line 125

def validate_prop_value(prop, val)
  decorator.validate_prop_value(prop, val)
end