refinerycms 0.9.6.5 → 0.9.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/VERSION +1 -1
  2. data/app/controllers/application.rb +1 -1
  3. data/app/controllers/application_controller.rb +1 -1
  4. data/config/environment.rb +2 -2
  5. data/config/environments/development.rb +1 -1
  6. data/config/environments/production.rb +1 -1
  7. data/config/preinitializer.rb +1 -1
  8. data/db/migrate/20100114092849_add_themes_table.rb +12 -12
  9. data/db/migrate/20100202034802_remove_custom_title_image_id_and_image_id_from_pages.rb +6 -6
  10. data/db/schema.rb +1 -1
  11. data/db/seeds.rb +2 -2
  12. data/lib/refinery_initializer.rb +1 -1
  13. data/public/javascripts/refinery/admin.js +61 -61
  14. data/readme.md +3 -3
  15. data/test/files/The world!.gif +0 -0
  16. data/test/files/car-wallpapers19.jpg +0 -0
  17. data/test/fixtures/images.yml +14 -0
  18. data/test/test_helper.rb +1 -1
  19. data/test/unit/image_test.rb +19 -8
  20. data/test/unit/page_part_test.rb +11 -11
  21. data/test/unit/page_test.rb +125 -125
  22. data/vendor/plugins/authentication/app/controllers/users_controller.rb +20 -20
  23. data/vendor/plugins/authentication/app/models/user.rb +5 -5
  24. data/vendor/plugins/authentication/app/views/user_mailer/reset_notification.html.erb +2 -2
  25. data/vendor/plugins/authentication/app/views/users/forgot.html.erb +1 -1
  26. data/vendor/plugins/authentication/app/views/users/reset.html.erb +2 -2
  27. data/vendor/plugins/authentication/config/routes.rb +4 -4
  28. data/vendor/plugins/dashboard/app/helpers/admin/dashboard_helper.rb +1 -1
  29. data/vendor/plugins/dashboard/app/views/admin/dashboard/_recent_activity.html.erb +1 -1
  30. data/vendor/plugins/dashboard/rails/init.rb +1 -1
  31. data/vendor/plugins/images/app/models/image.rb +14 -14
  32. data/vendor/plugins/images/app/views/admin/images/_form.html.erb +1 -8
  33. data/vendor/plugins/images/app/views/admin/images/insert.html.erb +1 -1
  34. data/vendor/plugins/inquiries/app/views/admin/inquiries/_inquiry.html.erb +3 -3
  35. data/vendor/plugins/inquiries/app/views/inquiries/new.html.erb +1 -1
  36. data/vendor/plugins/inquiries/app/views/inquiries/thank_you.html.erb +1 -1
  37. data/vendor/plugins/news/app/controllers/admin/news_items_controller.rb +1 -1
  38. data/vendor/plugins/news/app/controllers/news_items_controller.rb +1 -1
  39. data/vendor/plugins/news/app/views/news_items/index.html.erb +1 -1
  40. data/vendor/plugins/news/app/views/news_items/show.html.erb +1 -1
  41. data/vendor/plugins/pages/app/controllers/admin/pages_controller.rb +1 -1
  42. data/vendor/plugins/pages/app/models/page.rb +42 -42
  43. data/vendor/plugins/pages/app/models/page_part.rb +1 -1
  44. data/vendor/plugins/pages/app/presenters/page_presenter.rb +1 -1
  45. data/vendor/plugins/pages/app/views/admin/page_dialogs/_page_link.html.erb +1 -1
  46. data/vendor/plugins/pages/app/views/admin/pages/_form.html.erb +1 -1
  47. data/vendor/plugins/pages/app/views/admin/pages/_list.html.erb +1 -1
  48. data/vendor/plugins/pages/app/views/admin/pages/_page_part_field.html.erb +1 -1
  49. data/vendor/plugins/pages/app/views/pages/home.html.erb +1 -1
  50. data/vendor/plugins/pages/app/views/pages/show.html.erb +1 -1
  51. data/vendor/plugins/pages/rails/init.rb +5 -5
  52. data/vendor/plugins/rails_indexes/lib/indexer.rb +49 -47
  53. data/vendor/plugins/rails_indexes/tasks/indexer.rake +5 -3
  54. data/vendor/plugins/rails_indexes/test/fixtures/app/controllers/users_controller.rb +3 -3
  55. data/vendor/plugins/rails_indexes/test/fixtures/app/models/address.rb +2 -2
  56. data/vendor/plugins/rails_indexes/test/fixtures/app/models/company.rb +4 -4
  57. data/vendor/plugins/rails_indexes/test/fixtures/app/models/country.rb +1 -1
  58. data/vendor/plugins/rails_indexes/test/fixtures/app/models/freelancer.rb +1 -1
  59. data/vendor/plugins/rails_indexes/test/fixtures/app/models/gift.rb +4 -4
  60. data/vendor/plugins/rails_indexes/test/fixtures/app/models/god.rb +1 -1
  61. data/vendor/plugins/rails_indexes/test/fixtures/app/models/user.rb +7 -6
  62. data/vendor/plugins/rails_indexes/test/fixtures/app/sweepers/user_sweeper.rb +1 -1
  63. data/vendor/plugins/rails_indexes/test/fixtures/schema.rb +9 -9
  64. data/vendor/plugins/rails_indexes/test/rails_indexes_test.rb +18 -18
  65. data/vendor/plugins/refinery/app/views/admin/_head.html.erb +1 -1
  66. data/vendor/plugins/refinery/app/views/layouts/application.html.erb +1 -1
  67. data/vendor/plugins/refinery/app/views/shared/_content_page.html.erb +1 -1
  68. data/vendor/plugins/refinery/app/views/shared/_head.html.erb +1 -1
  69. data/vendor/plugins/refinery/app/views/shared/_header.html.erb +1 -1
  70. data/vendor/plugins/refinery/app/views/shared/_menu.html.erb +1 -1
  71. data/vendor/plugins/refinery/app/views/shared/_menu_branch.html.erb +5 -5
  72. data/vendor/plugins/refinery/app/views/shared/_submenu.html.erb +1 -1
  73. data/vendor/plugins/refinery/app/views/shared/admin/_continue_editing.html.erb +1 -1
  74. data/vendor/plugins/refinery/app/views/shared/admin/_error_messages_for.html.erb +1 -1
  75. data/vendor/plugins/refinery/app/views/shared/admin/_form_actions.html.erb +1 -1
  76. data/vendor/plugins/refinery/app/views/shared/admin/_image_picker.html.erb +27 -13
  77. data/vendor/plugins/refinery/app/views/shared/admin/_resource_picker.html.erb +1 -1
  78. data/vendor/plugins/refinery/app/views/shared/admin/_search.html.erb +1 -1
  79. data/vendor/plugins/refinery/app/views/shared/admin/_sortable_list.html.erb +1 -1
  80. data/vendor/plugins/refinery/lib/generators/refinery/templates/model.rb +1 -1
  81. data/vendor/plugins/refinery/lib/generators/refinery/templates/public_controller.rb +1 -1
  82. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_sortable_list.html.erb +1 -1
  83. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/index.html.erb +2 -2
  84. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/index.html.erb +1 -1
  85. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/show.html.erb +1 -1
  86. data/vendor/plugins/refinery/lib/refinery/activity.rb +1 -1
  87. data/vendor/plugins/refinery/lib/refinery/application_controller.rb +4 -4
  88. data/vendor/plugins/refinery/lib/refinery/application_helper.rb +1 -1
  89. data/vendor/plugins/refinery/lib/refinery/base_presenter.rb +1 -1
  90. data/vendor/plugins/refinery/lib/refinery/initializer.rb +1 -1
  91. data/vendor/plugins/refinery_dialogs/app/controllers/admin/dialogs_controller.rb +1 -1
  92. data/vendor/plugins/resources/app/models/resource.rb +8 -8
  93. data/vendor/plugins/resources/app/views/admin/resources/_form.html.erb +1 -1
  94. data/vendor/plugins/resources/app/views/admin/resources/index.html.erb +1 -1
  95. data/vendor/plugins/resources/app/views/admin/resources/insert.html.erb +1 -1
  96. data/vendor/plugins/resources/config/routes.rb +2 -2
  97. data/vendor/plugins/resources/rails/init.rb +1 -1
  98. data/vendor/plugins/themes/app/controllers/admin/themes_controller.rb +17 -17
  99. data/vendor/plugins/themes/app/models/theme.rb +40 -40
  100. data/vendor/plugins/themes/app/views/admin/themes/_form.html.erb +1 -1
  101. data/vendor/plugins/themes/config/routes.rb +2 -2
  102. data/vendor/plugins/themes/lib/theme_server.rb +26 -0
  103. data/vendor/plugins/themes/rails/init.rb +3 -1
  104. metadata +6 -3
  105. data/vendor/plugins/themes/app/controllers/themes_controller.rb +0 -45
