Module: Virtus
- Defined in:
- lib/virtus.rb,
lib/virtus/model.rb,
lib/virtus/builder.rb,
lib/virtus/coercer.rb,
lib/virtus/version.rb,
lib/virtus/attribute.rb,
lib/virtus/extensions.rb,
lib/virtus/value_object.rb,
lib/virtus/attribute_set.rb,
lib/virtus/class_methods.rb,
lib/virtus/configuration.rb,
lib/virtus/attribute/enum.rb,
lib/virtus/attribute/hash.rb,
lib/virtus/support/options.rb,
lib/virtus/attribute/strict.rb,
lib/virtus/class_inclusions.rb,
lib/virtus/instance_methods.rb,
lib/virtus/attribute/boolean.rb,
lib/virtus/attribute/builder.rb,
lib/virtus/attribute/coercer.rb,
lib/virtus/module_extensions.rb,
lib/virtus/support/equalizer.rb,
lib/virtus/attribute/accessor.rb,
lib/virtus/attribute/coercible.rb,
lib/virtus/support/type_lookup.rb,
lib/virtus/attribute/collection.rb,
lib/virtus/builder/hook_context.rb,
lib/virtus/attribute/lazy_default.rb,
lib/virtus/attribute/default_value.rb,
lib/virtus/attribute/nullify_blank.rb,
lib/virtus/attribute/embedded_value.rb,
lib/virtus/const_missing_extensions.rb,
lib/virtus/attribute/default_value/from_symbol.rb,
lib/virtus/attribute/default_value/from_callable.rb,
lib/virtus/attribute/default_value/from_clonable.rb
Overview
Builds a module for…modules
Defined Under Namespace
Modules: ClassInclusions, ClassMethods, ConstMissingExtensions, Extensions, InstanceMethods, Model, ModuleExtensions, Options, TypeLookup, ValueObject Classes: Attribute, AttributeSet, Builder, Coercer, CoercionError, Configuration, Equalizer, ModelBuilder, ModuleBuilder, PendingAttribute, TypeDefinition, ValueObjectBuilder
Constant Summary collapse
- EXTRA_CONST_ARGS =
(RUBY_VERSION < '1.9' ? [] : [ false ]).freeze
- Undefined =
Object.new.freeze
- VERSION =
'2.1.0'.freeze
Class Method Summary collapse
- .coerce ⇒ Object
- .coerce=(value) ⇒ Object
- .coercer(&block) ⇒ Object
- .config {|configuration| ... } ⇒ Object
-
.configuration ⇒ Object
private
Global configuration instance.
- .constantize(type) ⇒ Object private
-
.finalize ⇒ Array
Finalize pending attributes.
- .inflector ⇒ Object private
- .model(options = {}, &block) ⇒ Object
- .module(options = {}, &block) ⇒ Object
-
.value_object(options = {}, &block) ⇒ Module
Builds a module for value object models.
- .warn(msg) ⇒ Object private
Class Method Details
.coerce ⇒ Object
113 114 115 |
# File 'lib/virtus.rb', line 113 def self.coerce configuration.coerce end |
.coerce=(value) ⇒ Object
103 104 105 106 |
# File 'lib/virtus.rb', line 103 def self.coerce=(value) configuration.coerce = value self end |
.coercer(&block) ⇒ Object
92 93 94 |
# File 'lib/virtus.rb', line 92 def self.coercer(&block) configuration.coercer(&block) end |
.config {|configuration| ... } ⇒ Object
127 128 129 130 |
# File 'lib/virtus.rb', line 127 def self.config(&block) yield configuration if block_given? configuration end |
.configuration ⇒ 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.
Global configuration instance
@ return [Configuration]
210 211 212 |
# File 'lib/virtus.rb', line 210 def self.configuration @configuration ||= Configuration.new end |
.constantize(type) ⇒ 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.
215 216 217 |
# File 'lib/virtus.rb', line 215 def self.constantize(type) inflector.constantize(type) end |
.finalize ⇒ Array
Finalize pending attributes
253 254 255 256 257 |
# File 'lib/virtus.rb', line 253 def self.finalize Builder.pending.each do |klass| klass.attribute_set.finalize end end |
.inflector ⇒ 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.
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/virtus.rb', line 220 def self.inflector @inflector ||= begin require 'dry/inflector' Dry::Inflector.new rescue LoadError raise( NotImplementedError, 'Virtus needs dry-inflector gem to constantize namespaced constant names' ) end end |
.model(options = {}, &block) ⇒ Object
155 156 157 |
# File 'lib/virtus.rb', line 155 def self.model( = {}, &block) ModelBuilder.call(, &block) end |
.module(options = {}, &block) ⇒ Object
181 182 183 |
# File 'lib/virtus.rb', line 181 def self.module( = {}, &block) ModuleBuilder.call(, &block) end |
.value_object(options = {}, &block) ⇒ Module
Builds a module for value object models
201 202 203 |
# File 'lib/virtus.rb', line 201 def self.value_object( = {}, &block) ValueObjectBuilder.call(, &block) end |
.warn(msg) ⇒ 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.
260 261 262 |
# File 'lib/virtus.rb', line 260 def self.warn(msg) Kernel.warn(msg) end |