lib/grape_entity/exposure/base.rb in grape-entity-0.9.0 vs lib/grape_entity/exposure/base.rb in grape-entity-0.10.0
- old
+ new
@@ -14,10 +14,11 @@
@attribute = attribute.try(:to_sym)
@options = options
key = options[:as] || attribute
@key = key.respond_to?(:to_sym) ? key.to_sym : key
@is_safe = options[:safe]
+ @default_value = options[:default]
@for_merge = options[:merge]
@attr_path_proc = options[:attr_path]
@documentation = options[:documentation]
@override = options[:override]
@conditions = conditions
@@ -80,10 +81,13 @@
partial_output
end
end
def valid_value(entity, options)
- value(entity, options) if valid?(entity)
+ return unless valid?(entity)
+
+ output = value(entity, options)
+ output.blank? && @default_value.present? ? @default_value : output
end
def should_return_key?(options)
options.should_return_key?(@key)
end