Sha256: 42060c6c467eb9c969c1c1e0fee7aa8c97b7bbdd6082253d6e5c24aa5d2838f8

Contents?: true

Size: 470 Bytes

Versions: 2

Compression:

Stored size: 470 Bytes

Contents

module Plotline
  module Concerns
    module Taggable
      extend ActiveSupport::Concern

      included do
        attr_accessor :raw_tags
        before_save :split_raw_tags
      end

      module ClassMethods
        def tagged_with(tag)
          where('tags @> ?', "{#{tag}}")
        end
      end

      private

      def split_raw_tags
        return if raw_tags.blank?

        self.tags = raw_tags.split(',').map { |t| t.strip }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plotline-0.1.1 app/models/plotline/concerns/taggable.rb
plotline-0.1.0 app/models/plotline/concerns/taggable.rb