module Virtus::ClassMethods

Class methods that are added when you include Virtus

Private Class Methods

extended(descendant) click to toggle source

Hook called when module is extended

@param [Class] descendant

@return [undefined]

@api private

Calls superclass method Virtus::Extensions::Methods.extended
# File lib/virtus/class_methods.rb, line 15
def self.extended(descendant)
  super
  descendant.send(:include, AttributeSet.create(descendant))
end

Public Instance Methods

attribute_set() click to toggle source

Returns all the attributes defined on a Class

@example

class User
  include Virtus

  attribute :name, String
  attribute :age,  Integer
end

User.attribute_set  # =>

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

@return [AttributeSet]

@api public

# File lib/virtus/class_methods.rb, line 38
def attribute_set
  @attribute_set
end
attributes() click to toggle source

@see #attribute_set

@deprecated

@api public

# File lib/virtus/class_methods.rb, line 47
def attributes
  warn "#{self}.attributes is deprecated. Use #{self}.attribute_set instead: #{caller.first}"
  attribute_set
end

Private Instance Methods

allowed_methods() click to toggle source

The list of allowed public methods

@return [Array<String>]

@api private

# File lib/virtus/class_methods.rb, line 78
def allowed_methods
  public_instance_methods.map(&:to_s)
end
assert_valid_name(name) click to toggle source

@api private

# File lib/virtus/class_methods.rb, line 83
def assert_valid_name(name)
  if instance_methods.include?(:attributes) && name.to_sym == :attributes
    raise ArgumentError, "#{name.inspect} is not allowed as an attribute name"
  end
end
inherited(descendant) click to toggle source

Setup descendants' own Attribute-accessor-method-hosting modules

Descendants inherit Attribute accessor methods via Ruby's inheritance mechanism: Attribute accessor methods are defined in a module included in a superclass. Attributes defined on descendants add methods to the descendant's Attributes accessor module, leaving the superclass's method table unaffected.

@param [Class] descendant

@return [undefined]

@api private

Calls superclass method
# File lib/virtus/class_methods.rb, line 67
def inherited(descendant)
  super
  AttributeSet.create(descendant)
  descendant.module_eval { include attribute_set }
end