casting_attributes 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/casting_attributes.rb +2 -3
- metadata +1 -1
data/lib/casting_attributes.rb
CHANGED
@@ -5,13 +5,12 @@ module CastingAttributes
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def casting_attr_reader(attr, type_name, options = {})
|
8
|
-
default_value = options[:default]
|
9
|
-
|
10
8
|
caster = _caster_by_type_name(type_name).new(self, attr)
|
11
9
|
caster.readers.each do |reader|
|
12
10
|
define_method reader do
|
13
11
|
value = instance_variable_get(caster.storage_var)
|
14
|
-
if
|
12
|
+
if value.nil? and options.key?(:default)
|
13
|
+
default_value = options[:default]
|
15
14
|
instance_variable_set(caster.storage_var, default_value)
|
16
15
|
value = default_value
|
17
16
|
end
|