dm-tags 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -6,4 +6,9 @@
6
6
  == 0.0.2 2008-07-30
7
7
 
8
8
  * 1 major enhancement:
9
- * Added contextual finding to Model.tagged_with
9
+ * Added contextual finding to Model.tagged_with
10
+
11
+ == 0.0.3 2008-09-14
12
+
13
+ * 1 major enhancement:
14
+ * Fixed requirement of dm-core dependency on load
data/README.txt CHANGED
@@ -3,6 +3,8 @@
3
3
  http://dm-tags.rubyforge.org/
4
4
  http://github.com/bobby/dm-tags/
5
5
 
6
+ dm-tags is now part of dm-more [http://github.com/sam/dm-more].
7
+
6
8
  == Description
7
9
 
8
10
  This package brings tagging to DataMapper. It is inspired by Acts As Taggable On by Michael Bleigh, github's mbleigh. Props to him for the contextual tagging based on Acts As Taggable on Steroids.
@@ -20,62 +22,65 @@ This package brings tagging to DataMapper. It is inspired by Acts As Taggable O
20
22
 
21
23
  == Synopsis
22
24
 
23
- require 'rubygems'
24
- require 'dm-core'
25
- require 'dm-tags'
26
-
27
- DataMapper.setup(:default, "sqlite3::memory:")
28
-
29
- class MyModel
30
- include DataMapper::Resource
31
- property :id, Integer, :serial => true
32
- has_tags_on :tags, :skills
33
- end
34
-
35
- DataMapper.auto_migrate!
36
-
37
- # Contextual tagging
38
- MyModel.taggable? #=> true
39
- MyModel.new.taggable? #=> true
40
-
41
- model = MyModel.new
42
- model.tag_list = 'test, me out, please '
43
- model.tag_list #=> ['me out', 'please', 'test'] # Sanitized and alphabetized
44
- model.save #=> true
45
- model.tags #=> [#<Tag id=1 name="me out">, #<Tag id=2 name="please">, #<Tag id=3 name="test">]
46
- model.tag_list = 'test, again'
47
- model.save #=> true
48
- model.tags #=> [#<Tag id=3 name="test">, #<Tag id=4 name="again">] # Checks for existing tags
49
- Tag.all #=> [#<Tag id=1 name="me out">, #<Tag id=2 name="please">, #<Tag id=3 name="test">, #<Tag id=4 name="again">]
50
- another = MyModel.new
51
- another.skill_list = 'test, all, you, like'
52
- another.save #=> true
53
- another.tag_list #=> []
54
- another.skills
55
- #=> [#<Tag id=5 name="all">, #<Tag id=6 name="like">, #<Tag id=3 name="test">, #<Tag id=7 name="you">]
56
-
57
- MyModel.tagged_with('test') #=> [#<MyModel id=1>, #<MyModel id=2>]
58
- MyModel.tagged_with('test', :on => 'tags') #=> [#<MyModel id=1>]
59
- MyModel.tagged_with('test', :on => 'skills') #=> [#<MyModel id=2>]
60
-
61
- # Traditional 'tags only' tagging
62
-
63
- class TagsOnly
64
- include DataMapper::Resource
65
- property :id, Integer, :serial => true
66
- has_tags
67
- end
68
-
69
- TagsOnly.auto_migrate!
70
-
71
- TagsOnly.taggable? #=> true
72
- TagsOnly.new.taggable? #=> true
73
-
74
- tags_only = TagsOnly.new
75
- tags_only.tag_list = 'tags, only'
76
- tags_only.tag_list #=> ['only', 'tags']
77
- tags_only.save #=> true
78
- tags_only.tags #=> [#<Tag id=8 name="only">, #<Tag id=9 name="tags">]
25
+ require 'rubygems'
26
+ require 'dm-core'
27
+ require 'dm-tags'
28
+
29
+ DataMapper.setup(:default, "sqlite3::memory:")
30
+
31
+ class MyModel
32
+ include DataMapper::Resource
33
+ property :id, Integer, :serial => true
34
+ has_tags_on :tags, :skills
35
+ end
36
+
37
+ DataMapper.auto_migrate!
38
+
39
+ # Contextual tagging
40
+ MyModel.taggable? #=> true
41
+ MyModel.new.taggable? #=> true
42
+
43
+ model = MyModel.new
44
+ model.tag_list = 'test, me out, please '
45
+ model.tag_list #=> ['me out', 'please', 'test'] # Sanitized and alphabetized
46
+ model.save #=> true
47
+ model.tags
48
+ #=> [#<Tag id=1 name="me out">, #<Tag id=2 name="please">, #<Tag id=3 name="test">]
49
+ model.tag_list = 'test, again'
50
+ model.save #=> true
51
+ model.tags
52
+ #=> [#<Tag id=3 name="test">, #<Tag id=4 name="again">] # Checks for existing tags
53
+ Tag.all
54
+ #=> [#<Tag id=1 name="me out">, #<Tag id=2 name="please">, #<Tag id=3 name="test">, #<Tag id=4 name="again">]
55
+ another = MyModel.new
56
+ another.skill_list = 'test, all, you, like'
57
+ another.save #=> true
58
+ another.tag_list #=> []
59
+ another.skills
60
+ #=> [#<Tag id=5 name="all">, #<Tag id=6 name="like">, #<Tag id=3 name="test">, #<Tag id=7 name="you">]
61
+
62
+ MyModel.tagged_with('test') #=> [#<MyModel id=1>, #<MyModel id=2>]
63
+ MyModel.tagged_with('test', :on => 'tags') #=> [#<MyModel id=1>]
64
+ MyModel.tagged_with('test', :on => 'skills') #=> [#<MyModel id=2>]
65
+
66
+ # Traditional 'tags only' tagging
67
+
68
+ class TagsOnly
69
+ include DataMapper::Resource
70
+ property :id, Integer, :serial => true
71
+ has_tags
72
+ end
73
+
74
+ TagsOnly.auto_migrate!
75
+
76
+ TagsOnly.taggable? #=> true
77
+ TagsOnly.new.taggable? #=> true
78
+
79
+ tags_only = TagsOnly.new
80
+ tags_only.tag_list = 'tags, only'
81
+ tags_only.tag_list #=> ['only', 'tags']
82
+ tags_only.save #=> true
83
+ tags_only.tags #=> [#<Tag id=8 name="only">, #<Tag id=9 name="tags">]
79
84
 
80
85
  == Requirements
81
86
 
@@ -1,4 +1,3 @@
1
- require 'dm-core'
2
1
  module DataMapper
3
2
  module Resource
4
3
  class << self
@@ -16,9 +15,9 @@ module DataMapper
16
15
  def has_tags_on(*args)
17
16
  args.flatten!
18
17
  args.uniq!
19
-
18
+
20
19
  self.extend(DataMapper::Tags::SingletonMethods)
21
-
20
+
22
21
  args.map{|arg| arg.to_sym}.each do |arg|
23
22
  class_eval <<-RUBY
24
23
  property :frozen_#{arg.to_s.singular}_list, String
@@ -42,22 +41,22 @@ module DataMapper
42
41
  return if #{arg.to_s.singular}_list.empty?
43
42
  deleted_#{arg} = frozen_#{arg.to_s.singular}_list.to_s.split(',') - #{arg.to_s.singular}_list
44
43
  deleted_#{arg}.each do |name|
45
- tag = Tag.first(:name => name)
46
- tagging = #{arg.to_s.singular}_taggings.first(:tag_id => tag.id)
47
- tagging.destroy
48
- #{arg.to_s.singular}_taggings.reload
49
- end
50
- #{arg.to_s.singular}_list.each do |name|
51
- tag = Tag.first(:name => name)
52
- next if #{arg}.to_a.include?(tag)
53
- tag = Tag.create!(:name => name) unless tag
54
- #{arg.to_s.singular}_taggings << Tagging.new(:tag => tag, :taggable_type => self.class.to_s, :tag_context => "#{arg}")
55
- end
56
- self.frozen_#{arg.to_s.singular}_list = #{arg}.map{|#{arg.to_s.singular}| #{arg.to_s.singular}.name}.sort.join(',')
44
+ tag = Tag.first(:name => name)
45
+ tagging = #{arg.to_s.singular}_taggings.first(:tag_id => tag.id)
46
+ tagging.destroy
47
+ #{arg.to_s.singular}_taggings.reload
57
48
  end
58
- RUBY
49
+ #{arg.to_s.singular}_list.each do |name|
50
+ tag = Tag.first(:name => name)
51
+ next if #{arg}.to_a.include?(tag)
52
+ tag = Tag.create!(:name => name) unless tag
53
+ #{arg.to_s.singular}_taggings << Tagging.new(:tag => tag, :taggable_type => self.class.to_s, :tag_context => "#{arg}")
54
+ end
55
+ self.frozen_#{arg.to_s.singular}_list = #{arg}.map{|#{arg.to_s.singular}| #{arg.to_s.singular}.name}.sort.join(',')
59
56
  end
57
+ RUBY
60
58
  end
59
+ end
61
60
 
62
61
  def has_tags(*args)
63
62
  has_tags_on :tags
@@ -77,7 +76,7 @@ module SingletonMethods
77
76
  conditions[:tag_context] = options[:on] if options[:on]
78
77
  Tagging.all(conditions).map{|tagging| tagging.taggable}
79
78
  end
80
-
79
+
81
80
  def taggable?
82
81
  true
83
82
  end
@@ -3,7 +3,7 @@ module DataMapper::Tags
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
- TINY = 2
6
+ TINY = 3
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
data/lib/dm-tags.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ require 'dm-core'
4
5
  require 'dm-tags/tagging'
5
6
  require 'dm-tags/tag'
6
7
  require 'dm-tags/dm_tags'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bobby Calderwood
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-31 00:00:00 -06:00
12
+ date: 2008-09-14 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.7.0
24
24
  version:
25
- description: This package brings tagging to DataMapper. It is inspired by Acts As Taggable On by Michael Bleigh, github's mbleigh. Props to him for the contextual tagging based on Acts As Taggable on Steroids.
25
+ description: This package brings tagging to DataMapper. It is inspired by Acts As Taggable On by Michael Bleigh, github's mbleigh. Props to him for the contextual tagging based on Acts As Taggable on Steroids.
26
26
  email:
27
27
  - bobby_calderwood@me.com
28
28
  executables: []
@@ -81,7 +81,7 @@ rubyforge_project: dm-tags
81
81
  rubygems_version: 1.2.0
82
82
  signing_key:
83
83
  specification_version: 2
84
- summary: This package brings tagging to DataMapper. It is inspired by Acts As Taggable On by Michael Bleigh, github's mbleigh. Props to him for the contextual tagging based on Acts As Taggable on Steroids.
84
+ summary: This package brings tagging to DataMapper. It is inspired by Acts As Taggable On by Michael Bleigh, github's mbleigh. Props to him for the contextual tagging based on Acts As Taggable on Steroids.
85
85
  test_files:
86
86
  - spec/dm-tags/dm_tags_spec.rb
87
87
  - spec/dm-tags/tag_spec.rb