diff options
| author | Teddy Wing | 2017-07-07 16:36:51 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-07-12 11:06:03 +0200 |
| commit | d4be863478181b126faaafe25cfb293dca058570 (patch) | |
| tree | 66d4a5aaf02c4c63a118cc6af700d6ab784bad1b /app/helpers/table_builder_helper.rb | |
| parent | cdf5854f9a7b52f7b9f2607796d0dff90d04f6e4 (diff) | |
| download | chouette-core-d4be863478181b126faaafe25cfb293dca058570.tar.bz2 | |
TableBuilderHelper: Move `referential` variable to method
At Robert's recommendation, use `try` instead of `respond_to?` because
it's shorter.
Also at Robert's recommendation, move the `referential` variable to a
method to memoize it. This allows us to use it in other places without
re-getting it and without having to do the `if` check again.
He had suggested:
def referential
return @__referential__ if instance_variable_defined?(:@__referential__)
@__referential__ = try(:current_referential)
end
but I think the `||=` version works the same way and is shorter. Still
need to find out from him what our style guide rules for __variables__
are and why I should be using one here.
Refs #3479
Diffstat (limited to 'app/helpers/table_builder_helper.rb')
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index e1b8b406d..d82f1eb03 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -104,10 +104,6 @@ module TableBuilderHelper end def tbody(collection, columns, selectable, links) - # Certain controllers don't define a `#current_referential`. In these - # cases, avoid a `NoMethodError`. - referential = current_referential if respond_to?(:current_referential) - content_tag :tbody do collection.map do |item| @@ -238,4 +234,10 @@ module TableBuilderHelper class: ('delete-action' if link.method == :delete) ) end + + def referential + # Certain controllers don't define a `#current_referential`. In these + # cases, avoid a `NoMethodError`. + @__referential__ ||= try(:current_referential) + end end |
