Module: TaggingAlong::ClassMethods

Defined in:
lib/tagging_along.rb

Instance Method Summary collapse

Instance Method Details

#is_taggable_on(*attributes) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tagging_along.rb', line 6

def is_taggable_on(*attributes)
  options = attributes.extract_options!
  separator = options[:separator] || ','

  attributes.each do |attribute|
    # Define method that turns the attribute into an array of its comma-
    # separated values
    define_method :"#{attribute}_tags" do
      send(attribute).nil? ? [] : send(attribute).split(separator)
    end

    # Define method that turns the attribute into a human readable comma-
    # space-separated list in one string
    define_method :"#{attribute}_list" do
      send(attribute).nil? ? '' : send(attribute).split(separator).join("#{separator} ")
    end
  end
end

#taggable_on?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/tagging_along.rb', line 25

def taggable_on?(attribute)
  begin
    new.send(:"#{attribute}_tags")
    new.send(:"#{attribute}_list")
    true
  rescue Exception => e
    false
  end
end