Class: Virtus::Configuration
- Inherits:
-
Object
- Object
- Virtus::Configuration
- Defined in:
- lib/virtus/configuration.rb
Overview
A Configuration instance
Instance Attribute Summary collapse
-
#coerce ⇒ Object
Access the coerce setting for this instance.
-
#constructor ⇒ Object
Access the constructor setting for this instance.
-
#finalize ⇒ Object
Access the finalize setting for this instance.
-
#mass_assignment ⇒ Object
Access the mass-assignment setting for this instance.
-
#strict ⇒ Object
Access the strict setting for this instance.
Class Method Summary collapse
-
.build(options = {}, &block) ⇒ Configuration
Build new configuration instance using the passed block.
Instance Method Summary collapse
-
#call(&block) ⇒ self
private
Provide access to the attributes and methods via the passed block.
-
#coercer(&block) ⇒ Coercer
private
Access the coercer for this instance and optional configure a new coercer with the passed block.
-
#initialize ⇒ undefined
constructor
private
Initialized a configuration instance.
- #to_h ⇒ Object private
Constructor Details
#initialize ⇒ 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
42 43 44 45 46 47 48 49 |
# File 'lib/virtus/configuration.rb', line 42 def initialize @finalize = true @coerce = true @strict = false @constructor = true @mass_assignment = true @coercer = Coercible::Coercer.new end |
Instance Attribute Details
#coerce ⇒ Object
Access the coerce setting for this instance
10 11 12 |
# File 'lib/virtus/configuration.rb', line 10 def coerce @coerce end |
#constructor ⇒ Object
Access the constructor setting for this instance
16 17 18 |
# File 'lib/virtus/configuration.rb', line 16 def constructor @constructor end |
#finalize ⇒ Object
Access the finalize setting for this instance
7 8 9 |
# File 'lib/virtus/configuration.rb', line 7 def finalize @finalize end |
#mass_assignment ⇒ Object
Access the mass-assignment setting for this instance
19 20 21 |
# File 'lib/virtus/configuration.rb', line 19 def mass_assignment @mass_assignment end |
#strict ⇒ Object
Access the strict setting for this instance
13 14 15 |
# File 'lib/virtus/configuration.rb', line 13 def strict @strict end |
Class Method Details
.build(options = {}, &block) ⇒ Configuration
Build new configuration instance using the passed block
31 32 33 34 35 |
# File 'lib/virtus/configuration.rb', line 31 def self.build( = {}, &block) config = new.call(&block) .each { |key, value| config.public_send("#{key}=", value) } config end |
Instance Method Details
#call(&block) ⇒ 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.
Provide access to the attributes and methods via the passed block
61 62 63 64 |
# File 'lib/virtus/configuration.rb', line 61 def call(&block) block.call(self) if block_given? self end |
#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
77 78 79 80 |
# File 'lib/virtus/configuration.rb', line 77 def coercer(&block) @coercer = Coercible::Coercer.new(&block) if block_given? @coercer end |
#to_h ⇒ 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.
83 84 85 86 87 88 |
# File 'lib/virtus/configuration.rb', line 83 def to_h { :coerce => coerce, :finalize => finalize, :strict => strict, :configured_coercer => coercer }.freeze end |