Class: ENM::Enum::DryTypeBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/enm/enum.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Builds a Dry::Types::Type for an ENM::Enum.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDryTypeBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DryTypeBuilder.



52
53
54
55
56
# File 'lib/enm/enum.rb', line 52

def initialize(...)
  super

  @default = derive_real_default
end

Instance Attribute Details

#defaultString, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String, Symbol, nil)


50
51
52
# File 'lib/enm/enum.rb', line 50

def default
  @default
end

Instance Method Details

#callDry::Types::Type

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Dry::Types::Type)


59
60
61
62
63
64
65
66
67
# File 'lib/enm/enum.rb', line 59

def call
  base = build_base

  type = default? ? base.default(default.freeze) : base

  enum_values = symbol? ? enum.map(&:to_sym) : enum.to_a

  type.enum(*enum_values)
end

#default?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


69
# File 'lib/enm/enum.rb', line 69

def default? = !default_value.nil?

#symbol?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


71
# File 'lib/enm/enum.rb', line 71

def symbol? = mode == :symbol