Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
jviney committed Oct 3, 2007
1 parent 8a59051 commit d6a43be
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
9 changes: 1 addition & 8 deletions CHANGELOG
Expand Up @@ -8,7 +8,7 @@

* Remove TagList.parse, use TagList.from instead.

* Add :parse option to TagList#new and TagList#add.
* Add :parse option to TagList#new, TagList#add, and TagList#remove.

tag_list = TagList.new("One, Two", :parse => true) # ["One", "Two"]

Expand All @@ -35,13 +35,6 @@

* Make the TagList class inherit from Array.

BACKWARDS INCOMPATIBILITY:

TagList#initialize, TagList#add, and TagList#remove no longer accept array arguments.

Old: TagList.new(["One", "Two"])
New: TagList.new("One", "Two")

* Deprecate obsolete TagList#names.

[6 September 2007]
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_taggable.rb
Expand Up @@ -41,7 +41,7 @@ def find_tagged_with(*args)
end

def find_options_for_find_tagged_with(tags, options = {})
tags = tags.is_a?(Array) ? TagList.new(*tags.map(&:to_s)) : TagList.from(tags)
tags = tags.is_a?(Array) ? TagList.new(tags.map(&:to_s)) : TagList.from(tags)

return {} if tags.empty?

Expand Down
6 changes: 4 additions & 2 deletions lib/tag_list.rb
Expand Up @@ -59,8 +59,10 @@ def extract_and_apply_options!(args)
options.assert_valid_keys :parse

if options[:parse]
args.map! { |a| self.class.from(a) }.flatten!
args.map! { |a| self.class.from(a) }
end

args.flatten!
end

class << self
Expand All @@ -76,7 +78,7 @@ def from(string)
string.gsub!(/"(.*?)"\s*#{delimiter}?\s*/) { tag_list << $1; "" }
string.gsub!(/'(.*?)'\s*#{delimiter}?\s*/) { tag_list << $1; "" }

tag_list.add(*string.split(delimiter))
tag_list.add(string.split(delimiter))
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/tag_list_test.rb
Expand Up @@ -77,11 +77,13 @@ def test_add
assert_equal %w(One), tag_list

assert_equal %w(One Two), tag_list.add("Two")
assert_equal %w(One Two Three), tag_list.add(["Three"])
end

def test_remove
tag_list = TagList.new("One", "Two")
assert_equal %w(Two), tag_list.remove("One")
assert_equal %w(), tag_list.remove(["Two"])
end

def test_new_with_parsing
Expand Down

0 comments on commit d6a43be

Please sign in to comment.