Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Unpack metaprogramming
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
commit dc90a5e84269df871b1d688e7ebeb325318170d0
20 changes: 10 additions & 10 deletions app/presenters/search_result.rb
Original file line numberDiff line numberDiff 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