Class: Virtus::Attribute::Builder
- Inherits:
-
Object
- Object
- Virtus::Attribute::Builder
- Defined in:
- lib/virtus/attribute/builder.rb
Overview
Builder is used to set up an attribute instance based on input type and options
Instance Attribute Summary collapse
- #attribute ⇒ Object readonly
- #klass ⇒ Object readonly
- #options ⇒ Object readonly
- #type ⇒ Object readonly
- #type_definition ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type_definition, options) ⇒ Builder
constructor
private
A new instance of Builder.
Constructor Details
#initialize(type_definition, options) ⇒ Builder
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 a new instance of Builder.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/virtus/attribute/builder.rb', line 119 def initialize(type_definition, ) @type_definition = type_definition initialize_class initialize_type () initialize_default_value initialize_coercer initialize_attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
87 88 89 |
# File 'lib/virtus/attribute/builder.rb', line 87 def attribute @attribute end |
#klass ⇒ Object (readonly)
87 88 89 |
# File 'lib/virtus/attribute/builder.rb', line 87 def klass @klass end |
#options ⇒ Object (readonly)
87 88 89 |
# File 'lib/virtus/attribute/builder.rb', line 87 def @options end |
#type ⇒ Object (readonly)
87 88 89 |
# File 'lib/virtus/attribute/builder.rb', line 87 def type @type end |
#type_definition ⇒ Object (readonly)
87 88 89 |
# File 'lib/virtus/attribute/builder.rb', line 87 def type_definition @type_definition end |
Class Method Details
.call(type, options = {}) ⇒ 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.
90 91 92 93 94 95 96 97 98 |
# File 'lib/virtus/attribute/builder.rb', line 90 def self.call(type, = {}) type_definition = TypeDefinition.new(type) if type_definition.pending? PendingAttribute.new(type, ) else new(type_definition, ).attribute end end |
.determine_type(klass, default = nil) ⇒ 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.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/virtus/attribute/builder.rb', line 101 def self.determine_type(klass, default = nil) type = Attribute.determine_type(klass) if klass.is_a?(Class) type ||= if klass < Axiom::Types::Type determine_type(klass.primitive) elsif EmbeddedValue.handles?(klass) EmbeddedValue elsif klass < Enumerable Collection end end type || default end |