Module: OneTimeAssignment::ClassMethods

Defined in:
lib/one_time_assignment.rb

Instance Method Summary collapse

Instance Method Details

#allow_one_time_assignment(*attribute_names) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/one_time_assignment.rb', line 7

def allow_one_time_assignment(*attribute_names)
  attribute_names.map(&:to_sym).each do |attribute_name|
    define_method("#{attribute_name}=") do |value|
      if self.send(attribute_name).blank?
        write_attribute(attribute_name, value)
      else
        raise "#{attribute_name.to_s.humanize} is already set!"
      end
    end
  end
end