Method: ContentfulModel::Base.return_nil_for_empty
- Defined in:
- lib/contentful_model/base.rb
.return_nil_for_empty(*nillable_fields) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/contentful_model/base.rb', line 169 def return_nil_for_empty(*nillable_fields) @return_nil_for_empty_attribute_fields ||= [] nillable_fields.each do |field| define_method field do begin result = super() result.present? ? result : nil rescue NoMethodError nil end end @return_nil_for_empty_attribute_fields.push(field) end end |