acts_as_word_cloud 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +8 -9
- data/README.rdoc +19 -87
- data/Rakefile +1 -4
- data/VERSION +1 -1
- data/acts_as_word_cloud.gemspec +13 -18
- data/lib/acts_as_word_cloud/config.rb +6 -2
- data/lib/acts_as_word_cloud/railtie.rb +1 -0
- data/lib/acts_as_word_cloud/word_cloud.rb +108 -188
- data/lib/generators/acts_as_word_cloud/templates/config.rb +9 -4
- data/spec/acts_as_word_cloud_spec.rb +162 -99
- data/spec/dummy/app/models/article.rb +7 -5
- data/spec/dummy/app/models/article_reader.rb +10 -0
- data/spec/dummy/app/models/author.rb +5 -2
- data/spec/dummy/app/models/publisher.rb +5 -4
- data/spec/dummy/app/models/reader.rb +7 -4
- data/spec/dummy/db/migrate/20121107162154_create_system.rb +2 -28
- data/spec/dummy/db/schema.rb +14 -44
- data/spec/integration_spec.rb +123 -0
- data/spec/spec_helper.rb +18 -3
- data/spec/{dummy/features/support → support}/blueprints.rb +6 -21
- metadata +13 -17
- data/features/acts_as_word_cloud.feature +0 -9
- data/features/step_definitions/acts_as_word_cloud_steps.rb +0 -0
- data/features/support/env.rb +0 -13
- data/lib/model_methods_helper.rb +0 -87
- data/spec/dummy/app/models/following.rb +0 -5
- data/spec/dummy/app/models/site.rb +0 -8
- data/spec/dummy/lib/model_methods_helper.rb +0 -87
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
@@ -9,8 +9,8 @@ gem "rails", "~> 3.1.0"
|
|
9
9
|
group :development do
|
10
10
|
gem "sqlite3"
|
11
11
|
gem "rspec", "~> 2.8.0"
|
12
|
-
gem "
|
13
|
-
gem "
|
12
|
+
gem "rspec-rails"
|
13
|
+
gem "database_cleaner", "~>0.6.7"
|
14
14
|
gem "bundler", "~> 1.2.3"
|
15
15
|
gem "jeweler", "~> 1.8.4"
|
16
16
|
gem "debugger"
|
data/Gemfile.lock
CHANGED
@@ -32,11 +32,7 @@ GEM
|
|
32
32
|
arel (2.2.3)
|
33
33
|
builder (3.0.4)
|
34
34
|
columnize (0.3.6)
|
35
|
-
|
36
|
-
builder (>= 2.1.2)
|
37
|
-
diff-lcs (>= 1.1.3)
|
38
|
-
gherkin (~> 2.11.0)
|
39
|
-
json (>= 1.4.6)
|
35
|
+
database_cleaner (0.6.7)
|
40
36
|
debugger (1.2.1)
|
41
37
|
columnize (>= 0.3.1)
|
42
38
|
debugger-linecache (~> 1.1.1)
|
@@ -48,8 +44,6 @@ GEM
|
|
48
44
|
erubis (2.7.0)
|
49
45
|
faker (1.0.1)
|
50
46
|
i18n (~> 0.4)
|
51
|
-
gherkin (2.11.5)
|
52
|
-
json (>= 1.4.6)
|
53
47
|
git (1.2.5)
|
54
48
|
hike (1.2.1)
|
55
49
|
i18n (0.6.1)
|
@@ -102,6 +96,11 @@ GEM
|
|
102
96
|
rspec-expectations (2.8.0)
|
103
97
|
diff-lcs (~> 1.1.2)
|
104
98
|
rspec-mocks (2.8.0)
|
99
|
+
rspec-rails (2.8.1)
|
100
|
+
actionpack (>= 3.0)
|
101
|
+
activesupport (>= 3.0)
|
102
|
+
railties (>= 3.0)
|
103
|
+
rspec (~> 2.8.0)
|
105
104
|
sprockets (2.0.4)
|
106
105
|
hike (~> 1.2)
|
107
106
|
rack (~> 1.0)
|
@@ -119,12 +118,12 @@ PLATFORMS
|
|
119
118
|
|
120
119
|
DEPENDENCIES
|
121
120
|
bundler (~> 1.2.3)
|
122
|
-
|
121
|
+
database_cleaner (~> 0.6.7)
|
123
122
|
debugger
|
124
123
|
faker (~> 1.0.1)
|
125
124
|
jeweler (~> 1.8.4)
|
126
125
|
machinist (= 1.0.6)
|
127
126
|
rails (~> 3.1.0)
|
128
|
-
rdoc (~> 3.12)
|
129
127
|
rspec (~> 2.8.0)
|
128
|
+
rspec-rails
|
130
129
|
sqlite3
|
data/README.rdoc
CHANGED
@@ -1,109 +1,41 @@
|
|
1
1
|
= acts_as_word_cloud
|
2
2
|
|
3
|
-
|
3
|
+
Generate a word cloud of a model's database attributes, methods, and associations.
|
4
4
|
|
5
5
|
= How to use
|
6
6
|
|
7
7
|
class Article < ActiveRecord::Base
|
8
|
-
acts_as_word_cloud :
|
8
|
+
acts_as_word_cloud :included_methods => [:truncated_title]
|
9
9
|
|
10
|
-
belongs_to :site
|
11
10
|
belongs_to :author
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
|
12
|
+
def truncated_title
|
13
|
+
title[0..25] if title
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
=> ["Artcle title", "genre", "description", "review", "Website name", "domain", "tagline", <names of affiliated companies>,
|
19
|
-
"Author name", "gender", "location", "bio", "quote", <titles of other authored articles>,
|
20
|
-
"Publisher name", "address", "city", "state", "zip code", "phone number", <titles of other articles published>]
|
21
|
-
|
22
|
-
== Add the gem to your gemfile
|
17
|
+
Calling Article.last.word_cloud will return
|
23
18
|
|
24
|
-
|
19
|
+
* Database fields: "Near-Response Advertising", "Looking at the next generation of advertising companies, it...",
|
20
|
+
* Methods: "Near-Response Advert"
|
21
|
+
* Associations: "Jeremiah Hemphill" (Author name)
|
25
22
|
|
26
|
-
==
|
23
|
+
== Installing the gem
|
27
24
|
|
25
|
+
gem "acts_as_word_cloud"
|
28
26
|
rails generate acts_as_word_cloud:install
|
29
|
-
rake db:migrate
|
30
27
|
|
31
28
|
== Add the mixin to your models
|
32
29
|
|
33
|
-
|
34
|
-
acts_as_word_cloud :methods_to_use => [<Symbol>], :excluded_models => [<Constant>], :skipped_attributes => [<Symbol>], :depth => <Integer>
|
35
|
-
end
|
36
|
-
|
37
|
-
There are four options to customize search per model:
|
38
|
-
* methods_to_use : specify which methods (that return strings) should be called when the model is being searched. Models that are being scanned as associations on the model calling word_cloud will only return a value if each of them has a methods_to_use containing a valid method for that model.
|
39
|
-
* excluded_models : select associated models that you would like to leave out of the search.
|
40
|
-
* skipped_attributes : by default, all string attributes are returned, unless some are set to be skipped.
|
41
|
-
* depth : indicates the level of recursion word_cloud should take on the model being searched.
|
42
|
-
|
43
|
-
== Set options for gem's config file
|
44
|
-
|
45
|
-
/config/initializers/acts_as_word_cloud.rb:
|
46
|
-
|
47
|
-
ActsAsWordCloud.configure do |config|
|
48
|
-
config.min_depth = 1
|
49
|
-
config.no_mixin_fields = [:name, :title, :label]
|
50
|
-
end
|
51
|
-
|
52
|
-
Here you can set the default minimum depth to use on all models that include the mixin. (Depth must be greater than or equal to 1, word_cloud will return an error message if not so)
|
53
|
-
|
54
|
-
The no_mixin_fields option allows you to list methods to call on models that do not include the mixin for the gem. These models would be traversed during searches on models with the mixin if they aren't explicitly excluded in the hash. If no methods are added to the list or if a model does not respond to any on this list, word_cloud will return the object's class name.
|
55
|
-
|
56
|
-
== Searching
|
57
|
-
|
58
|
-
Example:
|
59
|
-
|
60
|
-
class Publisher < ActiveRecord::Base
|
61
|
-
belongs_to :site
|
62
|
-
end
|
63
|
-
|
64
|
-
class Site < ActiveRecord::Base
|
65
|
-
acts_as_word_cloud :excluded_models => [Author]
|
66
|
-
|
67
|
-
has_many :publishers
|
68
|
-
has_many :authors
|
69
|
-
has_many :articles
|
70
|
-
end
|
71
|
-
|
72
|
-
class Author < ActiveRecord::Base
|
73
|
-
acts_as_word_cloud :methods_to_use => [:full_name, :random_quote] :skipped_attributes => [:phone_number]
|
74
|
-
|
75
|
-
has_many :articles
|
76
|
-
belongs_to :site
|
77
|
-
end
|
78
|
-
|
79
|
-
class Article < ActiveRecord::Base
|
80
|
-
acts_as_word_cloud :methods_to_use => [:title], :depth => 2
|
81
|
-
|
82
|
-
belongs_to :author
|
83
|
-
belongs_to :site
|
84
|
-
end
|
85
|
-
|
86
|
-
Once model defaults are set, the method to call is .word_cloud:
|
87
|
-
|
88
|
-
Site.last.word_cloud
|
89
|
-
=> model's string attributes, Publisher names (:name having been added to no_mixin_fields in config file),
|
90
|
-
and associated Article titles (this model ignores its associated Author objects)
|
91
|
-
|
92
|
-
Author.last.word_cloud
|
93
|
-
=> model's string attributes except for :phone_number and the values for the methods :full_name and :random_quote,
|
94
|
-
associated Article titles, and nothing for associated Sites since methods_to_use isn't set on the Site model
|
95
|
-
|
96
|
-
Article.last.word_cloud
|
97
|
-
=> model's string attributes, (because of depth 2) the above data for Author and Site associated to current Article.
|
98
|
-
keeping in mind that the above results are due to the default depth being set to 1
|
99
|
-
and that so would they be on the recursive calls to those associated objects
|
100
|
-
|
101
|
-
When the method is scanning through objects recursively it goes as 'deep' as the original model's setting suggests. There may be cycling through the same objects but it will never be stuck in an endless loop since each further model's depth setting is not consulted.
|
30
|
+
The mixin has five options:
|
102
31
|
|
103
|
-
|
32
|
+
* included_methods An array of method symbols used to create this model's word cloud
|
33
|
+
* excluded_methods An array of method symbols that should not be used in the word cloud.
|
34
|
+
* excluded_models An array of model constants whose data should not be included in the word cloud
|
35
|
+
* depth_level How many levels of associations to include
|
36
|
+
* object_name_method How to name the object when included in the word cloud as an association
|
104
37
|
|
105
|
-
|
106
|
-
* The symbol :array to get results listed in an array, by default they are returned in a single string
|
38
|
+
These settings are optional. Using the mixin without any options will pull data from the database and associations only. Default values are set through the config file located in config/initializers/acts_as_word_cloud.rb.
|
107
39
|
|
108
40
|
== Contributing to acts_as_word_cloud
|
109
41
|
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
|
|
20
20
|
gem.summary = %Q{Search function for associated objects on model}
|
21
21
|
gem.description = %Q{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}
|
22
22
|
gem.email = "jeremiah@cloudspace.com"
|
23
|
-
gem.authors = ["Jeremiah Hemphill"]
|
23
|
+
gem.authors = ["Jeremiah Hemphill", "Alfredo Uribe"]
|
24
24
|
# dependencies defined in Gemfile
|
25
25
|
end
|
26
26
|
Jeweler::RubygemsDotOrgTasks.new
|
@@ -36,9 +36,6 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
36
36
|
spec.rcov = true
|
37
37
|
end
|
38
38
|
|
39
|
-
require 'cucumber/rake/task'
|
40
|
-
Cucumber::Rake::Task.new(:features)
|
41
|
-
|
42
39
|
task :default => :spec
|
43
40
|
|
44
41
|
require 'rdoc/task'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/acts_as_word_cloud.gemspec
CHANGED
@@ -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.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jeremiah Hemphill"]
|
12
|
-
s.date = "2013-02-
|
11
|
+
s.authors = ["Jeremiah Hemphill", "Alfredo Uribe"]
|
12
|
+
s.date = "2013-02-21"
|
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 = [
|
@@ -29,9 +29,6 @@ Gem::Specification.new do |s|
|
|
29
29
|
"Rakefile",
|
30
30
|
"VERSION",
|
31
31
|
"acts_as_word_cloud.gemspec",
|
32
|
-
"features/acts_as_word_cloud.feature",
|
33
|
-
"features/step_definitions/acts_as_word_cloud_steps.rb",
|
34
|
-
"features/support/env.rb",
|
35
32
|
"lib/acts_as_word_cloud.rb",
|
36
33
|
"lib/acts_as_word_cloud/config.rb",
|
37
34
|
"lib/acts_as_word_cloud/engine.rb",
|
@@ -39,7 +36,6 @@ Gem::Specification.new do |s|
|
|
39
36
|
"lib/acts_as_word_cloud/word_cloud.rb",
|
40
37
|
"lib/generators/acts_as_word_cloud/install_generator.rb",
|
41
38
|
"lib/generators/acts_as_word_cloud/templates/config.rb",
|
42
|
-
"lib/model_methods_helper.rb",
|
43
39
|
"spec/acts_as_word_cloud_spec.rb",
|
44
40
|
"spec/dummy/README.rdoc",
|
45
41
|
"spec/dummy/Rakefile",
|
@@ -50,11 +46,10 @@ Gem::Specification.new do |s|
|
|
50
46
|
"spec/dummy/app/mailers/.gitkeep",
|
51
47
|
"spec/dummy/app/models/.gitkeep",
|
52
48
|
"spec/dummy/app/models/article.rb",
|
49
|
+
"spec/dummy/app/models/article_reader.rb",
|
53
50
|
"spec/dummy/app/models/author.rb",
|
54
|
-
"spec/dummy/app/models/following.rb",
|
55
51
|
"spec/dummy/app/models/publisher.rb",
|
56
52
|
"spec/dummy/app/models/reader.rb",
|
57
|
-
"spec/dummy/app/models/site.rb",
|
58
53
|
"spec/dummy/app/views/layouts/application.html.erb",
|
59
54
|
"spec/dummy/config.ru",
|
60
55
|
"spec/dummy/config/application.rb",
|
@@ -74,16 +69,16 @@ Gem::Specification.new do |s|
|
|
74
69
|
"spec/dummy/config/routes.rb",
|
75
70
|
"spec/dummy/db/migrate/20121107162154_create_system.rb",
|
76
71
|
"spec/dummy/db/schema.rb",
|
77
|
-
"spec/dummy/features/support/blueprints.rb",
|
78
72
|
"spec/dummy/lib/assets/.gitkeep",
|
79
|
-
"spec/dummy/lib/model_methods_helper.rb",
|
80
73
|
"spec/dummy/log/.gitkeep",
|
81
74
|
"spec/dummy/public/404.html",
|
82
75
|
"spec/dummy/public/422.html",
|
83
76
|
"spec/dummy/public/500.html",
|
84
77
|
"spec/dummy/public/favicon.ico",
|
85
78
|
"spec/dummy/script/rails",
|
86
|
-
"spec/
|
79
|
+
"spec/integration_spec.rb",
|
80
|
+
"spec/spec_helper.rb",
|
81
|
+
"spec/support/blueprints.rb"
|
87
82
|
]
|
88
83
|
s.homepage = "http://github.com/jeremiahishere/acts_as_word_cloud"
|
89
84
|
s.licenses = ["MIT"]
|
@@ -98,8 +93,8 @@ Gem::Specification.new do |s|
|
|
98
93
|
s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"])
|
99
94
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
100
95
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
101
|
-
s.add_development_dependency(%q<
|
102
|
-
s.add_development_dependency(%q<
|
96
|
+
s.add_development_dependency(%q<rspec-rails>, [">= 0"])
|
97
|
+
s.add_development_dependency(%q<database_cleaner>, ["~> 0.6.7"])
|
103
98
|
s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
|
104
99
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
105
100
|
s.add_development_dependency(%q<debugger>, [">= 0"])
|
@@ -107,8 +102,8 @@ Gem::Specification.new do |s|
|
|
107
102
|
s.add_dependency(%q<rails>, ["~> 3.1.0"])
|
108
103
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
109
104
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
110
|
-
s.add_dependency(%q<
|
111
|
-
s.add_dependency(%q<
|
105
|
+
s.add_dependency(%q<rspec-rails>, [">= 0"])
|
106
|
+
s.add_dependency(%q<database_cleaner>, ["~> 0.6.7"])
|
112
107
|
s.add_dependency(%q<bundler>, ["~> 1.2.3"])
|
113
108
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
114
109
|
s.add_dependency(%q<debugger>, [">= 0"])
|
@@ -117,8 +112,8 @@ Gem::Specification.new do |s|
|
|
117
112
|
s.add_dependency(%q<rails>, ["~> 3.1.0"])
|
118
113
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
119
114
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
120
|
-
s.add_dependency(%q<
|
121
|
-
s.add_dependency(%q<
|
115
|
+
s.add_dependency(%q<rspec-rails>, [">= 0"])
|
116
|
+
s.add_dependency(%q<database_cleaner>, ["~> 0.6.7"])
|
122
117
|
s.add_dependency(%q<bundler>, ["~> 1.2.3"])
|
123
118
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
124
119
|
s.add_dependency(%q<debugger>, [">= 0"])
|
@@ -15,8 +15,10 @@ module ActsAsWordCloud
|
|
15
15
|
# setup config data
|
16
16
|
class Configuration
|
17
17
|
include ActiveSupport::Configurable
|
18
|
-
|
19
|
-
config_accessor :
|
18
|
+
# default recursion depth when looking at data in associations
|
19
|
+
config_accessor :default_search_depth
|
20
|
+
# List of name methods to try on associations
|
21
|
+
config_accessor :object_name_methods
|
20
22
|
|
21
23
|
def param_name
|
22
24
|
config.param_name.respond_to?(:call) ? config.param_name.call() : config.param_name
|
@@ -26,6 +28,8 @@ module ActsAsWordCloud
|
|
26
28
|
# setup default options
|
27
29
|
# this should match the generator config that goes in the initializer file
|
28
30
|
configure do |config|
|
31
|
+
config.default_search_depth = 1
|
32
|
+
config.object_name_methods = [:name, :title, :label, :to_s]
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
@@ -5,6 +5,7 @@ require 'acts_as_word_cloud/config'
|
|
5
5
|
module ActsAsWordCloud
|
6
6
|
class Railtie < ::Rails::Railtie
|
7
7
|
initializer 'acts_as_word_cloud' do |app|
|
8
|
+
# just one mixin: acts_ac_word_cloud
|
8
9
|
require 'acts_as_word_cloud/word_cloud'
|
9
10
|
ActiveRecord::Base.send :include, ActsAsWordCloud::WordCloud
|
10
11
|
end
|