@@ -28,11 +28,4 @@
28
28
  <label>Current Image</label>
29
29
  <%= image_fu @image, :medium, { :class => "brown_border" } %>
30
30
  </div>
31
- <% end %>
32
- <% content_for :head do %>
33
- <script type='text/javascript'>
34
- $(document).ready(function(){
35
- image_dialog.init();
36
- });
37
- </script>
38
- <% end if from_dialog? %>
31
+ <% end %>
@@ -44,7 +44,7 @@
44
44
  <% content_for :head do %>
45
45
  <script type='text/javascript'>
46
46
  $(document).ready(function(){
47
- image_dialog.init();
47
+ image_dialog.init(<%= @callback.present? ? "self.parent.#{@callback}" : "null" %>);
48
48
  });
49
49
  </script>
50
50
  <% end %>
@@ -1,11 +1,11 @@
1
1
  <li class='clearfix record <%= cycle("on", "on-hover") %>'>
2
2
  <span class='title'>
3
3
  <span class='actions'>
4
- <%= link_to refinery_icon_tag("#{inquiry.open? ? 'accept' : 'arrow_up'}.png"), {:action => "toggle_status", :id => inquiry.id},
4
+ <%= link_to refinery_icon_tag("#{inquiry.open? ? 'accept' : 'arrow_up'}.png"), {:action => "toggle_status", :id => inquiry.id},
5
5
  {:title => "Move this inquiry to #{inquiry.open? ? 'closed' : 'open'}"} %>
