Module: Virtus::ClassMethods

Includes:
Extensions
Defined in:
lib/virtus/class_methods.rb

Overview

Class methods that are added when you include Virtus

Constant Summary

Constants included from Extensions

Extensions::INVALID_WRITER_METHODS, Extensions::WRITER_METHOD_REGEXP

Instance Method Summary collapse

Methods included from Extensions

#allowed_writer_methods, #attribute

Instance Method Details

#attribute_setAttributeSet

Returns all the attributes defined on a Class

Examples:

class User
  include Virtus

  attribute :name, String
  attribute :age,  Integer
end

User.attribute_set  # =>

TODO: implement inspect so the output is not cluttered - solnic

Returns:



41
42
43
44
45
46
47
# File 'lib/virtus/class_methods.rb', line 41

def attribute_set
  return @attribute_set if defined?(@attribute_set)
  superclass  = self.superclass
  method      = __method__
  parent      = superclass.public_send(method) if superclass.respond_to?(method)
  @attribute_set = AttributeSet.new(parent)
end

#attributesObject

Deprecated.

See Also:

  • attribute_set


54
55
56
57
# File 'lib/virtus/class_methods.rb', line 54

def attributes
  warn "#{self}.attributes is deprecated. Use #{self}.attribute_set instead: #{caller.first}"
  attribute_set
end

#const_missing(name) ⇒ Class

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.

Hooks into const missing process to determine types of attributes

Parameters:

  • name (String)

Returns:

  • (Class)


66
67
68
# File 'lib/virtus/class_methods.rb', line 66

def const_missing(name)
  Attribute.determine_type(name) or super
end