Module: MetaSearch::ClassMethods

Includes:
Utility
Defined in:
lib/meta_search/model_compatibility.rb

Constant Summary

Constants included from Utility

Utility::FALSE_VALUES, Utility::TRUE_VALUES

Instance Method Summary collapse

Instance Method Details

#human_attribute_name(attribute, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/meta_search/model_compatibility.rb', line 53

def human_attribute_name(attribute, options = {})
  method_name = preferred_method_name(attribute)

  defaults = [:"meta_search.attributes.#{klass.model_name.i18n_key}.#{method_name || attribute}"]

  if method_name
    predicate = Where.get(method_name)[:name]
    predicate_attribute = method_name.sub(/_#{predicate}=?$/, '')
    predicate_attributes = predicate_attribute.split(/_or_/).map { |att|
      klass.human_attribute_name(att)
    }.join(" #{I18n.translate(:"meta_search.or", :default => 'or')} ")
    defaults << :"meta_search.predicates.#{predicate}"
  end

  defaults << options.delete(:default) if options[:default]
  defaults << attribute.to_s.humanize

  options.reverse_merge! :count => 1, :default => defaults, :attribute => predicate_attributes || klass.human_attribute_name(attribute)
  I18n.translate(defaults.shift, options)
end

#model_nameObject



49
50
51
# File 'lib/meta_search/model_compatibility.rb', line 49

def model_name
  @_model_name ||= Name.new
end