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
using instance variables instead of writers for work package selects
Ivan Kuchin4f77de64f520
diff --git a/app/models/queries/work_packages/selects/custom_field_select.rb b/app/models/queries/work_packages/selects/custom_field_select.rbindex c6e2a107d5d..21a0f0c730b 100644--- a/app/models/queries/work_packages/selects/custom_field_select.rb+++ b/app/models/queries/work_packages/selects/custom_field_select.rb@@ -69,20 +69,19 @@ class Queries::WorkPackages::Selects::CustomFieldSelect < Queries::WorkPackages:privatedef set_name!- self.name = custom_field.column_name.to_sym+ @name = custom_field.column_name.to_symenddef set_sortable!- self.sortable = custom_field.order_statements || false+ @sortable = custom_field.order_statements || falseenddef set_groupable!- self.groupable = custom_field.group_by_statement if groupable_custom_field?(custom_field)- self.groupable ||= false+ @groupable = groupable_custom_field?(custom_field) ? custom_field.group_by_statement || false : falseenddef set_summable!- self.summable = if %w(float int).include?(custom_field.field_format)+ @summable = if %w(float int).include?(custom_field.field_format)select = summable_select_statement->(query, grouped) {diff --git a/app/models/queries/work_packages/selects/relation_of_type_select.rb b/app/models/queries/work_packages/selects/relation_of_type_select.rbindex eb6809cec69..f7dd9d4d668 100644--- a/app/models/queries/work_packages/selects/relation_of_type_select.rb+++ b/app/models/queries/work_packages/selects/relation_of_type_select.rb@@ -28,12 +28,9 @@class Queries::WorkPackages::Selects::RelationOfTypeSelect < Queries::WorkPackages::Selects::RelationSelectdef initialize(type)- self.type = type- super(name)- end+ super(:"relations_of_type_#{type[:sym]}")- def name- :"relations_of_type_#{type[:sym]}"+ @type = typeenddef symdiff --git a/app/models/queries/work_packages/selects/relation_select.rb b/app/models/queries/work_packages/selects/relation_select.rbindex c12f7663eb2..224b1e58f74 100644--- a/app/models/queries/work_packages/selects/relation_select.rb+++ b/app/models/queries/work_packages/selects/relation_select.rb@@ -27,7 +27,7 @@#++class Queries::WorkPackages::Selects::RelationSelect < Queries::WorkPackages::Selects::WorkPackageSelect- attr_accessor :type+ attr_reader :typedef self.granted_by_enterprise_tokenEnterpriseToken.allows_to?(:work_package_query_relation_columns)diff --git a/app/models/queries/work_packages/selects/relation_to_type_select.rb b/app/models/queries/work_packages/selects/relation_to_type_select.rbindex cd6ddcd432f..7744ed717f1 100644--- a/app/models/queries/work_packages/selects/relation_to_type_select.rb+++ b/app/models/queries/work_packages/selects/relation_to_type_select.rb@@ -28,14 +28,9 @@class Queries::WorkPackages::Selects::RelationToTypeSelect < Queries::WorkPackages::Selects::RelationSelectdef initialize(type)- super+ super(:"relations_to_type_#{type.id}")- set_name! type- self.type = type- end-- def set_name!(type)- self.name = :"relations_to_type_#{type.id}"+ @type = typeenddef captiondiff --git a/app/models/queries/work_packages/selects/work_package_select.rb b/app/models/queries/work_packages/selects/work_package_select.rbindex a3ffe42aa3b..af559df44bd 100644--- a/app/models/queries/work_packages/selects/work_package_select.rb+++ b/app/models/queries/work_packages/selects/work_package_select.rb@@ -27,19 +27,13 @@#++class Queries::WorkPackages::Selects::WorkPackageSelect- attr_accessor :highlightable,- :name,- :sortable_join,- :summable,- :default_order,- :association- alias_method :highlightable?, :highlightable-- attr_reader :groupable,- :sortable,- :displayable-- attr_writer :null_handling,+ attr_reader :highlightable,+ :name,+ :sortable_join,+ :summable,+ :default_order,+ :association,+ :null_handling,:summable_select,:summable_work_packages_select@@ -76,31 +70,25 @@ class Queries::WorkPackages::Selects::WorkPackageSelect@null_handlingend- def groupable=(value)- @groupable = name_or_value_or_false(value)+ def displayable+ @displayable.nil? ? true : @displayableend- def sortable=(value)- @sortable = name_or_value_or_false(value)+ def sortable+ name_or_value_or_false(@sortable)end- def displayable=(value)- @displayable = value.nil? ? true : value+ def groupable+ name_or_value_or_false(@groupable)end- def displayable?- displayable- end+ def displayable? = !!displayable- # Returns true if the column is sortable, otherwise false- def sortable?- !!sortable- end+ def sortable? = !!sortable- # Returns true if the column is groupable, otherwise false- def groupable?- !!groupable- end+ def groupable? = !!groupable++ def highlightable? = !!highlightabledef summable?summable || @summable_select || @summable_work_packages_select@@ -127,22 +115,24 @@ class Queries::WorkPackages::Selects::WorkPackageSelectenddef initialize(name, options = {})- self.name = name-- %i(sortable- sortable_join- displayable- groupable- summable- summable_select- summable_work_packages_select- association- null_handling- default_order).each do |attribute|- send(:"#{attribute}=", options[attribute])+ @name = name++ %i[+ sortable+ sortable_join+ displayable+ groupable+ summable+ summable_select+ summable_work_packages_select+ association+ null_handling+ default_order+ ].each do |attribute|+ instance_variable_set(:"@#{attribute}", options[attribute])end- self.highlightable = !!options.fetch(:highlightable, false)+ @highlightable = !!options.fetch(:highlightable, false)enddef captiondiff --git a/spec/models/queries/work_packages/selects/shared_query_select_specs.rb b/spec/models/queries/work_packages/selects/shared_query_select_specs.rbindex 4fd9758d4c2..8df7f50fddc 100644--- a/spec/models/queries/work_packages/selects/shared_query_select_specs.rb+++ b/spec/models/queries/work_packages/selects/shared_query_select_specs.rb@@ -29,25 +29,25 @@RSpec.shared_examples_for "query column" do |sortable_by_default: false|describe "#groupable" doit "is the name if true is provided" do- instance.groupable = true+ instance.instance_variable_set(:@groupable, true)expect(instance.groupable).to eql(instance.name.to_s)endit "is the value if something truthy is provided" do- instance.groupable = "lorem ipsum"+ instance.instance_variable_set(:@groupable, "lorem ipsum")expect(instance.groupable).to eql("lorem ipsum")endit "is false if false is provided" do- instance.groupable = false+ instance.instance_variable_set(:@groupable, false)expect(instance.groupable).to be_falseyend- it "is false if nothing is provided" do- instance.groupable = nil+ it "is false if nil is provided" do+ instance.instance_variable_set(:@groupable, nil)expect(instance.groupable).to be_falseyend@@ -55,43 +55,39 @@ RSpec.shared_examples_for "query column" do |sortable_by_default: false|describe "#sortable" doit "is the name if true is provided" do- instance.sortable = true+ instance.instance_variable_set(:@sortable, true)expect(instance.sortable).to eql(instance.name.to_s)endit "is the value if something truthy is provided" do- instance.sortable = "lorem ipsum"+ instance.instance_variable_set(:@sortable, "lorem ipsum")expect(instance.sortable).to eql("lorem ipsum")endit "is false if false is provided" do- instance.sortable = false+ instance.instance_variable_set(:@sortable, false)expect(instance.sortable).to be_falseyend- it "is false if nothing is provided" do- instance.sortable = nil+ it "is false if nil is provided" do+ instance.instance_variable_set(:@sortable, nil)expect(instance.sortable).to be_falseyendenddescribe "#groupable?" do- it "is false by default" do- expect(instance).not_to be_groupable- end-it "is true if told so" do- instance.groupable = true+ instance.instance_variable_set(:@groupable, true)expect(instance).to be_groupableendit "is true if a value is provided (e.g. for specifying sql code)" do- instance.groupable = "COALESCE(null, 1)"+ instance.instance_variable_set(:@groupable, "COALESCE(null, 1)")expect(instance).to be_groupableend@@ -107,13 +103,13 @@ RSpec.shared_examples_for "query column" do |sortable_by_default: false|endit "is true if told so" do- instance.sortable = true+ instance.instance_variable_set(:@sortable, true)expect(instance).to be_sortableendit "is true if a value is provided (e.g. for specifying sql code)" do- instance.sortable = "COALESCE(null, 1)"+ instance.instance_variable_set(:@sortable, "COALESCE(null, 1)")expect(instance).to be_sortableend