Module: E9Tags::Model::DelayedClassMethods

Defined in:
lib/e9_tags/model.rb

Instance Method Summary collapse

Instance Method Details

#tagged_with(tags, options = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/e9_tags/model.rb', line 84

def tagged_with(tags, options = {})
  retv = super

  # for whatever reason, tagged_with by default returns an empty Hash (??) if there are no results
  return where("1=0") if retv.blank?

  # if :show_all is true, just return super with no modification
  #
  if !options[:show_all] && retv.joins_values.present? && retv.to_sql =~ /JOIN taggings (\S+)/
    #
    # otherwise we'll show hidden OR visible tags based on whether :show_hidden was passed
    #
    retv = retv.where(
      %Q[#{$1}.context #{options[:show_hidden] ? '' : ' NOT '} like '%__H__']
    )
  end

  retv
end