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:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
::Net::IMAP::Utils
|
|
| 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 50shareable{->(*enum) { safe_enum = Utils.shareable{enum} expected = -"one of #{safe_enum.map(&:inspect).join(", ")}" Utils.shareable{->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 48shareable{->val { Integer val unless val.nil? }}
-
Types =
# File 'lib/net/imap/config/attr_type_coercion.rb', line 35Hash.new do |h, type| type => Proc | nil Utils.shareable{type} end
Class Method Summary
::Net::IMAP::Utils - Extended
| implicit_int | Something like this exists in ruby's C API. |
| shareable | simplecov:disable. |
Class Method Details
.attr_accessor(attr, type: nil)
[ GitHub ]# File 'lib/net/imap/config/attr_type_coercion.rb', line 42
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 28
def self.included(mod) mod.extend Macros end