Module: GovUkDateFields::ActsAsGovUkDate::LocalInstanceMethods

Defined in:
lib/gov_uk_date_fields/acts_as_gov_uk_date.rb

Instance Method Summary collapse

Instance Method Details

#populate_gov_uk_datesObject

This is an after initialize method. We want to populate every gov_uk_date_field, unless it’s a new record, and there is already a non-nil form date (this happens when you call new and pass a hash of attributes and values)



115
116
117
118
119
120
121
122
123
# File 'lib/gov_uk_date_fields/acts_as_gov_uk_date.rb', line 115

def populate_gov_uk_dates
  self._gov_uk_dates.each do |field_name|
    instance_variable_name = "@_#{field_name}"
    next if self.new_record? &&
            self.instance_variable_defined?(instance_variable_name) &&
            self.instance_variable_get(instance_variable_name) != nil
    GovUkDateFields::FormDate.set_from_date(self, field_name, self[field_name])
  end
end