Class: Virtus::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/virtus/configuration.rb

Overview

A Configuration instance

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ undefined

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.

Initialized a configuration instance

Yields:

  • (_self)

Yield Parameters:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/virtus/configuration.rb', line 32

def initialize(options={})
  @finalize        = options.fetch(:finalize, true)
  @coerce          = options.fetch(:coerce, true)
  @strict          = options.fetch(:strict, false)
  @nullify_blank   = options.fetch(:nullify_blank, 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

Instance Attribute Details

#coerceObject

Access the coerce setting for this instance



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

def coerce
  @coerce
end

#constructorObject

Access the constructor setting for this instance



22
23
24
# File 'lib/virtus/configuration.rb', line 22

def constructor
  @constructor
end

#finalizeObject

Access the finalize setting for this instance



7
8
9
# File 'lib/virtus/configuration.rb', line 7

def finalize
  @finalize
end

#mass_assignmentObject

Access the mass-assignment setting for this instance



25
26
27
# File 'lib/virtus/configuration.rb', line 25

def mass_assignment
  @mass_assignment
end

#nullify_blankObject

Access the nullify_blank setting for this instance



16
17
18
# File 'lib/virtus/configuration.rb', line 16

def nullify_blank
  @nullify_blank
end

#requiredObject

Access the required setting for this instance



19
20
21
# File 'lib/virtus/configuration.rb', line 19

def required
  @required
end

#strictObject

Access the strict setting for this instance



13
14
15
# File 'lib/virtus/configuration.rb', line 13

def strict
  @strict
end

Instance Method Details

#coercer(&block) ⇒ Coercer

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.

Access the coercer for this instance and optional configure a new coercer with the passed block

Examples:

configuration.coercer do |config|
  config.string.boolean_map = { true => '1', false => '0' }
end

Returns:



56
57
58
59
# File 'lib/virtus/configuration.rb', line 56

def coercer(&block)
  @coercer = Coercible::Coercer.new(&block) if block_given?
  @coercer
end

#to_hObject

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.



62
63
64
65
66
67
68
69
# File 'lib/virtus/configuration.rb', line 62

def to_h
  { :coerce             => coerce,
    :finalize           => finalize,
    :strict             => strict,
    :nullify_blank      => nullify_blank,
    :required           => required,
    :configured_coercer => coercer }.freeze
end