Module: Globalize3JQueryAutocomplete::Orm::ActiveRecord::InstanceMethods

Defined in:
lib/globalize3_jquery_autocomplete/orm/active_record.rb

Instance Method Summary collapse

Instance Method Details

#find_globalized_column_class_for(record, attribute) ⇒ Object

If the attribute of the record is globalized, returns the translation class; otherwise, returns nil.



58
59
60
61
62
63
64
# File 'lib/globalize3_jquery_autocomplete/orm/active_record.rb', line 58

def find_globalized_column_class_for(record, attribute)
  if record.respond_to?(:translation_class) && record.translated_attribute_names.include?(attribute)
    record.translation_class
  else
    nil
  end
end

#get_autocomplete_items_with_globalize3(parameters) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/globalize3_jquery_autocomplete/orm/active_record.rb', line 15

def get_autocomplete_items_with_globalize3(parameters)
  model             = parameters[:model]
  translated_model  = find_globalized_column_class_for(model, parameters[:method])
  model_with_method = translated_model || model
  term    = parameters[:term]
  method  = parameters[:method]
  options = parameters[:options]
  scopes  = Array(options[:scopes])
  where   = options[:where]
  limit   = get_autocomplete_limit(options)
  order   = get_autocomplete_order(method, options, model_with_method)

  items = model.scoped

  if scopes.present?
    scopes.each { |scope| items = items.send(scope) }
  end

  unless options[:full_model]
    items = items.select(get_autocomplete_select_clause(model, model_with_method, method, options))
  end

  if translated_model.present?
    items = items.with_translations(Globalize.locale)
  end

  items = items.where(get_autocomplete_where_clause(model_with_method, term, method, options)).
      limit(limit).order(order)

  items = items.where(where) if where.present?

  items.all.uniq
end

#get_autocomplete_select_clause_with_globalize3(model_with_pk, model_with_method, method, options) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/globalize3_jquery_autocomplete/orm/active_record.rb', line 49

def get_autocomplete_select_clause_with_globalize3(model_with_pk, model_with_method, method, options)
  pk_table_name = model_with_pk.table_name
  m_table_name  = model_with_method.table_name

  (["#{pk_table_name}.#{model_with_pk.primary_key}", "#{m_table_name}.#{method}"] +
      (options[:extra_data].presence || []))
end