Class: SmartCore::Initializer::Attribute Private
- Inherits:
-
Object
- Object
- SmartCore::Initializer::Attribute
- Defined in:
- lib/smart_core/initializer/attribute.rb,
lib/smart_core/initializer/attribute/builder.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.
Defined Under Namespace
Modules: Builder, ValueFinalizer
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.
{ private: :private, protected: :protected, public: :public, default: :public }.freeze
Instance Attribute Summary collapse
- #finalizer ⇒ SmartCore::Initializer::Attribute::ValueFinalizer::Lambda, SmartCore::Initializer::Attribute::ValueFinalizer::Method readonly private
- #name ⇒ Symbol readonly private
- #options ⇒ Hash<Symbol,Any> readonly private
- #privacy ⇒ Symbol readonly private
- #type ⇒ String, Symbol readonly private
Instance Method Summary collapse
- #default_value ⇒ Any private
- #dup ⇒ SmartCore::Intializer::Attribute private
- #finalize(value, instance) ⇒ Any private
- #has_default_value? ⇒ Boolean private
- #initialize(name, type, privacy, finalizer, **options) ⇒ void constructor private
- #validate_value_type!(value) ⇒ void private
Constructor Details
#initialize(name, type, privacy, finalizer, **options) ⇒ 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.
61 62 63 64 65 66 67 |
# File 'lib/smart_core/initializer/attribute.rb', line 61 def initialize(name, type, privacy, finalizer, **) @name = name @type = type @privacy = privacy @finalizer = finalizer = end |
Instance Attribute Details
#finalizer ⇒ SmartCore::Initializer::Attribute::ValueFinalizer::Lambda, SmartCore::Initializer::Attribute::ValueFinalizer::Method (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.
43 44 45 |
# File 'lib/smart_core/initializer/attribute.rb', line 43 def finalizer @finalizer end |
#name ⇒ Symbol (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.
24 25 26 |
# File 'lib/smart_core/initializer/attribute.rb', line 24 def name @name end |
#options ⇒ Hash<Symbol,Any> (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.
49 50 51 |
# File 'lib/smart_core/initializer/attribute.rb', line 49 def end |
#privacy ⇒ Symbol (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.
36 37 38 |
# File 'lib/smart_core/initializer/attribute.rb', line 36 def privacy @privacy end |
#type ⇒ String, Symbol (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.
30 31 32 |
# File 'lib/smart_core/initializer/attribute.rb', line 30 def type @type end |
Instance Method Details
#default_value ⇒ Any
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.
98 99 100 101 102 103 104 |
# File 'lib/smart_core/initializer/attribute.rb', line 98 def default_value default_value = .fetch(:default) do raise(SmartCore::Initializer::ArgumentError, 'Default value is not provided.') end default_value.is_a?(Proc) ? default_value.call : default_value end |
#dup ⇒ SmartCore::Intializer::Attribute
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.
120 121 122 |
# File 'lib/smart_core/initializer/attribute.rb', line 120 def dup self.class.new(name, type, privacy, finalizer, **) end |
#finalize(value, instance) ⇒ Any
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.
112 113 114 |
# File 'lib/smart_core/initializer/attribute.rb', line 112 def finalize(value, instance) finalizer.finalize(value, instance) end |
#has_default_value? ⇒ 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.
73 74 75 |
# File 'lib/smart_core/initializer/attribute.rb', line 73 def has_default_value? .key?(:default) end |
#validate_value_type!(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.
82 83 84 85 86 87 88 89 90 |
# File 'lib/smart_core/initializer/attribute.rb', line 82 def validate_value_type!(value) type_checker = SmartCore::Initializer.get_type(type) raise( SmartCore::Initializer::ArgumentError, "Incorrect type of <#{name}> attribute " \ "(given: #{value.class}, expected: :#{type_checker.name})" ) unless type_checker.comparable?(value) end |