6
- <%= link_to refinery_icon_tag('email_open.png'), {:action => 'show', :id => inquiry.id},
6
+ <%= link_to refinery_icon_tag('email_open.png'), {:action => 'show', :id => inquiry.id},
7
7
  {:title => "Read this inquiry"} -%>
8
- <%= link_to refinery_icon_tag('delete.png'), admin_inquiry_url(inquiry), :class => "cancel confirm-delete",
8
+ <%= link_to refinery_icon_tag('delete.png'), admin_inquiry_url(inquiry), :class => "cancel confirm-delete",
9
9
  :title => "Remove this inquiry forever" -%>
10
10
  </span>
11
11
  <%=h inquiry.name %>
@@ -28,4 +28,4 @@
28
28
  <% end %>
29
29
  </div>
30
30
  <% end %>
31
- <%= render :partial => "/shared/content_page" %>
31
+ <%= render :partial => "/shared/content_page" %>
@@ -1 +1 @@
1
- <%= render :partial => "/shared/content_page" %>
1
+ <%= render :partial => "/shared/content_page" %>
@@ -2,4 +2,4 @@ class Admin::NewsItemsController < Admin::BaseController
2
2
 
3
3
  crudify :news_item, :order => "created_at DESC"
4
4
 
5
- end
5
+ end
@@ -17,4 +17,4 @@ protected
17
17
  @page = Page.find_by_link_url("/news", :include => [:parts, :slugs])
18
18
  end
19
19
 
20
- end
20
+ end
@@ -14,4 +14,4 @@
14
14
  <% end %>
15
15
  <% end %>
16
16
 
17
- <%= render :partial => "/shared/content_page" %>
17
+ <%= render :partial => "/shared/content_page" %>
@@ -10,4 +10,4 @@
10
10
  <% end %>
11
11
  <% content_for :body_content_right, render(:partial => 'recent_posts') %>
12
12
 
13
- <%= render :partial => "/shared/content_page" %>
13
+ <%= render :partial => "/shared/content_page" %>
@@ -15,4 +15,4 @@ protected
15
15
  expire_fragment(%r{site_menu})
16
16
  end
17
17
 
