Permalink
Browse files

Revert "Criteria as separate model"

This reverts commit e3fd2f4.
  • Loading branch information...
1 parent e0ae11c commit 683df88491aeaebb1ccb4724c4045e88b93ac8ba @paul committed Oct 13, 2010
@@ -1,28 +0,0 @@
-
-class Criterion < SsbeModel
- service_type :measurements
-
- persists :target, :comparison, :pattern
-
- validates_presence_of :target, :comparison
- validates_presence_of :pattern, :message => "Pattern is required"
- validate :comparison_valid_for_target
-
- def valid_comparisons
- MetricFilter.targets.detect { |comparisons|
- comparisons["target"] == target
- }["valid_comparisons"]
- end
-
- def new_record?; false; end
- def persisted?; false; end
-
- protected
-
- def comparison_valid_for_target
- unless valid_comparisons.include?(comparison)
- errors.add(:comparison, "Comparison is applicable to this target")
- end
- end
-
-end
@@ -62,5 +62,48 @@ def valid_criteria
end
end
+ class Criterion
+ include ActiveModel::Validations
+
+ attr_accessor :id, :target, :comparison, :pattern
+
+ attr_accessor :_delete # Virtual attribute for form remove
+
+ validates_presence_of :target, :comparison
+ validates_presence_of :pattern, :message => "Pattern is required"
+ validate :comparison_valid_for_target
+
+ def initialize(attrs = {})
+ attrs.each do |k,v|
+ send(:"#{k}=", v)
+ end
+ end
+
+ def to_json
+ {
+ :target => target,
+ :comparison => comparison,
+ :pattern => pattern
+ }.to_json
+ end
+
+ def valid_comparisons
+ MetricFilter.targets.detect { |comparisons|
+ comparisons["target"] == target
+ }["valid_comparisons"]
+ end
+
+ def new_record?; false; end
+ def persisted?; false; end
+
+ protected
+
+ def comparison_valid_for_target
+ unless valid_comparisons.include?(comparison)
+ errors.add(:comparison, "Comparison is applicable to this target")
+ end
+ end
+
+ end
end
@@ -19,10 +19,6 @@ def save!
save
end
- def persisted?
- !!href
- end
-
class << self
def service_type(service_type = nil)

0 comments on commit 683df88

Please sign in to comment.