| EXTRA_CONST_ARGS | = | (RUBY_VERSION < '1.9' ? [] : [ false ]).freeze | Provides args for const_get and const_defined? to make them behave consistently across different versions of ruby | |
| Undefined | = | Object.new.freeze | Represents an undefined parameter used by auto-generated option methods | |
| VERSION | = | '1.0.5'.freeze |
Sets the global coercer configuration
@example
Virtus.coercer do |config|
config.string.boolean_map = { true => '1', false => '0' }
end
@return [Coercible::Coercer]
@api public
Provides access to the global Virtus configuration
@example
Virtus.config do |config|
config.coerce = false
end
@return [Configuration]
@api public
Finalize pending attributes
@example
class User
include Virtus.model(:finalize => false)
attribute :address, 'Address'
end
class Address
include Virtus.model(:finalize => false)
attribute :user, 'User'
end
Virtus.finalize # this will resolve constant names
@return [Array] array of finalized models
@api public
Provides access to the Virtus module builder see Virtus::ModuleBuilder
@example
MyVirtusModule = Virtus.module { |mod|
mod.coerce = true
mod.string.boolean_map = { 'yup' => true, 'nope' => false }
}
class Book
include MyVirtusModule
attribute :published, Boolean
end
# This could be made more succinct as well
class OtherBook
include Virtus.module { |m| m.coerce = false }
end
@return [Module]
@api public
Builds a module for...modules
@example
module Common
include Virtus.module
attribute :name, String
attribute :age, Integer
end
class User
include Common
end
class Admin
include Common
end
@return [Module]
@api public
Builds a module for value object models
@example
class GeoLocation
include Virtus.value_object
values do
attribute :lat, Float
attribute :lng, Float
end
end
@return [Module]
@api public