aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/custom_field.rb
diff options
context:
space:
mode:
authorZog2018-01-23 15:23:19 +0100
committerZog2018-02-26 10:00:34 +0100
commit3b84483f292c5b880bb2f72bd185f505dabbc478 (patch)
tree1cc18712055cb7899949d4823ec0ee108e2a85d1 /app/models/custom_field.rb
parent3e2ec765db2835be3772a57b4fc045c7c2e0e4ed (diff)
downloadchouette-core-3b84483f292c5b880bb2f72bd185f505dabbc478.tar.bz2
CR #1
Diffstat (limited to 'app/models/custom_field.rb')
-rw-r--r--app/models/custom_field.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 5a7c1954c..279f7cb39 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -20,16 +20,20 @@ class CustomField < ActiveRecord::Base
@custom_field = custom_field
@raw_value = value
@owner = owner
+ @errors = []
+ @validated = false
+ @valid = false
end
- %i(code name field_type options).each do |attr|
- define_method attr do
- @custom_field.send(attr)
- end
+ delegate :code, :name, :field_type, :options, to: :@custom_field
+
+ def validate
+ @valid = true
end
def valid?
- true
+ validate unless @validated
+ @valid
end
def value
@@ -46,9 +50,11 @@ class CustomField < ActiveRecord::Base
@raw_value.to_i
end
- def valid?
- unless ActiveRecord::Base::NumericalityValidator.new(attributes: 42).send(:parse_raw_value_as_an_integer, @raw_value).present?
+ def validate
+ @valid = true
+ unless @raw_value =~ /\A\d*\Z/
@owner.errors.add errors_key, "'#{@raw_value}' is not a valid integer"
+ @valid = false
end
end
end