acts_as_word_cloud 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ == unreleased changes
2
+
3
+ == 0.0.4
4
+
5
+ * Improved performance of the recursive word cloud by avoiding calling it multiple times on the same object
6
+ * Made rails requirements more general
7
+
1
8
  == 0.0.3
2
9
 
3
10
  * Added an option for permanently excluded models to the config file
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
- gem "rails", "~> 3.1.0"
5
+ gem "rails", ">= 3.1.0"
6
6
 
7
7
  # Add dependencies to develop your gem here.
8
8
  # Include everything needed to run rake, tests, features, etc.
@@ -11,7 +11,7 @@ group :development do
11
11
  gem "rspec", "~> 2.8.0"
12
12
  gem "rspec-rails"
13
13
  gem "database_cleaner", "~>0.6.7"
14
- gem "bundler", "~> 1.2.3"
14
+ gem "bundler", ">= 1.2.3"
15
15
  gem "jeweler", "~> 1.8.4"
16
16
  gem "debugger"
17
17
  end
@@ -117,13 +117,13 @@ PLATFORMS
117
117
  ruby
118
118
 
119
119
  DEPENDENCIES
120
- bundler (~> 1.2.3)
120
+ bundler (>= 1.2.3)
121
121
  database_cleaner (~> 0.6.7)
122
122
  debugger
123
123
  faker (~> 1.0.1)
124
124
  jeweler (~> 1.8.4)
125
125
  machinist (= 1.0.6)
126
- rails (~> 3.1.0)
126
+ rails (>= 3.1.0)
127
127
  rspec (~> 2.8.0)
128
128
  rspec-rails
129
129
  sqlite3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "acts_as_word_cloud"
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremiah Hemphill", "Alfredo Uribe"]
12
- s.date = "2013-02-21"
12
+ s.date = "2013-03-14"
13
13
  s.description = "Returns values for specified methods on each object containing mixix and values from general methods specified for models that don't have the mixin; depending on 'depth' value passed in the method will also recursively return values for associated objects on each model scanned"
14
14
  s.email = "jeremiah@cloudspace.com"
