Class: Virtus::PendingAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/virtus/attribute/builder.rb

Overview

Attribute placeholder used when type constant is passed as a string or symbol

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, options) ⇒ PendingAttribute

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 PendingAttribute.



10
11
12
13
# File 'lib/virtus/attribute/builder.rb', line 10

def initialize(type, options)
  @type, @options = type.to_s, options
  @name = options[:name]
end

Instance Attribute Details

#nameObject (readonly)



7
8
9
# File 'lib/virtus/attribute/builder.rb', line 7

def name
  @name
end

#optionsObject (readonly)



7
8
9
# File 'lib/virtus/attribute/builder.rb', line 7

def options
  @options
end

#typeObject (readonly)



7
8
9
# File 'lib/virtus/attribute/builder.rb', line 7

def type
  @type
end

Instance Method Details

#determine_typeObject

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.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/virtus/attribute/builder.rb', line 26

def determine_type
  if type.include?('::')
    # TODO: wrap it up in Virtus.constantize and use feature-detection to
    #       pick up either Inflecto or ActiveSupport, whateve is available
    if defined?(Inflecto)
      Inflecto.constantize(type)
    else
      raise NotImplementedError, 'Virtus needs inflecto gem to constantize namespaced constant names'
    end
  else
    Object.const_get(type)
  end
end

#finalizeObject

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.



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

def finalize
  Attribute::Builder.call(determine_type, options).finalize
end

#finalized?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.

Returns:

  • (Boolean)


21
22
23
# File 'lib/virtus/attribute/builder.rb', line 21

def finalized?
  false
end