18
- end
18
+ end
@@ -4,26 +4,26 @@ class Page < ActiveRecord::Base
4
4
 
5
5
  acts_as_tree :order => "position ASC", :include => [:children, :slugs]
6
6
 
7
- # Docs for friendly_id http://github.com/norman/friendly_id
7
+ # Docs for friendly_id http://github.com/norman/friendly_id
8
8
  has_friendly_id :title, :use_slug => true
9
9
 
10
10
  has_many :parts, :class_name => "PagePart", :order => "position ASC"
11
11
  accepts_nested_attributes_for :parts, :allow_destroy => true
12
12
 
13
- # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
13
+ # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
14
14
  acts_as_indexed :fields => [:title, :meta_keywords, :meta_description, :custom_title, :browser_title, :all_page_part_content],
15
- :index_file => [Rails.root.to_s, "tmp", "index"]
15
+ :index_file => [Rails.root.to_s, "tmp", "index"]
16
16
 
17
17
  before_destroy :deletable?
18
18
 
19
- # when a dialog pops up to link to a page, how many pages per page should there be
20
- PAGES_PER_DIALOG = 14
19
+ # when a dialog pops up to link to a page, how many pages per page should there be
20
+ PAGES_PER_DIALOG = 14
21
21
 
22
- # when listing pages out in the admin area, how many pages should show per page
23
- PAGES_PER_ADMIN_INDEX = 20
22
+ # when listing pages out in the admin area, how many pages should show per page
23
+ PAGES_PER_ADMIN_INDEX = 20
24
24
 
25
- # when collecting the pages path how is each of the pages seperated?
26
- PATH_SEPERATOR = " - "
25
+ # when collecting the pages path how is each of the pages seperated?
26
+ PATH_SEPERATOR = " - "
27
27
 
28
28
  # Am I allowed to delete this page?
29
29
  # If a link_url is set we don't want to break the link so we don't allow them to delete
@@ -38,13 +38,13 @@ class Page < ActiveRecord::Base
38
38
  if self.deletable?
39
39
  super
40
40
  else
41
- unless RAILS_ENV == "test"
42
- # give useful feedback when trying to delete from console
43
- puts "This page is not deletable. Please use .destroy! if you really want it deleted "
44
- puts "unset .link_url," if self.link_url.present?
45
- puts "unset .menu_match," if self.menu_match.present?
46
- puts "set .deletable to true" unless self.deletable
47
- end
41
+ unless RAILS_ENV == "test"
42
+ # give useful feedback when trying to delete from console
43
+ puts "This page is not deletable. Please use .destroy! if you really want it deleted "
44
+ puts "unset .link_url," if self.link_url.present?
45
+ puts "unset .menu_match," if self.menu_match.present?
46
+ puts "set .deletable to true" unless self.deletable
47
+ end
48
48
 
49
49
  return false
50
50
  end
@@ -76,13 +76,13 @@ class Page < ActiveRecord::Base
76
76
  end
77
77
  end
78
78
 
79
- # When this page is rendered in the navigation, where should it link?
80
- # If a custom "link_url" is set, it uses that otherwise it defaults to a normal page URL.
81
- # The "link_url" is often used to link to a plugin rather than a page.
82
- #
83
- # For example if I had a "Contact Us" page I don't want it to just render a contact us page
84
- # I want it to show the Inquiries form so I can collect inquiries. So I would set the "link_url"
85
- # to "/inquiries/new"
79
+ # When this page is rendered in the navigation, where should it link?
80
+ # If a custom "link_url" is set, it uses that otherwise it defaults to a normal page URL.
81
+ # The "link_url" is often used to link to a plugin rather than a page.
82
+ #
83
+ # For example if I had a "Contact Us" page I don't want it to just render a contact us page
84
+ # I want it to show the Inquiries form so I can collect inquiries. So I would set the "link_url"
85
+ # to "/inquiries/new"
86
86
  def url
87
87
  if self.link_url.present?
88
88
  self.link_url
@@ -91,29 +91,29 @@ class Page < ActiveRecord::Base
91
91
  end
92
92
  end
93
93
 
94
- # Returns true if this page is "published"
94
+ # Returns true if this page is "published"
95
95
  def live?
