OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
extract factory for calculator to set options in one place
Ivan Kuchinf7be16057ac6
diff --git a/app/models/custom_field/calculated_value.rb b/app/models/custom_field/calculated_value.rbindex e6179003892..353e90ee3ef 100644--- a/app/models/custom_field/calculated_value.rb+++ b/app/models/custom_field/calculated_value.rb@@ -39,6 +39,10 @@ module CustomField::CalculatedValue# Field formats that can be used within a formula.FIELD_FORMATS_FOR_FORMULA = %w[int float calculated_value].freeze+ def self.calculator_instance+ Dentaku::Calculator.new(case_sensitive: true)+ end+included dovalidate :validate_formula, if: :field_format_calculated_value?@@ -122,13 +126,9 @@ module CustomField::CalculatedValueprivate- def calculator- Dentaku::Calculator.new(case_sensitive: true)- end-def valid_formula_syntax?# Attempt to parse the formula. If no error is returned, the formula is syntactically valid.- calculator.ast(formula_str_without_patterns)+ CustomField::CalculatedValue.calculator_instance.ast(formula_str_without_patterns)truerescue Dentaku::ParseError, Dentaku::TokenizerErrorfalse