Module: Net::IMAP::Config::AttrTypeCoercion
Do not use. This module is for internal use only.
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
| |
| Defined in: | lib/net/imap/config/attr_type_coercion.rb |
Overview
NOTE: This module is an internal implementation detail, with no guarantee of backward compatibility.
Adds a type keyword parameter to .attr_accessor, to enforce that config attributes have valid types, for example: boolean, numeric, enumeration, non-nullable, etc.
Constant Summary
-
Enum =
# File 'lib/net/imap/config/attr_type_coercion.rb', line 62->(*enum) { safe_enum = safe{enum} expected = -"one of #{safe_enum.map(&:inspect).join(", ")}" safe{->val { return val if safe_enum.include?(val) raise ArgumentError, "expected %s, got %p" % [expected, val] }} }
-
NilOrInteger =
# File 'lib/net/imap/config/attr_type_coercion.rb', line 60safe{->val { Integer val unless val.nil? }}
-
Types =
# File 'lib/net/imap/config/attr_type_coercion.rb', line 50Hash.new do |h, type| type => Proc | nil; safe{type} end
Class Method Summary
- .attr_accessor(attr, type: nil)
- .included(mod) private
-
.safe(&b)
private
See additional method definition at line 32.
Class Method Details
.attr_accessor(attr, type: nil)
[ GitHub ]# File 'lib/net/imap/config/attr_type_coercion.rb', line 54
def self.attr_accessor(attr, type: nil) type = Types[type] or return define_method :"#{attr}=" do |val| super type[val] end define_method :"#{attr}?" do send attr end if type == Boolean end
.included(mod) (private)
[ GitHub ]# File 'lib/net/imap/config/attr_type_coercion.rb', line 26
def self.included(mod) mod.extend Macros end
.safe(&b) (private)
See additional method definition at line 32.
See additional method definition at line 41.
# File 'lib/net/imap/config/attr_type_coercion.rb', line 46
def self.safe(&b) case obj = b.call when Proc Ractor.shareable_proc(&obj) else Ractor.make_shareable obj end end