Module: Virtus::ModuleExtensions

Includes:
ConstMissingExtensions
Defined in:
lib/virtus/module_extensions.rb

Overview

Virtus module that can define attributes for later inclusion

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConstMissingExtensions

#const_missing

Class Method Details

.extended(mod) ⇒ 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.



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

def self.extended(mod)
  super
  setup(mod)
end

.setup(mod, inclusions = [Model], attribute_definitions = []) ⇒ 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.



16
17
18
19
20
21
# File 'lib/virtus/module_extensions.rb', line 16

def self.setup(mod, inclusions = [Model], attribute_definitions = [])
  mod.instance_variable_set('@inclusions', inclusions)
  existing_attributes = mod.instance_variable_get('@attribute_definitions')
  new_attributes = (existing_attributes || []) + attribute_definitions
  mod.instance_variable_set('@attribute_definitions', new_attributes)
end

Instance Method Details

#attribute(name, type = nil, options = {}) ⇒ self

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.

Define an attribute in the module

Returns:

  • (self)

See Also:

  • Extensions#attribute


30
31
32
33
# File 'lib/virtus/module_extensions.rb', line 30

def attribute(name, type = nil, options = {})
  @attribute_definitions << [name, type, options]
  self
end