pose 1.3.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. data/README.md +11 -0
  2. data/Rakefile +4 -2
  3. data/app/models/pose/assignment.rb +34 -0
  4. data/app/models/pose/word.rb +24 -0
  5. data/db/migrate/20130308144915_pose_install.rb +18 -0
  6. data/lib/generators/pose/remove/templates/remove_migration.rb +3 -5
  7. data/lib/generators/pose/upgrade/templates/upgrade_migration.rb +9 -0
  8. data/lib/generators/pose/upgrade/upgrade_generator.rb +35 -0
  9. data/lib/pose/activerecord_base_additions.rb +5 -2
  10. data/lib/pose/engine.rb +5 -0
  11. data/lib/pose/internal_helpers.rb +13 -7
  12. data/lib/pose/{model_additions.rb → model_class_additions.rb} +8 -8
  13. data/lib/pose/railtie.rb +1 -2
  14. data/lib/pose/static_api.rb +5 -6
  15. data/lib/pose/version.rb +1 -1
  16. data/lib/pose.rb +5 -7
  17. data/lib/tasks/pose_tasks.rake +27 -29
  18. data/spec/dummy/Rakefile +7 -0
  19. data/spec/{support/models.rb → dummy/app/models/posable_one.rb} +1 -4
  20. data/spec/dummy/app/models/posable_two.rb +5 -0
  21. data/spec/dummy/config/application.rb +59 -0
  22. data/spec/dummy/config/boot.rb +10 -0
  23. data/spec/dummy/config/database.yml +25 -0
  24. data/spec/dummy/config/environment.rb +5 -0
  25. data/spec/dummy/config/environments/development.rb +37 -0
  26. data/spec/dummy/config/environments/production.rb +67 -0
  27. data/spec/dummy/config/environments/test.rb +37 -0
  28. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/spec/dummy/config/initializers/inflections.rb +15 -0
  30. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  31. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  32. data/spec/dummy/config/initializers/session_store.rb +8 -0
  33. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  34. data/spec/dummy/config/locales/en.yml +5 -0
  35. data/spec/dummy/config/routes.rb +2 -0
  36. data/spec/dummy/config.ru +4 -0
  37. data/spec/dummy/db/migrate/20130308054001_create_posable_one.rb +8 -0
  38. data/spec/dummy/db/migrate/20130308054142_create_posable_two.rb +9 -0
  39. data/spec/dummy/db/schema.rb +41 -0
  40. data/spec/dummy/script/rails +6 -0
  41. data/spec/factories/assignments.rb +8 -0
  42. data/spec/factories/posable_one.rb +5 -0
  43. data/spec/factories/words.rb +7 -0
  44. data/spec/internal_helpers_spec.rb +40 -42
  45. data/spec/models/assignment_spec.rb +46 -0
  46. data/spec/models/word_spec.rb +42 -0
  47. data/spec/pose_api_spec.rb +198 -196
  48. data/spec/spec_helper.rb +21 -77
  49. data/spec/support/matchers.rb +0 -1
  50. metadata +83 -102
  51. data/doc/Pose/InstanceMethods.html +0 -341
  52. data/doc/Pose.html +0 -774
  53. data/doc/PoseAssignment.html +0 -125
  54. data/doc/PoseGenerator.html +0 -255
  55. data/doc/PoseMigrations.html +0 -261
  56. data/doc/PoseWord.html +0 -125
  57. data/doc/_index.html +0 -134
  58. data/doc/class_list.html +0 -47
  59. data/doc/css/common.css +0 -1
  60. data/doc/css/full_list.css +0 -55
  61. data/doc/css/style.css +0 -322
  62. data/doc/file_list.html +0 -46
  63. data/doc/frames.html +0 -13
  64. data/doc/index.html +0 -134
  65. data/doc/js/app.js +0 -205
  66. data/doc/js/full_list.js +0 -167
  67. data/doc/js/jquery.js +0 -16
  68. data/doc/method_list.html +0 -150
  69. data/doc/top-level-namespace.html +0 -172
  70. data/lib/generators/pose/install/install_generator.rb +0 -56
  71. data/lib/generators/pose/install/templates/install_migration.rb +0 -24
  72. data/lib/pose/models/pose_assignment.rb +0 -31
  73. data/lib/pose/models/pose_word.rb +0 -28
  74. data/spec/factories.rb +0 -15
  75. data/spec/pose_assignment_spec.rb +0 -45
  76. data/spec/pose_word_spec.rb +0 -26
