Class: RuleVersion
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- RuleVersion
- Defined in:
- lib/generators/decision_agent/install/templates/rule_version.rb
Instance Method Summary collapse
-
#activate! ⇒ Object
Activate this version (deactivates others).
-
#compare_with(other_version) ⇒ Object
Compare with another version.
-
#content_hash=(hash) ⇒ Object
Set content from a hash.
-
#parsed_content ⇒ Object
Parse the JSON content.
Instance Method Details
#activate! ⇒ Object
Activate this version (deactivates others)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/decision_agent/install/templates/rule_version.rb', line 31 def activate! transaction do # Deactivate all other versions for this rule # Use update! instead of update_all to trigger validations self.class.where(rule_id: rule_id, status: "active") .where.not(id: id) .find_each do |v| v.update!(status: "archived") end # Activate this version update!(status: "active") end end |
#compare_with(other_version) ⇒ Object
Compare with another version
47 48 49 50 51 52 |
# File 'lib/generators/decision_agent/install/templates/rule_version.rb', line 47 def compare_with(other_version) DecisionAgent::Versioning::VersionManager.new.compare( version_id_1: id, version_id_2: other_version.id ) end |
#content_hash=(hash) ⇒ Object
Set content from a hash
26 27 28 |
# File 'lib/generators/decision_agent/install/templates/rule_version.rb', line 26 def content_hash=(hash) self.content = hash.to_json end |
#parsed_content ⇒ Object
Parse the JSON content
19 20 21 22 23 |
# File 'lib/generators/decision_agent/install/templates/rule_version.rb', line 19 def parsed_content JSON.parse(content, symbolize_names: true) rescue JSON::ParserError {} end |