Module: ActsAsTaggableOn::Compatibility

Defined in:
lib/acts_as_taggable_on/compatibility.rb

Instance Method Summary collapse

Instance Method Details

#build_taggable_scope_and_options(opts) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/acts_as_taggable_on/compatibility.rb', line 11

def build_taggable_scope_and_options(opts)
  scope_opts, opts = parse_taggable_options(opts)

  unless scope_opts.empty?
    scope = -> {
      scope_opts.inject(self) { |result, hash| result.send(*hash) }
    }
    return [scope, opts]
  end

  [nil, opts]
end

#has_many_with_taggable_compatibility(name, options = {}, &extention) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/acts_as_taggable_on/compatibility.rb', line 2

def has_many_with_taggable_compatibility(name, options = {}, &extention)
  if ActsAsTaggableOn::Utils.active_record4?
    scope, opts = build_taggable_scope_and_options(options)
    has_many(name, scope, opts, &extention)
  else
    has_many(name, options, &extention)
  end
end

#parse_taggable_options(opts) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/acts_as_taggable_on/compatibility.rb', line 24

def parse_taggable_options(opts)
  scope_opts = {}
  [:order, :having, :select, :group, :limit, :offset, :readonly].each do |o|
    scope_opts[o] = opts.delete o if opts[o]
  end
  scope_opts[:where] = opts.delete :conditions if opts[:conditions]
  scope_opts[:joins] = opts.delete :include if opts [:include]
  scope_opts[:distinct] = opts.delete :uniq if opts[:uniq]

  [scope_opts, opts]
end