96
96
  not self.draft?
97
97
  end
98
98
 
99
- # Return true if this page can be shown in the navigation.
100
- # If it's a draft or is set to not show in the menu it will return false.
101
- # If any of the page's ancestors aren't to be shown in the menu then this page is not either.
99
+ # Return true if this page can be shown in the navigation.
100
+ # If it's a draft or is set to not show in the menu it will return false.
101
+ # If any of the page's ancestors aren't to be shown in the menu then this page is not either.
102
102
  def in_menu?
103
103
  self.live? && self.show_in_menu? && !self.ancestors.any? { |a| !a.in_menu? }
104
104
  end
105
105
 
106
- # Returns true if this page is the home page or links to it.
106
+ # Returns true if this page is the home page or links to it.
107
107
  def home?
108
108
  self.link_url == "/"
109
109
  end
110
110
 
111
- # Returns all visible sibling pages that can be rendered for the menu
111
+ # Returns all visible sibling pages that can be rendered for the menu
112
112
  def shown_siblings
113
113
  self.siblings.reject { |sibling| not sibling.in_menu? }
114
114
  end
115
115
 
116
- # Returns all the top level pages, usually to render the top level navigation.
116
+ # Returns all the top level pages, usually to render the top level navigation.
117
117
  def self.top_level(include_children = false)
118
118
  include_associations = [:parts]
119
119
  include_associations.push(:slugs) if self.class.methods.include? "find_one_with_friendly"
@@ -121,12 +121,12 @@ class Page < ActiveRecord::Base
121
121
  find_all_by_parent_id(nil,:conditions => {:show_in_menu => true, :draft => false}, :order => "position ASC", :include => include_associations)
122
122
  end
123
123
 
124
- # Accessor method to get a page part from a page.
125
- # Example:
126
- #
127
- # Page.first[:body]
128
- #
129
- # Will return the body page part of the first page.
124
+ # Accessor method to get a page part from a page.
125
+ # Example:
126
+ #
127
+ # Page.first[:body]
128
+ #
129
+ # Will return the body page part of the first page.
130
130
  def [](part_title)
131
131
  # don't want to override a super method when trying to call a page part.
132
132
  # the way that we call page parts seems flawed, will probably revert to page.parts[:title] in a future release.
@@ -140,13 +140,13 @@ class Page < ActiveRecord::Base
140
140
  super_value
141
141
  end
142
142
 
143
- # In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
143
+ # In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
144
144
  def title_with_meta
145
- title = self.title
146
- title << " <em>(hidden)</em>" unless self.show_in_menu?
147
- title << " <em>(draft)</em>" if self.draft?
145
+ title = self.title
146
+ title << " <em>(hidden)</em>" unless self.show_in_menu?
147
+ title << " <em>(draft)</em>" if self.draft?
148
148
 
149
- title.strip
149
+ title.strip
150
150
  end
151
151
 
152
152
  # Used to index all the content on this page so it can be easily searched.
@@ -154,7 +154,7 @@ class Page < ActiveRecord::Base
154
154
  self.parts.collect {|p| p.body}.join(" ")
155
155
  end
156
156
 
157
- # Returns how many pages per page should there be when paginating pages
157
+ # Returns how many pages per page should there be when paginating pages
158
158
  def self.per_page(dialog = false)
159
159
  dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
160
160
  end
@@ -7,4 +7,4 @@ class PagePart < ActiveRecord::Base
7
7
 
8
8
  has_friendly_id :title, :use_slug => true
9
9
 
10
- end
10
+ end
@@ -1,3 +1,3 @@
1
1
  class PagePresenter < Refinery::BasePresenter
2
2
  #delegate DEFAULT_FIELDS.keys :to => :model
3
- end
3
+ end
@@ -2,4 +2,4 @@
2
2
  <li class='clearfix<%= " child#{child}" if child %><%= " linked" if linked%>' id="<%= dom_id(page_link) -%>">
3
3
  <%= link_to page_link.title_with_meta, page_link.url, :title => 'Link to this Page', :rel => page_link.title, :class => 'page_link' %>
4
4
  </li>