15
15
  s.extra_rdoc_files = [
@@ -90,31 +90,31 @@ Gem::Specification.new do |s|
90
90
  s.specification_version = 3
91
91
 
92
92
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
93
- s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"])
93
+ s.add_runtime_dependency(%q<rails>, [">= 3.1.0"])
94
94
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
95
95
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
96
96
  s.add_development_dependency(%q<rspec-rails>, [">= 0"])
97
97
  s.add_development_dependency(%q<database_cleaner>, ["~> 0.6.7"])
98
- s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
98
+ s.add_development_dependency(%q<bundler>, [">= 1.2.3"])
99
99
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
100
100
  s.add_development_dependency(%q<debugger>, [">= 0"])
101
101
  else
102
- s.add_dependency(%q<rails>, ["~> 3.1.0"])
102
+ s.add_dependency(%q<rails>, [">= 3.1.0"])
103
103
  s.add_dependency(%q<sqlite3>, [">= 0"])
104
104
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
105
105
  s.add_dependency(%q<rspec-rails>, [">= 0"])
106
106
  s.add_dependency(%q<database_cleaner>, ["~> 0.6.7"])
107
- s.add_dependency(%q<bundler>, ["~> 1.2.3"])
107
+ s.add_dependency(%q<bundler>, [">= 1.2.3"])
108
108
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
109
109
  s.add_dependency(%q<debugger>, [">= 0"])
110
110
  end
111
111
  else
112
- s.add_dependency(%q<rails>, ["~> 3.1.0"])
112
+ s.add_dependency(%q<rails>, [">= 3.1.0"])
113
113
  s.add_dependency(%q<sqlite3>, [">= 0"])
114
114
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
115
115
  s.add_dependency(%q<rspec-rails>, [">= 0"])
116
116
  s.add_dependency(%q<database_cleaner>, ["~> 0.6.7"])
117
- s.add_dependency(%q<bundler>, ["~> 1.2.3"])
117
+ s.add_dependency(%q<bundler>, [">= 1.2.3"])
118
118
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
119
119
  s.add_dependency(%q<debugger>, [">= 0"])
120
120
  end
@@ -53,10 +53,12 @@ module ActsAsWordCloud
53
53
  protected
54
54
 
55
55
  # Finds all text attributes, associated objects, and included methods down to a specified depth
56
+ # Avoids running the word cloud on objects that have already been included
56
57
  #
57
58
  # @param [Integer] depth How many layers of associations to search
59
+ # @param [Array] already_included_objects List of objects of models that have already been included in the word cloud
58
60
  # @return [Array] The word cloud for the specified object and depth
59
- def recursive_word_cloud(depth)
61
+ def recursive_word_cloud(depth, already_included_objects = [])
60
62
  # prepare an array of strings to be used as an output
61
63
  output = []
62
64
 
@@ -65,10 +67,16 @@ module ActsAsWordCloud
65
67
 
66
68
  # array of objects for every association minus a list of excluded objects
67
69
  objects = word_cloud_associated_objects
70
+
71
+ # do not search again on self
72
+ already_included_objects << self
73
+
68
74
  objects.each do |obj|
69
- if obj.respond_to?(:recursive_word_cloud) && depth > 1
75
+ if already_included_objects.include?(obj)
76
+ # pass because the data is already in the output
77
+ elsif obj.respond_to?(:recursive_word_cloud) && depth > 1
70
78
  # if the object has a word cloud mixin and we can recurse
71
- output |= obj.recursive_word_cloud(depth - 1)
79
+ output |= obj.recursive_word_cloud(depth - 1, already_included_objects)
72
80
  else
73
81
  # otherwise get the default name for the object
74
82
  output |= [self.word_cloud_object_name(obj)]
@@ -15,5 +15,5 @@ ActsAsWordCloud.configure do |config|
15
15
  #
16
16
  # Each of the contants in this list will be added to the word cloud attribute, excluded_models.
17
17
  # This will happen even when the attribute is included in the mixin call.
18
- # config.premanently_excluded_models = []
18
+ # config.permanently_excluded_models = []
19
19
  end
@@ -33,6 +33,7 @@ describe "ActsAsWordCloud" do
33
33
  @article.stub(:word_cloud_get_valid_strings).and_return([])
34
34
  @article.stub(:word_cloud_associated_objects).and_return([])
35
35
  end
36
+
36
37
  it "should call word_cloud_get_valid_strings" do
37
38
  @article.should_receive(:word_cloud_get_valid_strings).and_return([])
38
39
  @article.send(:recursive_word_cloud, 1)
@@ -43,9 +44,9 @@ describe "ActsAsWordCloud" do
43
44
  @article.send(:recursive_word_cloud, 1)
44
45
  end
45
46
 
46
- it "should call rescursive_word_cloud on an associated object if the depth is more than 1" do
47
+ it "should call rescursive_word_cloud on an associated object if the depth is more than 1 and it should include the calling object in the parameters" do
47
48
  object_with_word_cloud = mock(Author)
48
- object_with_word_cloud.should_receive(:recursive_word_cloud).with(1).and_return([])
49
+ object_with_word_cloud.should_receive(:recursive_word_cloud).with(1, [@article]).and_return([])
49
50
 
50
51
  @article.stub(:word_cloud_associated_objects).and_return([object_with_word_cloud])
51
52
  @article.send(:recursive_word_cloud, 2)
@@ -68,6 +69,15 @@ describe "ActsAsWordCloud" do
68
69
  @article.send(:recursive_word_cloud, 2)
69
70
  end
70
71
 
72
+ it "should not call rescursive_word_cloud on an associated object if the object is included in the already_included_objects" do
73
+ object_with_word_cloud = mock(Author)
74
+ object_with_word_cloud.should_not_receive(:recursive_word_cloud)
75
+ object_with_word_cloud.should_not_receive(:name)
76
+
77
+ @article.stub(:word_cloud_associated_objects).and_return([object_with_word_cloud])
78
+ @article.send(:recursive_word_cloud, 2, [object_with_word_cloud])
79
+ end
80
+
71
81
  it "should return an array of strings" do
72
82
  @article.stub(:word_cloud_get_valid_strings).and_return(["hello"])
73
83
  results = @article.send(:recursive_word_cloud, 1)
@@ -12,6 +12,7 @@ class CreateSystem < ActiveRecord::Migration
12
12
  create_table :authors do |t|
13
13
  t.integer :publisher_id
14
14
  t.string :name
15
+ t.text :biography
15
16
 
16
17
  t.timestamps
17
18
  end
@@ -30,6 +30,7 @@ ActiveRecord::Schema.define(:version => 20121107162154) do
30
30
  create_table "authors", :force => true do |t|
31
31
  t.integer "publisher_id"
32
32
  t.string "name"
33
+ t.text "biography"
33
34
  t.datetime "created_at"
34
35
  t.datetime "updated_at"
35
36
  end
@@ -108,12 +108,13 @@ describe "Integration tests" do
108
108
 
109
109
  end
110
110
 
111
- it "should return multiple levels of associations if the depth is set to 2" do
111
+ it "should return two levels of associations if the depth is set to 2" do
112
112
  @word_cloud_output = @article.word_cloud(:array)
113
113
 
114
114
  expected_word_cloud_output = [
115
- @author.name,
116
- @publisher.name,
115
+ @author.name, # default name
116
+ @author.biography, # from author word cloud
117
+ @publisher.name # default name
117
118
  ]
118
119
  expected_word_cloud_output.each do |str|
119
120
  @word_cloud_output.should include str
@@ -23,6 +23,7 @@ end
23
23
  Author.blueprint do
24
24
  publisher { Publisher.make }
25
25
  name { generate_tiny_text }
26
+ biography { generate_text }
26
27
  end
27
28
 
28
29
  Publisher.blueprint do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_word_cloud
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeremiah Hemphill
@@ -11,14 +11,14 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2013-02-21 00:00:00 Z
14
+ date: 2013-03-14 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ~>
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 3.1.0
24
24
  type: :runtime
@@ -73,7 +73,7 @@ dependencies:
73
73
  requirement: &id006 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
- - - ~>
76
+ - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: 1.2.3
79
79
  type: :development
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  requirements:
187
187
  - - ">="
188
188
  - !ruby/object:Gem::Version
189
- hash: 39024837777467519
189
+ hash: 2627755293098628913
190
190
  segments:
191
191
  - 0
192
192
  version: "0"