lib/amee-data-abstraction/input.rb in amee-data-abstraction-2.1.0 vs lib/amee-data-abstraction/input.rb in amee-data-abstraction-2.1.1
- old
+ new
@@ -9,10 +9,12 @@
# Subclass of <tt>Term</tt> providing methods and attributes appropriate for
# representing calculation inputs specifically
#
class Input < Term
+ attr_accessor :dirty
+
# Returns the valid choices for this input
# (Abstract, implemented only for subclasses of input.)
def choices
raise NotImplementedError
end
@@ -27,10 +29,11 @@
#
def initialize(options={},&block)
@validation = nil
validation_message {"#{name} is invalid."}
super
+ @dirty = false
end
# Configures the value of <tt>self</tt> to be fixed to <tt>val</tt>, i.e.
# the value is read-only.
#
@@ -64,11 +67,11 @@
#
def value(*args)
unless args.empty?
if args.first.to_s != @value.to_s
raise Exceptions::FixedValueInterference if fixed?
- parent.dirty! if parent and parent.is_a? OngoingCalculation
+ mark_as_dirty
end
end
super
end
@@ -182,16 +185,25 @@
# Otherwise, returns <tt>false</tt>.
#
def disabled?
super || fixed?
end
+
+ def dirty?
+ @dirty
+ end
protected
# Returns <tt>true</tt> if the value set for <tt>self</tt> is either blank
# or passes custom validation criteria. Otherwise, returns <tt>false</tt>.
#
def valid?
validation.blank? || validation === @value_before_cast
+ end
+
+ def mark_as_dirty
+ @dirty = true
+ parent.dirty! if parent and parent.is_a? OngoingCalculation
end
end
end
end
\ No newline at end of file