Class: ActiveInteractor::Context::Attribute
- Inherits:
-
Object
- Object
- ActiveInteractor::Context::Attribute
- Defined in:
- lib/active_interactor/context/attribute.rb
Constant Summary collapse
- NO_DEFAULT_VALUE =
:__no_default_value__
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#error_messages ⇒ Object
readonly
Returns the value of attribute error_messages.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #assign_value(value) ⇒ Object
- #default_value ⇒ Object
-
#initialize(owner, name, type, description = nil, **options) ⇒ Attribute
constructor
A new instance of Attribute.
- #required? ⇒ Boolean
- #type ⇒ Object
- #validate! ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(owner, name, type, description = nil, **options) ⇒ Attribute
Returns a new instance of Attribute.
9 10 11 12 13 14 15 16 |
# File 'lib/active_interactor/context/attribute.rb', line 9 def initialize(owner, name, type, description = nil, **) @owner = owner @name = name.to_sym @type_expression = type @description = description || [:description] @options = { required: false, default: NO_DEFAULT_VALUE }.merge() @error_messages = [] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/active_interactor/context/attribute.rb', line 7 def description @description end |
#error_messages ⇒ Object (readonly)
Returns the value of attribute error_messages.
7 8 9 |
# File 'lib/active_interactor/context/attribute.rb', line 7 def @error_messages end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/active_interactor/context/attribute.rb', line 7 def name @name end |
Instance Method Details
#assign_value(value) ⇒ Object
18 19 20 |
# File 'lib/active_interactor/context/attribute.rb', line 18 def assign_value(value) @user_provided_value = value end |
#default_value ⇒ Object
22 23 24 25 26 |
# File 'lib/active_interactor/context/attribute.rb', line 22 def default_value return if @options[:default] == NO_DEFAULT_VALUE @options[:default] end |
#required? ⇒ Boolean
28 29 30 |
# File 'lib/active_interactor/context/attribute.rb', line 28 def required? @options[:required] end |
#type ⇒ Object
32 33 34 |
# File 'lib/active_interactor/context/attribute.rb', line 32 def type @type_expression end |
#validate! ⇒ Object
36 37 38 |
# File 'lib/active_interactor/context/attribute.rb', line 36 def validate! validate_presence! && validate_type! end |
#value ⇒ Object
40 41 42 |
# File 'lib/active_interactor/context/attribute.rb', line 40 def value @user_provided_value || default_value end |