Sha256: 14eeb5abb5c8af5af70abe5524a446cfdcd53065de57d0e8e8f7739c853e9dd0

Contents?: true

Size: 1.07 KB

Versions: 57

Compression:

Stored size: 1.07 KB

Contents

module Cmor::Tags
  class Search < Rao::Service::Base
    class Result < Rao::Service::Result::Base
      attr_accessor :tag_list, :taggable_classes, :exact, :found
    end

    attr_accessor :tag_list, :taggable_classes, :exact

    validates :tag_list, presence: true

    def tag_list
      @tag_list ||= ''
    end

    def taggable_classes
      @taggable_classes ||= Cmor::Tags::Tagging.distinct.pluck(:taggable_type)
    end

    def exact
      @exact ||= Cmor::Tags::Configuration.tag_search_exact_default_value
    end

    def exact=(value)
      if Rails.version < '5.1'
        @exact = ActiveRecord::Type::Boolean.new.type_cast_from_database(value)
      else
        @exact = ActiveRecord::Type::Boolean.new.cast(value)
      end
    end

    private

    def _perform
      @result.found = search!
    end

    def wild
      @wild ||= !exact
    end

    def any
      @any ||= !exact
    end

    def search!
      taggable_classes.each_with_object({}) { |klass, result| result[klass] = klass.constantize.tagged_with(tag_list.split(', '), any: any, wild: wild) }
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
cmor_tags-0.0.60.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.59.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.58.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.57.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.56.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.55.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.54.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.53.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.52.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.51.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.50.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.49.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.48.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.45.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.44.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.43.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.42.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.41.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.40.pre app/models/cmor/tags/search.rb
cmor_tags-0.0.39.pre app/models/cmor/tags/search.rb