Module: VestalVersions::Configuration
- Included in:
- VestalVersions
- Defined in:
- lib/vestal_versions/configuration.rb
Overview
Allows for easy application-wide configuration of options passed into the versioned
method.
Class Method Summary collapse
-
.method_missing(symbol, *args) ⇒ Object
If given a setter method name, will assign the first argument to the
options
hash with the method name (sans “=”) as the key. -
.options ⇒ Object
Simply stores a hash of options given to the
configure
block.
Instance Method Summary collapse
-
#configure {|Configuration| ... } ⇒ Object
The VestalVersions module is extended by VestalVersions::Configuration, allowing the configure method to be used as follows in a Rails initializer:.
Class Method Details
.method_missing(symbol, *args) ⇒ Object
If given a setter method name, will assign the first argument to the options
hash with the method name (sans “=”) as the key. If given a getter method name, will attempt to a value from the options
hash for that key. If the key doesn’t exist, defers to super
.
31 32 33 34 35 36 37 |
# File 'lib/vestal_versions/configuration.rb', line 31 def method_missing(symbol, *args) if (method = symbol.to_s).sub!(/\=$/, '') [method.to_sym] = args.first else .fetch(method.to_sym, super) end end |
.options ⇒ Object
Simply stores a hash of options given to the configure
block.
24 25 26 |
# File 'lib/vestal_versions/configuration.rb', line 24 def @options ||= {} end |
Instance Method Details
#configure {|Configuration| ... } ⇒ Object
The VestalVersions module is extended by VestalVersions::Configuration, allowing the configure method to be used as follows in a Rails initializer:
VestalVersions.configure do |config|
config.class_name = "MyCustomVersion"
config.dependent = :destroy
end
Each variable assignment in the configure
block corresponds directly with the options available to the versioned
method. Assigning common options in an initializer can keep your models tidy.
If an option is given in both an initializer and in the options passed to versioned
, the value given in the model itself will take precedence.
18 19 20 |
# File 'lib/vestal_versions/configuration.rb', line 18 def configure yield Configuration end |