Class: SmartCore::Initializer::Attribute::Value::Base Private

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

Direct Known Subclasses

Option, Param

Constant Summary collapse

PRIVACY_MODES =

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:

  • (Hash<Symbol,Symbol>)

Since:

  • 0.8.0

{
  public:    :public,
  protected: :protected,
  private:   :private
}.freeze
DEFAULT_PRIVACY_MODE =

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:

  • (Symbol)

Since:

  • 0.8.0

PRIVACY_MODES[:public]
DEFAULT_FINALIZER =

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:

  • (Proc)

Since:

  • 0.8.0

proc { |value| value }.freeze
DEFAULT_AS =

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:

  • (NilClass)

Since:

  • 0.8.0

nil
DEFAULT_MUTABLE =

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, type_system, privacy, finalizer, cast, mutable, as) ⇒ 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



103
104
105
106
107
108
109
110
111
112
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 103

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

Instance Attribute Details

#asString, ... (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, NilClass)

Since:

  • 0.8.0



89
90
91
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 89

def as
  @as
end

#castBoolean (readonly) Also known as: cast?

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



75
76
77
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 75

def cast
  @cast
end

#finalizerSmartCore::Initializer::Attribute::Finalizer::AnonymousBlock, SmartCore::Initializer::Attribute::Finalizer::InstanceMethod (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.



69
70
71
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 69

def finalizer
  @finalizer
end

#mutableBoolean (readonly) Also known as: mutable?

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



82
83
84
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 82

def mutable
  @mutable
end

#nameSymbol (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:

  • (Symbol)

Since:

  • 0.8.0



44
45
46
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 44

def name
  @name
end

#privacySymbol (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:

  • (Symbol)

Since:

  • 0.8.0



62
63
64
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 62

def privacy
  @privacy
end

#typeSmartCore::Initializer::TypeSystem::Interop (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.



50
51
52
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 50

def type
  @type
end

#type_systemClass<SmartCore::Initilizer::TypeSystem::Interop> (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:

  • (Class<SmartCore::Initilizer::TypeSystem::Interop>)

Since:

  • 0.8.0



56
57
58
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 56

def type_system
  @type_system
end

Instance Method Details

#validate!(value) ⇒ 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.

This method returns an undefined value.

Parameters:

  • value (Any)

Since:

  • 0.8.0



119
120
121
122
123
124
125
126
127
# File 'lib/smart_core/initializer/attribute/value/base.rb', line 119

def validate!(value)
  type.validate!(value)
rescue => error # TODO: move to typesystem interop
  raise(
    SmartCore::Initializer::IncorrectTypeError,
    "Validation of attribute `#{name}` failed:" \
    "(expected: #{type.identifier}, got: #{value.class}) \"#{error.message}\""
  )
end