lib/traco/attributes.rb in traco-5.2.0 vs lib/traco/attributes.rb in traco-5.3.0

- old
+ new

@@ -19,14 +19,15 @@ end private def define_reader(attribute) + default_fallback = @options.fetch(:fallback, LocaleFallbacks::DEFAULT_FALLBACK) + class_eval <<-EOM, __FILE__, __LINE__ + 1 - def #{attribute}(options = {}) - default_fallback = #{@options.fetch(:fallback, LocaleFallbacks::DEFAULT_FALLBACK).inspect} - fallback = options.fetch(:fallback, default_fallback) + def #{attribute}(locale: nil, fallback: #{default_fallback.inspect}) + return send(Traco.column(:#{attribute}, locale)) if locale columns_to_try = self.class._locale_columns_for_attribute(:#{attribute}, fallback: fallback) columns_to_try.each do |column| value = send(column) return value if value.present? @@ -46,11 +47,11 @@ EOM end def define_query(attribute) class_eval <<-EOM, __FILE__, __LINE__ + 1 - def #{attribute}? - #{attribute}.present? + def #{attribute}?(locale: nil) + send(:#{attribute}, locale: locale).present? end EOM end # Only called once per class or inheritance chain (e.g. once