5
- <%= render :partial => 'page_link', :collection => page_link.children, :locals => {:child => child ? (child+1) : 1} unless page_link.children.empty? %>
5
+ <%= render :partial => 'page_link', :collection => page_link.children, :locals => {:child => child ? (child+1) : 1} unless page_link.children.empty? %>
@@ -137,4 +137,4 @@
137
137
  page_options.init(page_parts, new_part_url, del_part_url);
138
138
  });
139
139
  </script>
140
- <% end %>
140
+ <% end %>
@@ -26,4 +26,4 @@
26
26
  <% end %>
27
27
  </ul>
28
28
  <% end %>
29
- </li>
29
+ </li>
@@ -1,4 +1,4 @@
1
1
  <div class='page_part field' id='<%= new_part ? "page_part_new_#{part_index}" : dom_id(part) %>'>
2
2
  <%= hidden_field_tag "page[parts_attributes][#{part_index}][title]", part.title if new_part %>
3
3
  <%= text_area_tag "page[parts_attributes][#{part_index}][body]", part.body, :rows => 20, :cols => 140, :class => 'wymeditor' %>
4
- </div>
4
+ </div>
@@ -1 +1 @@
1
- <%= render :partial => "/shared/content_page", :locals => {:show_submenu => false} %>
1
+ <%= render :partial => "/shared/content_page", :locals => {:show_submenu => false} %>
@@ -1 +1 @@
1
- <%= render :partial => "/shared/content_page" %>
1
+ <%= render :partial => "/shared/content_page" %>
@@ -4,10 +4,10 @@ Refinery::Plugin.register do |plugin|
4
4
  plugin.version = 1.0
5
5
  plugin.menu_match = /admin\/((pages)|(page_dialogs)|(page_parts))$/
6
6
  plugin.activity = {
7
- :class => Page,
8
- :url_prefix => "edit",
9
- :title => "title",
10
- :created_image => "page_add.png",
7
+ :class => Page,
8
+ :url_prefix => "edit",
9
+ :title => "title",
10
+ :created_image => "page_add.png",
11
11
  :updated_image => "page_edit.png"
12
12
  }
13
- end
13
+ end
@@ -113,49 +113,8 @@ module Indexer
113
113
  @indexes_required[table_name] += [primary_key] unless @indexes_required[table_name].include?(primary_key)
114
114
  end
115
115
 
