Module: Virtus::ClassMethods
- Defined in:
- lib/virtus/class_methods.rb
Overview
Class methods that are added when you include Virtus
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ self
Defines an attribute on an object’s class.
-
#attributes ⇒ AttributeSet
Returns all the attributes defined on a Class.
Instance Method Details
#attribute(name, type, options = {}) ⇒ self
Defines an attribute on an object’s class
45 46 47 48 49 50 |
# File 'lib/virtus/class_methods.rb', line 45 def attribute(name, type, = {}) attribute = Attribute.determine_type(type).new(name, ) virtus_define_attribute_methods(attribute) virtus_add_attribute(attribute) self end |
#attributes ⇒ AttributeSet
Returns all the attributes defined on a Class
69 70 71 72 73 74 75 |
# File 'lib/virtus/class_methods.rb', line 69 def attributes @attributes ||= begin superclass = self.superclass parent = superclass.attributes if superclass.respond_to?(:attributes) AttributeSet.new(parent) end end |