Class: Virtus::Attribute::DefaultValue Private

Inherits:
Object
  • Object
show all
Extended by:
DescendantsTracker
Defined in:
lib/virtus/attribute/default_value.rb,
lib/virtus/attribute/default_value/from_symbol.rb,
lib/virtus/attribute/default_value/from_callable.rb,
lib/virtus/attribute/default_value/from_clonable.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.

Class representing the default value option

Direct Known Subclasses

FromCallable, FromClonable, FromSymbol

Defined Under Namespace

Classes: FromCallable, FromClonable, FromSymbol

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DescendantsTracker

add_descendant, descendants

Constructor Details

#initialize(attribute, value) ⇒ undefined

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.

Initializes an default value instance

Parameters:



42
43
44
# File 'lib/virtus/attribute/default_value.rb', line 42

def initialize(attribute, value)
  @attribute, @value = attribute, value
end

Instance Attribute Details

#attributeVirtus::Attribute::Object (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 the attribute associated with this default value instance



25
26
27
# File 'lib/virtus/attribute/default_value.rb', line 25

def attribute
  @attribute
end

#valueObject (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 the value instance

Returns:



32
33
34
# File 'lib/virtus/attribute/default_value.rb', line 32

def value
  @value
end

Class Method Details

.build(*args) ⇒ Virtus::Attribute::DefaultValue

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.

Builds a default value instance



15
16
17
18
# File 'lib/virtus/attribute/default_value.rb', line 15

def self.build(*args)
  klass = descendants.detect { |descendant| descendant.handle?(*args) } || self
  klass.new(*args)
end

Instance Method Details

#evaluate(instance) ⇒ Object

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.

Evaluates the value

Parameters:

Returns:

  • (Object)

    evaluated value



53
54
55
# File 'lib/virtus/attribute/default_value.rb', line 53

def evaluate(instance)
  value
end