Sha256: 2e4db16c3671cd9d7202894730564e473a1d9bb7a53ac7148e519765ab34354f

Contents?: true

Size: 1.01 KB

Versions: 13

Compression:

Stored size: 1.01 KB

Contents

module ActsAsTaggableOn::Compatibility
  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

  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

  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
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
acts-as-taggable-on-3.5.0 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.4.4 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.4.3 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.4.2 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.4.1 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.4.0 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.3.0 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.2.6 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.2.5 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.2.4 lib/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.2.3 lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.2.2 lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb
acts-as-taggable-on-3.2.1 lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb