taggregator 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -11,4 +11,5 @@ group :development do
11
11
  gem "jeweler", "~> 1.6.2"
12
12
  gem "rcov", ">= 0"
13
13
  gem 'mongo_mapper', '~> 0.9.0'
14
+ gem 'pry'
14
15
  end
@@ -8,12 +8,15 @@ GEM
8
8
  activesupport (3.0.9)
9
9
  bson (1.3.1)
10
10
  builder (2.1.2)
11
+ coderay (0.9.8)
11
12
  git (1.2.5)
12
13
  i18n (0.5.0)
13
14
  jeweler (1.6.4)
14
15
  bundler (~> 1.0)
15
16
  git (>= 1.2.5)
16
17
  rake
18
+ method_source (0.6.0)
19
+ ruby_parser (>= 2.0.5)
17
20
  mongo (1.3.1)
18
21
  bson (>= 1.3.1)
19
22
  mongo_mapper (0.9.1)
@@ -22,9 +25,18 @@ GEM
22
25
  plucky (~> 0.3.8)
23
26
  plucky (0.3.8)
24
27
  mongo (~> 1.3)
28
+ pry (0.9.2)
29
+ coderay (>= 0.9.8)
30
+ method_source (>= 0.6.0)
31
+ ruby_parser (>= 2.0.5)
32
+ slop (~> 1.9.0)
25
33
  rake (0.9.2)
26
34
  rcov (0.9.9)
35
+ ruby_parser (2.0.6)
36
+ sexp_processor (~> 3.0)
37
+ sexp_processor (3.0.5)
27
38
  shoulda (2.11.3)
39
+ slop (1.9.1)
28
40
 
29
41
  PLATFORMS
30
42
  ruby
@@ -33,5 +45,6 @@ DEPENDENCIES
33
45
  bundler (~> 1.0.0)
34
46
  jeweler (~> 1.6.2)
35
47
  mongo_mapper (~> 0.9.0)
48
+ pry
36
49
  rcov
37
50
  shoulda
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Taggregator
2
2
 
3
- Adds tagging with context and aggregation of tags for MongoMapper. Adds weight and distribution convenience methods to models in which it is included. Uses MongoDB's increment/decrement ($inc/$dec) to keep real-time counts of individual tags in context with optional type. Based on 'Mongoid Taggable With Context' (https://github.com/aq1018/mongoid_taggable_with_context).
3
+ Adds tagging in context (and aggregation of those tags) to your MongoMapper models. Tag weight and distribution methods make it easy to find real-time taxonomical hotspots in datastore. **Taggregator** Uses MongoDB's increment/decrement (`$inc`/`$dec`) to keep real-time counts of individual tags in context with optional type. Based on [Mongoid Taggable With Context](https://github.com/aq1018/mongoid_taggable_with_context "The Progenitor.").
4
4
 
5
- ## Usage
5
+ ## Basic Usage
6
6
 
7
- **Taggregator** is very easy to use. Just include the MongoMapper plugin in your model the normal way and call `taggable`, like so:
7
+ **Taggregator** is easy to use. Just include the MongoMapper plugin in your model the normal way and call `taggable`, like so:
8
8
 
9
9
  class Article
10
10
  include MongoMapper::Document
@@ -19,9 +19,9 @@ Adds tagging with context and aggregation of tags for MongoMapper. Adds weight a
19
19
 
20
20
  a = Article.new
21
21
 
22
- Tags are then set with a string by calling `a.tags = 'space separated tags'`. Tag separators default to a space character, but as you see in the above example, can be overridden for with any character or string of your choice. If we follow the lead of the example, we would set `a.ads` by calling `a.ads = 'comma,separated,tags'`. The call to `taggable` will also add the array representation of the taggable fields with context, accessible through `a.tags_array`, `a.keywords_array`, and `a.ads_array`. If you have an array of string tags and wish to set the tags array manually, you can (i.e., `a.ads_array = ['xmas', 'shopping', 'books']`). Just as setting the string `a.ads` will populate `a.ads_array`, setting the tags array will also populate the string representation of the tag list in context.
22
+ Tags are then set with a string by calling `a.tags = 'space separated tags'`. The tag separator character defaults to the space character, but as you see in the above example, it can be overridden with any character or string of your choice. If we follow the lead of the example, we would set `a.ads` by calling `a.ads = 'comma,separated,tags'`. The call to `taggable` injects an array representation of the model's taggable fields with context, accessible through `a.tags_array`, `a.keywords_array`, and `a.ads_array`. If you have an array of tags (strings) and wish to set the tags array manually, you can (i.e., `a.ads_array = ['xmas', 'shopping', 'books']`). When the string `a.ads` is set, `a.ads_array` is populated with the individual tags. Likewise, setting the tags array populates the string representation of the tag list for that context.
23
23
 
24
- The call to `taggable` will also allow you to do some pretty cool stuff now. You can get all articles tags with a call to `Article.tags` and all tags (in the 'keywords' context) with `Article.keywords`. If you would like to get a list of all keywords with the keyword's associated frequency/weight, simply do something like:
24
+ The call to `taggable` will mixes in some cool stuff. You can get all articles tags with a call to `Article.tags` and all tags (in the 'keywords' context) with `Article.keywords`. If you would like to get a list of all keywords with the keyword's associated frequency/weight, try this:
25
25
 
26
26
  Article.tags_with_weight_for :keywords
27
27
  => [["stocks", 4], ["finance", 4], ["banking", 3], ["bonds", 1]]
@@ -38,5 +38,5 @@ The call to `taggable` will also allow you to do some pretty cool stuff now. You
38
38
 
39
39
  ## Copyright
40
40
 
41
- Copyright © 2011 Mark Coates. See LICENSE.txt for further details.
42
-
41
+ Copyright © 2011 Mark Coates and dtime, inc. (http://dtime.com). See LICENSE.txt for further details.
42
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -6,8 +6,8 @@ module MongoMapper
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  included do
9
- class_inheritable_reader :taggable_with_context_options
10
- write_inheritable_attribute(:taggable_with_context_options, {})
9
+ class_attribute :taggable_with_context_options
10
+ self.taggable_with_context_options = {}
11
11
  delegate "convert_string_to_array", :to => 'self.class'
12
12
  delegate "convert_array_to_string", :to => 'self.class'
13
13
  delegate "get_tag_separator_for", :to => 'self.class'
@@ -51,9 +51,9 @@ module MongoMapper
51
51
  tags_array_field = options[:array_field]
52
52
 
53
53
  # register / update settings
54
- class_options = taggable_with_context_options || {}
54
+ class_options = self.taggable_with_context_options || {}
55
55
  class_options[tags_field] = options
56
- write_inheritable_attribute(:taggable_with_context_options, class_options)
56
+ self.taggable_with_context_options = class_options
57
57
 
58
58
  # setup fields & indexes
59
59
  key tags_field.to_sym, String, :default => ""
@@ -168,10 +168,6 @@ module MongoMapper
168
168
  taggable_with_context_options[context]
169
169
  end
170
170
 
171
- def tags_for(context, conditions={})
172
- raise AggregationStrategyMissing
173
- end
174
-
175
171
  # Collection name for storing results of tag count aggregation
176
172
  def aggregation_collection_for(context)
177
173
  "#{collection_name}_#{context}_aggregation"
@@ -213,7 +209,19 @@ module MongoMapper
213
209
  def tagged_with(context, tags)
214
210
  tags = convert_string_to_array(tags, get_tag_separator_for(context)) if tags.is_a? String
215
211
  array_field = tag_options_for(context)[:array_field]
216
- all_in(array_field => tags)
212
+ where(:"#{array_field}".in => tags)
213
+ end
214
+
215
+ # tags for similar items
216
+ # def similar?(article)
217
+ # end
218
+
219
+ # an array returned with similar items
220
+ def find_similar(article, options={:through => :tags})
221
+ context = options[:through]
222
+ array_field = tag_options_for(options[:through])[:array_field]
223
+ tags = article[array_field]
224
+ where(:"#{array_field}".in => tags)
217
225
  end
218
226
 
219
227
  # Helper method to convert a String to an Array based on the
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{taggregator}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Mark Coates"]
12
- s.date = %q{2011-07-21}
11
+ s.authors = [%q{Mark Coates}]
12
+ s.date = %q{2011-08-08}
13
13
  s.description = %q{Adds tagging with context and aggregation of tags for MongoMapper. Adds weight and distribution convenience methods to models in which it is included. Uses MongoDB's increment/decrement ($inc/$dec) to keep real-time counts of individual tags in context with optional type. Based on 'Mongoid Taggable With Context' (https://github.com/aq1018/mongoid_taggable_with_context).}
14
14
  s.email = %q{mark.coates@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -28,12 +28,13 @@ Gem::Specification.new do |s|
28
28
  "lib/taggregator/instance_methods.rb",
29
29
  "taggregator.gemspec",
30
30
  "test/helper.rb",
31
+ "test/models/article.rb",
31
32
  "test/test_taggregator.rb"
32
33
  ]
33
34
  s.homepage = %q{http://github.com/oddlyzen/taggregator}
34
- s.licenses = ["MIT"]
35
- s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.6.2}
35
+ s.licenses = [%q{MIT}]
36
+ s.require_paths = [%q{lib}]
37
+ s.rubygems_version = %q{1.8.6}
37
38
  s.summary = %q{Bad-ass tagging intelligence for your document tagging in MongoMapper.}
38
39
 
39
40
  if s.respond_to? :specification_version then
@@ -45,12 +46,14 @@ Gem::Specification.new do |s|
45
46
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
46
47
  s.add_development_dependency(%q<rcov>, [">= 0"])
47
48
  s.add_development_dependency(%q<mongo_mapper>, ["~> 0.9.0"])
49
+ s.add_development_dependency(%q<pry>, [">= 0"])
48
50
  else
49
51
  s.add_dependency(%q<shoulda>, [">= 0"])
50
52
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
53
  s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
52
54
  s.add_dependency(%q<rcov>, [">= 0"])
53
55
  s.add_dependency(%q<mongo_mapper>, ["~> 0.9.0"])
56
+ s.add_dependency(%q<pry>, [">= 0"])
54
57
  end
55
58
  else
56
59
  s.add_dependency(%q<shoulda>, [">= 0"])
@@ -58,6 +61,7 @@ Gem::Specification.new do |s|
58
61
  s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
59
62
  s.add_dependency(%q<rcov>, [">= 0"])
60
63
  s.add_dependency(%q<mongo_mapper>, ["~> 0.9.0"])
64
+ s.add_dependency(%q<pry>, [">= 0"])
61
65
  end
62
66
  end
63
67
 
@@ -1,4 +1,7 @@
1
1
  require 'rubygems'
2
+ require 'active_support'
3
+ require 'pry'
4
+ require 'mongo_mapper'
2
5
  require 'bundler'
3
6
  begin
4
7
  Bundler.setup(:default, :development)
@@ -14,5 +17,14 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
17
  $LOAD_PATH.unshift(File.dirname(__FILE__))
15
18
  require 'taggregator'
16
19
 
20
+ MongoMapper.database = "testing_taggregator"
21
+
22
+ require 'models/article'
23
+
17
24
  class Test::Unit::TestCase
18
25
  end
26
+
27
+ @lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus porttitor, ipsum a commodo aliquet,
28
+ velit ligula porttitor eros, sit amet consequat purus massa sit amet quam. Aliquam tempus magna faucibus
29
+ lacus ultricies rhoncus. In ut metus purus, at venenatis est. Donec vel elementum turpis. Nullam feugiat
30
+ massa quis elit egestas."
@@ -0,0 +1,13 @@
1
+ class Article
2
+ include MongoMapper::Document
3
+ include MongoMapper::Plugins::Taggregator
4
+
5
+ key :title, String
6
+ key :body, String
7
+ key :authors, Array
8
+
9
+ taggable
10
+ taggable :keywords
11
+ taggable :ads, :separator => ', '
12
+
13
+ end
@@ -1,7 +1,61 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestTaggregator < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ def setup
5
+ @articles = [
6
+ (@home_and_garden = Article.new( title: 'Is your refrigerator running? Better catch it',
7
+ body: @lipsum,
8
+ authors: ['Thomas Mann', 'Jim Byrd'])),
9
+ (@golf_digest = Article.new( title: 'The Colonial: In Full Swing',
10
+ body: @lipsum,
11
+ authors: ['Rebecca Simmons']))
12
+ ]
13
+ @home_and_garden.keywords = 'luxury household appliances'
14
+ @home_and_garden.ads_array = ['LG Electronics', 'Kenneth Cole']
15
+ @golf_digest.keywords = 'resort vacation luxury'
16
+ @golf_digest.ads_array = ['Calloway', 'Ping']
17
+ save_articles
6
18
  end
19
+
20
+ should "Have keywords context" do
21
+ assert @home_and_garden.keywords
22
+ assert @golf_digest.keywords
23
+ end
24
+
25
+ should 'parse a string to tags' do
26
+ assert @home_and_garden.keywords_array.count == 3
27
+ assert @golf_digest.keywords_array.count == 3
28
+ end
29
+
30
+ should 'parse an array for a string representation of the tags' do
31
+ assert @home_and_garden.ads == 'LG Electronics, Kenneth Cole'
32
+ assert @golf_digest.ads == 'Calloway, Ping'
33
+ end
34
+
35
+ should 'return all tags for Articles with the tag\'s corresponding weight' do
36
+ tags = Article.tags_with_weight_for :keywords
37
+ assert tags.kind_of? Array
38
+ assert tags[0][0] == 'luxury' && tags[0][1] == 2
39
+ end
40
+
41
+ should 'return a list of articles if given a tag' do
42
+ articles = Article.keywords_tagged_with 'luxury'
43
+ assert articles.count == 2
44
+ end
45
+
46
+ should 'find similar articles when given a context and article' do
47
+ article = Article.all.first
48
+ assert (Article.find_similar article, :through => :keywords).count == 2
49
+ end
50
+
51
+ def teardown
52
+ Article.destroy_all
53
+ end
54
+
55
+ private
56
+ def save_articles
57
+ @articles.each{ |article| article.save }
58
+ end
59
+
7
60
  end
61
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taggregator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-21 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2011-08-08 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: shoulda
17
- requirement: &2152444980 !ruby/object:Gem::Requirement
16
+ requirement: &2161338120 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :development
24
23
  prerelease: false
25
- version_requirements: *2152444980
24
+ version_requirements: *2161338120
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: bundler
28
- requirement: &2152444440 !ruby/object:Gem::Requirement
27
+ requirement: &2161336380 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: 1.0.0
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2152444440
35
+ version_requirements: *2161336380
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: jeweler
39
- requirement: &2152443920 !ruby/object:Gem::Requirement
38
+ requirement: &2161326480 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: 1.6.2
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2152443920
46
+ version_requirements: *2161326480
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: rcov
50
- requirement: &2152443340 !ruby/object:Gem::Requirement
49
+ requirement: &2161325420 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,10 +54,10 @@ dependencies:
55
54
  version: '0'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2152443340
57
+ version_requirements: *2161325420
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: mongo_mapper
61
- requirement: &2152442720 !ruby/object:Gem::Requirement
60
+ requirement: &2161324300 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ~>
@@ -66,7 +65,18 @@ dependencies:
66
65
  version: 0.9.0
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *2152442720
68
+ version_requirements: *2161324300
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: &2161323420 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2161323420
70
80
  description: Adds tagging with context and aggregation of tags for MongoMapper. Adds
71
81
  weight and distribution convenience methods to models in which it is included. Uses
72
82
  MongoDB's increment/decrement ($inc/$dec) to keep real-time counts of individual
@@ -89,8 +99,8 @@ files:
89
99
  - lib/taggregator/instance_methods.rb
90
100
  - taggregator.gemspec
91
101
  - test/helper.rb
102
+ - test/models/article.rb
92
103
  - test/test_taggregator.rb
93
- has_rdoc: true
94
104
  homepage: http://github.com/oddlyzen/taggregator
95
105
  licenses:
96
106
  - MIT
@@ -106,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
116
  version: '0'
107
117
  segments:
108
118
  - 0
109
- hash: 1716478362843917750
119
+ hash: 3761616067399779497
110
120
  required_rubygems_version: !ruby/object:Gem::Requirement
111
121
  none: false
112
122
  requirements:
@@ -115,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
125
  version: '0'
116
126
  requirements: []
117
127
  rubyforge_project:
118
- rubygems_version: 1.6.2
128
+ rubygems_version: 1.8.6
119
129
  signing_key:
120
130
  specification_version: 3
121
131
  summary: Bad-ass tagging intelligence for your document tagging in MongoMapper.