data/doc/method_list.html DELETED
@@ -1,150 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html>
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
-
7
- <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
8
-
9
- <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
10
-
11
-
12
-
13
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
14
-
15
- <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
16
-
17
-
18
- <base id="base_target" target="_parent" />
19
- </head>
20
- <body>
21
- <script type="text/javascript" charset="utf-8">
22
- if (window.top.frames.main) {
23
- document.getElementById('base_target').target = 'main';
24
- document.body.className = 'frames';
25
- }
26
- </script>
27
- <div id="content">
28
- <h1 id="full_list_header">Method List</h1>
29
- <div id="nav">
30
-
31
- <a target="_self" href="class_list.html">Classes</a>
32
-
33
- <a target="_self" href="method_list.html">Methods</a>
34
-
35
- <a target="_self" href="file_list.html">Files</a>
36
-
37
- </div>
38
- <div id="search">Search: <input type="text" /></div>
39
-
40
- <ul id="full_list" class="methods">
41
-
42
-
43
- <li class="r1 ">
44
- <span class='object_link'><a href="PoseGenerator.html#create_migration_file-instance_method" title="PoseGenerator#create_migration_file (method)">#create_migration_file</a></span>
45
-
46
- <small>PoseGenerator</small>
47
-
48
- </li>
49
-
50
-
51
- <li class="r2 ">
52
- <span class='object_link'><a href="Pose/InstanceMethods.html#delete_pose_index-instance_method" title="Pose::InstanceMethods#delete_pose_index (method)">#delete_pose_index</a></span>
53
-
54
- <small>Pose::InstanceMethods</small>
55
-
56
- </li>
57
-
58
-
59
- <li class="r1 ">
60
- <span class='object_link'><a href="PoseMigrations.html#down-class_method" title="PoseMigrations.down (method)">down</a></span>
61
-
62
- <small>PoseMigrations</small>
63
-
64
- </li>
65
-
66
-
67
- <li class="r2 ">
68
- <span class='object_link'><a href="Pose.html#get_words_to_add-class_method" title="Pose.get_words_to_add (method)">get_words_to_add</a></span>
69
-
70
- <small>Pose</small>
71
-
72
- </li>
73
-
74
-
75
- <li class="r1 ">
76
- <span class='object_link'><a href="Pose.html#get_words_to_remove-class_method" title="Pose.get_words_to_remove (method)">get_words_to_remove</a></span>
77
-
78
- <small>Pose</small>
79
-
80
- </li>
81
-
82
-
83
- <li class="r2 ">
84
- <span class='object_link'><a href="Pose.html#is_url-class_method" title="Pose.is_url (method)">is_url</a></span>
85
-
86
- <small>Pose</small>
87
-
88
- </li>
89
-
90
-
91
- <li class="r1 ">
92
- <span class='object_link'><a href="PoseGenerator.html#next_migration_number-class_method" title="PoseGenerator.next_migration_number (method)">next_migration_number</a></span>
93
-
94
- <small>PoseGenerator</small>
95
-
96
- </li>
97
-
98
-
99
- <li class="r2 ">
100
- <span class='object_link'><a href="#posify-instance_method" title="#posify (method)">#posify</a></span>
101
-
102
- <small>Top Level Namespace</small>
103
-
104
- </li>
105
-
106
-
107
- <li class="r1 ">
108
- <span class='object_link'><a href="Pose.html#root_word-class_method" title="Pose.root_word (method)">root_word</a></span>
109
-
110
- <small>Pose</small>
111
-
112
- </li>
113
-
114
-
115
- <li class="r2 ">
116
- <span class='object_link'><a href="Pose.html#search-class_method" title="Pose.search (method)">search</a></span>
117
-
118
- <small>Pose</small>
119
-
120
- </li>
121
-
122
-
123
- <li class="r1 ">
124
- <span class='object_link'><a href="PoseMigrations.html#up-class_method" title="PoseMigrations.up (method)">up</a></span>
125
-
126
- <small>PoseMigrations</small>
127
-
128
- </li>
129
-
130
-
131
- <li class="r2 ">
132
- <span class='object_link'><a href="Pose/InstanceMethods.html#update_pose_index-instance_method" title="Pose::InstanceMethods#update_pose_index (method)">#update_pose_index</a></span>
133
-
134
- <small>Pose::InstanceMethods</small>
135
-
136
- </li>
137
-
138
-
139
- <li class="r1 ">
140
- <span class='object_link'><a href="Pose/InstanceMethods.html#update_pose_words-instance_method" title="Pose::InstanceMethods#update_pose_words (method)">#update_pose_words</a></span>
141
-
142
- <small>Pose::InstanceMethods</small>
143
-
144
- </li>
145
-
146
-
147
- </ul>
148
- </div>
149
- </body>
150
- </html>
@@ -1,172 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>
7
- Top Level Namespace
8
-
9
- &mdash; Documentation by YARD 0.7.3
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- relpath = '';
19
- if (relpath != '') relpath += '/';
20
- </script>
21
-
22
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
23
-
24
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
25
-
26
-
27
- </head>
28
- <body>
29
- <script type="text/javascript" charset="utf-8">
30
- if (window.top.frames.main) document.body.className = 'frames';
31
- </script>
32
-
33
- <div id="header">
34
- <div id="menu">
35
-
36
- <a href="_index.html">Index</a> &raquo;
37
-
38
-
39
- <span class="title">Top Level Namespace</span>
40
-
41
-
42
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
- </div>
44
-
45
- <div id="search">
46
-
47
- <a id="class_list_link" href="#">Class List</a>
48
-
49
- <a id="method_list_link" href="#">Method List</a>
50
-
51
- <a id="file_list_link" href="#">File List</a>
52
-
53
- </div>
54
- <div class="clear"></div>
55
- </div>
56
-
57
- <iframe id="search_frame"></iframe>
58
-
59
- <div id="content"><h1>Top Level Namespace
60
-
61
-
62
-
63
- </h1>
64
-
65
- <dl class="box">
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
- </dl>
75
- <div class="clear"></div>
76
-
77
- <h2>Defined Under Namespace</h2>
78
- <p class="children">
79
-
80
-
81
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="Pose.html" title="Pose (module)">Pose</a></span>
82
-
83
-
84
-
85
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="PoseAssignment.html" title="PoseAssignment (class)">PoseAssignment</a></span>, <span class='object_link'><a href="PoseGenerator.html" title="PoseGenerator (class)">PoseGenerator</a></span>, <span class='object_link'><a href="PoseMigrations.html" title="PoseMigrations (class)">PoseMigrations</a></span>, <span class='object_link'><a href="PoseWord.html" title="PoseWord (class)">PoseWord</a></span>
86
-
87
-
88
- </p>
89
-
90
-
91
-
92
-
93
-
94
-
95
- <h2>
96
- Instance Method Summary
97
- <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
98
- </h2>
99
-
100
- <ul class="summary">
101
-
102
- <li class="public ">
103
- <span class="summary_signature">
104
-
105
- <a href="#posify-instance_method" title="#posify (instance method)">- (Object) <strong>posify</strong> </a>
106
-
107
-
108
-
109
- </span>
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
- <span class="summary_desc"><div class='inline'></div></span>
119
-
120
- </li>
121
-
122
-
123
- </ul>
124
-
125
-
126
-
127
-
128
- <div id="instance_method_details" class="method_details_list">
129
- <h2>Instance Method Details</h2>
130
-
131
-
132
- <div class="method_details first">
133
- <p class="signature first" id="posify-instance_method">
134
-
135
- - (<tt>Object</tt>) <strong>posify</strong>
136
-
137
-
138
-
139
- </p><table class="source_code">
140
- <tr>
141
- <td>
142
- <pre class="lines">
143
-
144
-
145
- 159
146
- 160
147
- 161</pre>
148
- </td>
149
- <td>
150
- <pre class="code"><span class="info file"># File 'lib/pose.rb', line 159</span>
151
-
152
- <span class='def def kw'>def</span> <span class='posify identifier id'>posify</span>
153
- <span class='include identifier id'>include</span> <span class='Pose constant id'>Pose</span>
154
- <span class='end end kw'>end</span>
155
- </pre>
156
- </td>
157
- </tr>
158
- </table>
159
- </div>
160
-
161
- </div>
162
-
163
- </div>
164
-
165
- <div id="footer">
166
- Generated on Wed Nov 16 11:48:27 2011 by
167
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
168
- 0.7.3 (ruby-1.8.7).
169
- </div>
170
-
171
- </body>
172
- </html>
@@ -1,56 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
-
4
- module Pose
5
- module Generators
6
-
7
- class InstallGenerator < Rails::Generators::Base
8
- include Rails::Generators::Migration
9
- source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
10
-
11
- def create_migration_file
12
- say ''
13
- say ' Creating database migration for the Pose tables.'
14
- say ''
15
- migration_template 'install_migration.rb', 'db/migrate/install_pose.rb'
16
- say ''
17
- end
18
-
19
- def installation_instructions
20
- say ''
21
- say ' All done! You need to do two things now:'
22
- say ''
23
- say ' 1. Run the database migration'
24
- say ''
25
- say ' rake db:migrate', Thor::Shell::Color::BOLD
26
- say ''
27
- say ''
28
- say ' 2. Add a posify block to all your models.'
29
- say ' Here is an example:'
30
- say ''
31
- say ' class MyClass < ActiveRecord::Base'
32
- say ' ...'
33
- say ''
34
- say ' posify do', Thor::Shell::Color::BOLD
35
- say ' # return searchable text as a string here', Thor::Shell::Color::BOLD
36
- say ' end', Thor::Shell::Color::BOLD
37
- say ''
38
- say ' ...'
39
- say ' end'
40
- say ''
41
- say ''
42
- say ' Happy searching! :)'
43
- say ''
44
- end
45
-
46
-
47
- private
48
-
49
- # Helper method for creating the migration.
50
- def self.next_migration_number(path)
51
- Time.now.utc.strftime("%Y%m%d%H%M%S")
52
- end
53
- end
54
-
55
- end
56
- end
@@ -1,24 +0,0 @@
1
- class InstallPose < ActiveRecord::Migration
2
-
3
- def self.up
4
- create_table "pose_assignments" do |t|
5
- t.integer "pose_word_id", null: false
6
- t.integer "posable_id", null: false
7
- t.string "posable_type", limit: 40, null: false
8
- end
9
-
10
- add_index "pose_assignments", :pose_word_id
11
- add_index "pose_assignments", :posable_id
12
-
13
- create_table "pose_words" do |t|
14
- t.string "text", limit: 80, null: false
15
- end
16
-
17
- add_index "pose_words", :text
18
- end
19
-
20
- def self.down
21
- drop_table 'pose_assignments'
22
- drop_table 'pose_words'
23
- end
24
- end
@@ -1,31 +0,0 @@
1
- # Assigns searchable objects to words in the search index.
2
- class PoseAssignment < ActiveRecord::Base
3
- belongs_to :pose_word
4
- belongs_to :posable, polymorphic: true
5
- attr_accessible :pose_word, :posable
6
-
7
- # Removes all PoseAssignments for the given class.
8
- def self.delete_class_index clazz
9
- PoseAssignment.delete_all(['posable_type=?', clazz.name])
10
- end
11
-
12
- # Removes all PoseAssignments that aren't used anymore.
13
- def self.cleanup_orphaned_pose_assignments progress_bar = nil
14
- PoseAssignment.find_each(include: [:posable, :pose_word], batch_size: 5000) do |assignment|
15
- progress_bar.increment if progress_bar
16
-
17
- # Delete the assignment if the posable object no longer exists.
18
- if assignment.posable.nil?
19
- puts "deleting assignment '#{assignment.id}' because the posable object no longer exists."
20
- assignment.delete
21
- next
22
- end
23
-
24
- # Delete the assignment if the PoseWord for it no longer exists.
25
- if assignment.pose_word.nil?
26
- puts "deleting assignment '#{assignment.id}' because its word no longer exists."
27
- assignment.delete
28
- end
29
- end
30
- end
31
- end
@@ -1,28 +0,0 @@
1
- # A single word in the search index.
2
- class PoseWord < ActiveRecord::Base
3
- has_many :pose_assignments
4
-
5
- attr_accessible :text
6
-
7
- def self.remove_unused_words progress_bar = nil
8
- if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
9
- # Will generate something like:
10
- #
11
- # DELETE FROM "pose_words" WHERE "pose_words"."id" IN
12
- # (SELECT "pose_words"."id" FROM "pose_words" INNER JOIN "pose_assignments" ON "pose_assignments"."pose_word_id" = "pose_words"."id"
13
- # HAVING.... GROUP BY "pose_words"."id")
14
- PoseWord.delete_all(id: PoseWord.select("pose_words.id").
15
- joins("LEFT OUTER JOIN pose_assignments ON pose_assignments.pose_word_id = pose_words.id").
16
- group("pose_words.id").
17
- having("COUNT(pose_assignments.id) = 0"))
18
- else
19
- # NOTE (SZ): do not use find_each uses batch_size == 100.
20
- # Use find_in_batches instead.
21
- #
22
- PoseWord.select(:id).find_in_batches.each(include: [:pose_assignments], batch_size: 5000) do |pose_word|
23
- pose_word.delete if pose_word.pose_assignments.size == 0
24
- progress_bar.increment if progress_bar
25
- end
26
- end
27
- end
28
- end
data/spec/factories.rb DELETED
@@ -1,15 +0,0 @@
1
- FactoryGirl.define do
2
-
3
- factory :pose_word do
4
- text { Faker::Lorem.words(1).first }
5
- end
6
-
7
- factory :pose_assignment do
8
- pose_word
9
- posable factory: :posable_one
10
- end
11
-
12
- factory :posable_one do
13
- text { Faker::Lorem.words(3).join ' ' }
14
- end
15
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PoseAssignment do
4
-
5
- describe "delete_class_index" do
6
-
7
- before :each do
8
- FactoryGirl.create :pose_assignment, posable_id: 1, posable_type: 'PosableOne'
9
- FactoryGirl.create :pose_assignment, posable_id: 2, posable_type: 'PosableTwo'
10
- PoseAssignment.delete_class_index PosableOne
11
- end
12
-
13
- it "deletes all PoseAssignments for the given class" do
14
- PoseAssignment.where(posable_type: 'PosableOne').should have(0).items
15
- end
16
-
17
- it "doesn't delete PoseAssignments for other classes" do
18
- PoseAssignment.where(posable_type: 'PosableTwo').should have(1).items
19
- end
20
- end
21
-
22
-
23
- describe "cleanup_orphaned_pose_assignments" do
24
-
25
- it "deletes the assignment if the posable object doesn't exist" do
26
- FactoryGirl.create :pose_assignment, posable_id: 2, posable_type: 'PosableOne'
27
- PoseAssignment.count.should > 0
28
- PoseAssignment.cleanup_orphaned_pose_assignments
29
- PoseAssignment.count.should == 0
30
- end
31
-
32
- it "deletes the assignment if the pose_word doesn't exist" do
33
- assignment = FactoryGirl.create :pose_assignment, pose_word: nil, pose_word_id: 27
34
- PoseAssignment.cleanup_orphaned_pose_assignments
35
- PoseAssignment.find_by_id(assignment.id).should be_nil
36
- end
37
-
38
- it "doesn't delete the assignment if it is still used" do
39
- assignment = FactoryGirl.create :pose_assignment
40
- PoseAssignment.cleanup_orphaned_pose_assignments
41
- PoseAssignment.find_by_id(assignment.id).should_not be_nil
42
- end
43
- end
44
-
45
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PoseWord do
4
-
5
- describe 'class methods' do
6
- subject { PoseWord }
7
-
8
- describe '::remove_unused_words' do
9
-
10
- before :each do
11
- instantiate_objects
12
- PoseWord.remove_unused_words
13
- end
14
-
15
- context 'having unused words' do
16
- let(:instantiate_objects) { FactoryGirl.create :pose_word }
17
- its(:count) { should == 0 }
18
- end
19
-
20
- context 'having used words' do
21
- let(:instantiate_objects) { FactoryGirl.create :posable_one }
22
- its(:count) { should > 0 }
23
- end
24
- end
25
- end
26
- end