Revision 09ce8a63
Added by Ori Rabin almost 9 years ago
app/models/lookup_key.rb | ||
---|---|---|
|
||
KEY_DELM = ","
|
||
EQ_DELM = "="
|
||
VALUE_REGEX =/\A[^#{KEY_DELM}]+#{EQ_DELM}[^#{KEY_DELM}]+(#{KEY_DELM}[^#{KEY_DELM}]+#{EQ_DELM}[^#{KEY_DELM}]+)*\Z/
|
||
|
||
audited :associated_with => :audit_class, :allow_mass_assignment => true, :except => :lookup_values_count
|
||
validates_lengths_from_database
|
||
... | ... | |
|
||
has_many :lookup_values, :dependent => :destroy, :inverse_of => :lookup_key
|
||
accepts_nested_attributes_for :lookup_values,
|
||
:reject_if => lambda { |a| a[:value].blank? && (a[:use_puppet_default].nil? || a[:use_puppet_default] == "0")},
|
||
:reject_if => :reject_invalid_lookup_values,
|
||
:allow_destroy => true
|
||
|
||
before_validation :validate_and_cast_default_value, :unless => Proc.new{|p| p.use_puppet_default }
|
||
... | ... | |
write_attribute(:path, using_default ? nil : v)
|
||
end
|
||
|
||
def reject_invalid_lookup_values(attributes)
|
||
attributes[:match].empty? ||
|
||
(attributes[:value].blank? &&
|
||
(attributes[:use_puppet_default].nil? || attributes[:use_puppet_default] == "0"))
|
||
end
|
||
|
||
def default_value_before_type_cast
|
||
value_before_type_cast default_value
|
||
end
|
Also available in: Unified diff
Fixes #4419 - rearranging smart class parameters edit form