116
- find_regexp = Regexp.new(/([A-Z]{1}[A-Za-z]+|self).(find){1}((_all){0,1}(_by_){0,1}([A-Za-z_]+))?\(([0-9A-Za-z"\':=>. \[\]{},]*)\)/)
117
- if matches = find_regexp.match(line)
116
+ check_line_for_find_indexes(file_name, line)
118
117
 
119
- model_name, column_names, options = matches[1], matches[6], matches[7]
120
-
121
- if model_name == "self"
122
- model_name = File.basename(file_name).sub(/\.rb$/,'').camelize
123
- table_name = model_name.constantize.table_name
124
- else
125
- if model_name.respond_to?(:constantize)
126
- if model_name.constantize.respond_to?(:table_name)
127
- table_name = model_name.constantize.table_name
128
- else
129
- #puts "Unable to get the table_name for #{model_name.to_s}. it could be an ActiveResource"
130
- next
131
- end
132
- else
133
- #puts "Unable to constantize #{model_name.to_s}, if you are sure that #{model_name.to_s} is a valid class name, please file an issue on\nhttp://github.com/eladmeidar/rails_indexes\nPlease supply the relevant code as well, thanks. =)"
134
- next
135
- end
136
- end
137
-
138
- primary_key = model_name.constantize.primary_key
139
- @indexes_required[table_name] += [primary_key] unless @indexes_required[table_name].include?(primary_key)
140
-
141
- if column_names.present?
142
- column_names = column_names.split('_and_')
143
-
144
- # remove find_by_sql references.
145
- column_names.delete("sql")
146
-
147
- column_names = model_name.constantize.column_names & column_names
148
-
149
- # Check if there were more than 1 column
150
- if column_names.size == 1
151
- column_name = column_names.first
152
- @indexes_required[table_name] += [column_name] unless @indexes_required[table_name].include?(column_name)
153
- else
154
- @indexes_required[table_name] += [column_names] unless @indexes_required[table_name].include?(column_names)
155
- @indexes_required[table_name] += [column_names.reverse] unless @indexes_required[table_name].include?(column_names.reverse)
156
- end
157
- end
158
- end
159
118
  end
160
119
  end
161
120
 
@@ -180,6 +139,53 @@ module Indexer
180
139
  @indexes_required
181
140
  end
182
141
 
142
+
143
+ def self.check_line_for_find_indexes(file_name, line)
144
+ find_regexp = Regexp.new(/([A-Z]{1}[A-Za-z]+|self).(find){1}((_all){0,1}(_by_){0,1}([A-Za-z_]+))?\(([0-9A-Za-z"\':=>. \[\]{},]*)\)/)
145
+ if matches = find_regexp.match(line)
146
+
147
+ model_name, column_names, options = matches[1], matches[6], matches[7]
148
+
149
+ if model_name == "self"
150
+ model_name = File.basename(file_name).sub(/\.rb$/,'').camelize
151
+ table_name = model_name.constantize.table_name
152
+ else
153
+ if model_name.respond_to?(:constantize)
154
+ if model_name.constantize.respond_to?(:table_name)
155
+ table_name = model_name.constantize.table_name
156
+ else
157
+ #puts "Unable to get the table_name for #{model_name.to_s}. it could be an ActiveResource"
158
+ next
159
+ end
160
+ else
161
+ #puts "Unable to constantize #{model_name.to_s}, if you are sure that #{model_name.to_s} is a valid class name, please file an issue on\nhttp://github.com/eladmeidar/rails_indexes\nPlease supply the relevant code as well, thanks. =)"
162
+ next
163
+ end
164
+ end
165
+
166
+ primary_key = model_name.constantize.primary_key
167
+ @indexes_required[table_name] += [primary_key] unless @indexes_required[table_name].include?(primary_key)
168
+
169
+ if column_names.present?
170
+ column_names = column_names.split('_and_')
171
+
172
+ # remove find_by_sql references.
173
+ column_names.delete("sql")
174
+
175
+ column_names = model_name.constantize.column_names & column_names
176
+
177
+ # Check if there were more than 1 column
178
+ if column_names.size == 1
179
+ column_name = column_names.first
180
+ @indexes_required[table_name] += [column_name] unless @indexes_required[table_name].include?(column_name)
181
+ else
182
+ @indexes_required[table_name] += [column_names] unless @indexes_required[table_name].include?(column_names)
183
+ @indexes_required[table_name] += [column_names.reverse] unless @indexes_required[table_name].include?(column_names.reverse)
184
+ end
185
+ end
186
+ end
187
+ end
188
+
183
189
  def self.key_exists?(table,key_columns)
184
190
  result = (key_columns.to_a - ActiveRecord::Base.connection.indexes(table).map { |i| i.columns }.flatten)
185
191
  result.empty?
@@ -234,8 +240,6 @@ EOM
234
240
 
235
241
  puts "## Drop this into a file in db/migrate ##"
236
242
  puts migration
237
- else
238
- puts "Didn't find any models requiring indexing in your app/models directory."
239
243
  end
240
244
  end
241
245
 
@@ -293,11 +297,9 @@ EOM
293
297
 
294
298
  puts "## Drop this into a file in db/migrate ##"
295
299
  puts migration
296
- else
297
- puts "Didn't find any models requiring indexing in your app/models directory."
298
300
  end
299
301
  end
300
302
  else
301
303
  find_indexes
302
304
  end
303
- end
305
+ end
@@ -1,16 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), "../lib/indexer.rb")
2
+
1
3
  namespace :db do
2
4
  desc "collect indexes based on AR::Base.find calls."
3
5
  task :show_me_ar_find_indexes => :environment do
4
6
  Indexer.ar_find_indexes
5
7
  end
6
-
8
+
7
9
  desc "scan for possible required indexes"
8
10
  task :show_me_some_indexes => :environment do
9
11
  # Indexer.indexes_list
10
12
  puts "Sorry, simple report is deprecated.\nuse rake db:show_me_a_migration or db:show_me_ar_find_indexes instead"
11
13
  end
12
-
14
+
13
15
  task :show_me_a_migration => :environment do
14
16
  Indexer.simple_migration
15
17
  end
16
- end
18
+ end