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.
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/virtus/attribute/builder.rb', line 113 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)
81 82 83 |
# File 'lib/virtus/attribute/builder.rb', line 81 def attribute @attribute end |
#klass ⇒ Object (readonly)
81 82 83 |
# File 'lib/virtus/attribute/builder.rb', line 81 def klass @klass end |
#options ⇒ Object (readonly)
81 82 83 |
# File 'lib/virtus/attribute/builder.rb', line 81 def @options end |
#type ⇒ Object (readonly)
81 82 83 |
# File 'lib/virtus/attribute/builder.rb', line 81 def type @type end |
#type_definition ⇒ Object (readonly)
81 82 83 |
# File 'lib/virtus/attribute/builder.rb', line 81 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.
84 85 86 87 88 89 90 91 92 |
# File 'lib/virtus/attribute/builder.rb', line 84 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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/virtus/attribute/builder.rb', line 95 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 && !(klass <= Range) Collection end end type || default end |