Sha256: 42c8f17db8a82fd78301a5f5c630fc27b7cc9000a51103885fd7ebccc9d5375c
Contents?: true
Size: 1.8 KB
Versions: 1
Compression:
Stored size: 1.8 KB
Contents
module Virtus # A Configuration instance class Configuration # Access the finalize setting for this instance attr_accessor :finalize # Access the coerce setting for this instance attr_accessor :coerce # Access the strict setting for this instance attr_accessor :strict # Access the required setting for this instance attr_accessor :required # Access the constructor setting for this instance attr_accessor :constructor # Access the mass-assignment setting for this instance attr_accessor :mass_assignment # Initialized a configuration instance # # @return [undefined] # # @api private def initialize(options={}) @finalize = options.fetch(:finalize, true) @coerce = options.fetch(:coerce, true) @strict = options.fetch(:strict, false) @required = options.fetch(:required, true) @constructor = options.fetch(:constructor, true) @mass_assignment = options.fetch(:mass_assignment, true) @coercer = Coercible::Coercer.new yield self if block_given? end # Access the coercer for this instance and optional configure a # new coercer with the passed block # # @example # configuration.coercer do |config| # config.string.boolean_map = { true => '1', false => '0' } # end # # @return [Coercer] # # @api private def coercer(&block) @coercer = Coercible::Coercer.new(&block) if block_given? @coercer end # @api private def to_h { :coerce => coerce, :finalize => finalize, :strict => strict, :required => required, :configured_coercer => coercer }.freeze end end # class Configuration end # module Virtus
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
virtus-1.0.4 | lib/virtus/configuration.rb |