Skip to content

Commit

Permalink
Unpack metaprogramming
Browse files Browse the repository at this point in the history
Given this is only being used for 3 things and I just spent quite a while
getting lost in the meta-programming while debugging something, I've unpacked
this to non-metaprogrammed methods to save the next person who comes to this
some time.
  • Loading branch information
Alice Bartlett committed Apr 9, 2015
1 parent 6c3d93f commit dc90a5e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app/presenters/search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ def self.result_accessor(*keys)
end
end

result_accessor :link, :title, :format, :es_score
result_accessor :link, :title, :format, :es_score, :section, :subsection, :subsubsection

# Avoid the mundanity of creating these all by hand by making
# dynamic method and accessors.
%w(section subsection subsubsection).each do |key|
define_method "formatted_#{key}_name" do
mapped_name(send(key)) || humanized_name(send(key))
end
def formatted_section_name
mapped_name(section) || humanized_name(section)
end

define_method key do
result[key]
end
def formatted_subsection_name
mapped_name(subsection) || humanized_name(subsection)
end

def formatted_subsubsection_name
mapped_name(subsubsection) || humanized_name(subsubsection)
end

# External links have a truncated version of their URLs displayed on the
Expand Down

0 comments on commit dc90a5e

Please sign in to comment.