Class: SmartCore::Initializer::Attribute::Value::Option Private

Inherits:
Base
  • Object
show all
Defined in:
lib/smart_core/initializer/attribute/value/option.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.

Since:

  • 0.8.0

Constant Summary collapse

UNDEFINED_DEFAULT =

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

Returns:

  • (Object)

Since:

  • 0.8.0

::Object.new.tap(&:freeze)
DEFAULT_OPTIONAL =

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

Returns:

  • (Boolean)

Since:

  • 0.8.0

false

Constants inherited from Base

Base::DEFAULT_AS, Base::DEFAULT_FINALIZER, Base::DEFAULT_MUTABLE, Base::DEFAULT_PRIVACY_MODE, Base::PRIVACY_MODES

Instance Attribute Summary collapse

Attributes inherited from Base

#as, #cast, #finalizer, #klass, #mutable, #name, #privacy, #type, #type_system

Instance Method Summary collapse

Methods inherited from Base

#validate!

Constructor Details

#initialize(klass, name, type, type_system, privacy, finalizer, cast, mutable, as, default, optional) ⇒ void

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.

Parameters:

Since:

  • 0.8.0



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/smart_core/initializer/attribute/value/option.rb', line 41

def initialize(
  klass,
  name,
  type,
  type_system,
  privacy,
  finalizer,
  cast,
  mutable,
  as,
  default,
  optional
)
  super(klass, name, type, type_system, privacy, finalizer, cast, mutable, as)
  @default = default
  @optional = optional
end

Instance Attribute Details

#optionalBoolean (readonly) Also known as: optional?

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)

Since:

  • 0.8.0



23
24
25
# File 'lib/smart_core/initializer/attribute/value/option.rb', line 23

def optional
  @optional
end

Instance Method Details

#defaultAny

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:

  • (Any)

Raises:

Since:

  • 0.8.0



73
74
75
76
77
78
79
80
# File 'lib/smart_core/initializer/attribute/value/option.rb', line 73

def default
  raise(
    SmartCore::Initializer::NoDefaultValueError,
    "Attribute #{name} has no default value"
  ) if @default.equal?(UNDEFINED_DEFAULT)

  @default.is_a?(Proc) ? @default.call : @default.dup
end

#dupSmartCore::Initializer::Attribute::Value::Option

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.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/smart_core/initializer/attribute/value/option.rb', line 86

def dup
  default = @default.equal?(UNDEFINED_DEFAULT) ? @default : @default.dup

  self.class.new(
    klass,
    name.dup,
    type,
    type_system,
    privacy,
    finalizer.dup,
    cast,
    mutable,
    as,
    default,
    optional
  )
end

#has_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)

Since:

  • 0.8.0



63
64
65
# File 'lib/smart_core/initializer/attribute/value/option.rb', line 63

def has_default?
  !@default.equal?(UNDEFINED_DEFAULT)
end