refinerycms 0.9.5.20 → 0.9.5.21

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,6 +9,11 @@ require 'rake/rdoctask'
9
9
 
10
10
  require 'tasks/rails'
11
11
 
12
+ unless REFINERY_ROOT == RAILS_ROOT
13
+ # Load any custom rakefile extensions (for the gem only)
14
+ Dir[File.join(REFINERY_ROOT, %w(vendor plugins * ** tasks ** *.rake))].sort.each { |ext| load ext }
15
+ end
16
+
12
17
  desc 'Removes trailing whitespace'
13
18
  task :whitespace do
14
19
  sh %{find . -name '*.*rb' -exec sed -i '' 's/\t/ /g' {} \\; -exec sed -i '' 's/ *$//g' {} \\; }
@@ -23,7 +28,7 @@ begin
23
28
  s.email = %q{info@refinerycms.com}
24
29
  s.homepage = %q{http://refinerycms.com}
25
30
  s.authors = ["Resolve Digital", "David Jones", "Philip Arndt"]
26
- s.extra_rdoc_files = %w(README CONTRIBUTORS LICENSE)
31
+ s.extra_rdoc_files = %w(README CONTRIBUTORS LICENSE VERSION)
27
32
  end
28
33
 
29
34
  namespace :version do
@@ -37,6 +42,6 @@ begin
37
42
  end
38
43
  end
39
44
  end
40
- rescue LoadError
45
+ rescue LoadError
41
46
  puts "Jeweler not available. Install it with: sudo gem install jeweler"
42
47
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.5.20
1
+ 0.9.5.21
@@ -4,7 +4,7 @@ REFINERY_ROOT = File.expand_path(File.dirname(__FILE__) << "/..")
4
4
  RAILS_ROOT = ARGV.first unless defined? RAILS_ROOT
5
5
  unless RAILS_ROOT.nil? or RAILS_ROOT.length == 0
6
6
  # ensure asset directories exist.
7
- dirs = [%w(public stylesheets), %w(public javascripts), %w(db migrate), %w(lib tasks)]
7
+ dirs = [%w(public stylesheets), %w(public javascripts), %w(db migrate)]
8
8
  FileUtils::makedirs dirs.map {|dir| File.join(RAILS_ROOT, dir) }
9
9
 
10
10
  # copy in the new assets.
@@ -17,9 +17,6 @@ unless RAILS_ROOT.nil? or RAILS_ROOT.length == 0
17
17
  # copy in any new migrations.
18
18
  FileUtils::cp Dir[File.join(REFINERY_ROOT, %w(db migrate *.rb))], File.join(RAILS_ROOT, %w(db migrate))
19
19
 
20
- # copy any rake tasks from plugins to the main lib directory so they can be run.
21
- FileUtils::cp Dir[File.join(REFINERY_ROOT, %w(** tasks *.rake))], File.join(RAILS_ROOT, %w(lib tasks))
22
-
23
20
  # read in the config files
24
21
  app_config = File.open(File.join(RAILS_ROOT, %w(config environment.rb)), "r").read
25
22
  environment_updated = false
@@ -49,7 +49,7 @@ class User < ActiveRecord::Base
49
49
  validates_uniqueness_of :login, :email, :case_sensitive => false
50
50
  before_save :encrypt_password
51
51
 
52
- serialize :plugins_column#, Array
52
+ serialize :plugins_column#, Array # this is seriously deprecated and will be removed later.
53
53
 
54
54
  has_many :plugins, :class_name => "UserPlugin", :order => "position ASC"
55
55
 
@@ -78,11 +78,11 @@ class User < ActiveRecord::Base
78
78
  end
79
79
 
80
80
  def plugins=(plugin_titles)
81
- self.plugins.delete_all
81
+ unless self.new_record? # don't add plugins when the user_id is NULL.
82
+ self.plugins.delete_all
82
83
 
83
- plugin_titles.each do |plugin_title|
84
- if plugin_title.is_a?(String)
85
- self.plugins.find_or_create_by_title(plugin_title)
84
+ plugin_titles.each do |plugin_title|
85
+ self.plugins.find_or_create_by_title(plugin_title) if plugin_title.is_a?(String)
86
86
  end
87
87
  end
88
88
  end
@@ -2,26 +2,30 @@ class PagesController < ApplicationController
2
2
 
3
3
  def home
4
4
  @page = Page.find_by_link_url("/", :include => [:parts, :slugs])
5
- error_404 if @page.nil?
6
-
7
- respond_to do |wants|
8
- wants.html
5
+ if @page.nil?
6
+ error_404
7
+ else
8
+ respond_to do |wants|
9
+ wants.html
10
+ end
9
11
  end
10
12
  end
11
13
 
12
14
  def show
13
15
  @page = Page.find(params[:id], :include => [:parts, :slugs])
14
16
 
15
- error_404 unless @page.live? or (logged_in? and current_user.authorized_plugins.include?("Pages"))
16
-
17
- # if the admin wants this to be a "placeholder" page which goes to its first child, go to that instead.
18
- if @page.skip_to_first_child
19
- first_live_child = @page.children.find_by_draft(false, :order => "position ASC")
20
- redirect_to first_live_child.url unless first_live_child.nil?
21
- else
22
- respond_to do |wants|
23
- wants.html
17
+ if @page.live? or (logged_in? and current_user.authorized_plugins.include?("Pages"))
18
+ # if the admin wants this to be a "placeholder" page which goes to its first child, go to that instead.
19
+ if @page.skip_to_first_child
20
+ first_live_child = @page.children.find_by_draft(false, :order => "position ASC")
21
+ redirect_to first_live_child.url unless first_live_child.nil?
22
+ else
23
+ respond_to do |wants|
24
+ wants.html
25
+ end
24
26
  end
27
+ else
28
+ error_404
25
29
  end
26
30
  end
27
31
 
@@ -1,14 +1,14 @@
1
1
  module Indexer
2
-
2
+
3
3
  def self.sortalize(array)
4
4
  Marshal.load(Marshal.dump(array)).each do |element|
5
5
  element.sort! if element.is_a?(Array)
6
6
  end
7
7
  end
8
-
8
+
9
9
  def self.check_for_indexes(migration_format = false)
10
10
  model_names = []
11
- Dir.chdir(Rails.root) do
11
+ Dir.chdir(Rails.root) do
12
12
  model_names = Dir["**/app/models/**/*.rb"].collect {|filename| File.basename(filename) }.uniq
13
13
  end
14
14
 
@@ -24,14 +24,14 @@ module Indexer
24
24
  # No-op
25
25
  end
26
26
  end
27
-
27
+
28
28
  @index_migrations = Hash.new([])
29
29
 
30
30
  model_classes.each do |class_name|
31
31
 
32
- # check if this is an STI child instance
32
+ # check if this is an STI child instance
33
33
  if class_name.base_class.name != class_name.name && (class_name.column_names.include?(class_name.base_class.inheritance_column) || class_name.column_names.include?(class_name.inheritance_column))
34
-
34
+
35
35
  # add the inharitance column on the parent table
36
36
  # index migration for STI should require both the primary key and the inheritance_column in a composite index.
37
37
  @index_migrations[class_name.base_class.table_name] += [[class_name.inheritance_column, class_name.base_class.primary_key].sort] unless @index_migrations[class_name.base_class.table_name].include?([class_name.base_class.inheritance_column].sort)
@@ -42,11 +42,11 @@ module Indexer
42
42
  case reflection_options.macro
43
43
  when :belongs_to
44
44
  # polymorphic?
45
- @table_name = class_name.table_name.to_s
45
+ @table_name = class_name.table_name.to_s
46
46
  if reflection_options.options.has_key?(:polymorphic) && (reflection_options.options[:polymorphic] == true)
47
47
  poly_type = "#{reflection_options.name.to_s}_type"
48
48
  poly_id = "#{reflection_options.name.to_s}_id"
49
-
49
+
50
50
  @index_migrations[@table_name.to_s] += [[poly_type, poly_id].sort] unless @index_migrations[@table_name.to_s].include?([poly_type, poly_id].sort)
51
51
  else
52
52
 
@@ -57,9 +57,9 @@ module Indexer
57
57
  table_name = reflection_options.options[:join_table] ||= [class_name.table_name, reflection_name.to_s].sort.join('_')
58
58
  association_foreign_key = reflection_options.options[:association_foreign_key] ||= "#{reflection_name.to_s.singularize}_id"
59
59
  foreign_key = reflection_options.options[:foreign_key] ||= "#{class_name.name.tableize.singularize}_id"
60
-
60
+
61
61
  composite_keys = [association_foreign_key, foreign_key]
62
-
62
+
63
63
  @index_migrations[table_name.to_s] += [composite_keys] unless @index_migrations[table_name].include?(composite_keys)
64
64
  @index_migrations[table_name.to_s] += [composite_keys.reverse] unless @index_migrations[table_name].include?(composite_keys.reverse)
65
65
 
@@ -70,7 +70,7 @@ module Indexer
70
70
  end
71
71
 
72
72
  @missing_indexes = {}
73
-
73
+
74
74
  @index_migrations.each do |table_name, foreign_keys|
75
75
 
76
76
  unless foreign_keys.blank?
@@ -79,32 +79,32 @@ module Indexer
79
79
  @missing_indexes[table_name] = keys_to_add unless keys_to_add.empty?
80
80
  end
81
81
  end
82
-
82
+
83
83
  @missing_indexes
84
84
  end
85
85
 
86
86
  def self.scan_finds
87
87
  file_names = []
88
-
89
- Dir.chdir(Rails.root) do
88
+
89
+ Dir.chdir(Rails.root) do
90
90
  file_names = Dir["**/app/**/*.rb"].uniq.reject {|file_with_path| file_with_path.include?('test')}
91
91
  end
92
92
 
93
93
  @indexes_required = Hash.new([])
94
- file_names.each do |file_name|
94
+ file_names.each do |file_name|
95
95
  current_file = File.open(File.join(Rails.root, file_name), 'r')
96
96
 
97
97
  current_file.each do |line|
98
-
98
+
99
99
  # by default, try to add index on primary key, based on file name
100
100
  # this will fail if the file isnot a model file
101
-
101
+
102
102
  begin
103
103
  current_model_name = File.basename(file_name).sub(/\.rb$/,'').camelize
104
104
  rescue
105
105
  # NO-OP
106
106
  end
107
-
107
+
108
108
  klass = current_model_name.split('::').inject(Object){ |klass,part| klass.const_get(part) } rescue nil
109
109
  if klass.present? && klass < ActiveRecord::Base && !klass.abstract_class?
110
110
  current_model = current_model_name.constantize
@@ -112,18 +112,18 @@ module Indexer
112
112
  table_name = current_model.table_name
113
113
  @indexes_required[table_name] += [primary_key] unless @indexes_required[table_name].include?(primary_key)
114
114
  end
115
-
115
+
116
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
117
  if matches = find_regexp.match(line)
118
118
 
119
119
  model_name, column_names, options = matches[1], matches[6], matches[7]
120
-
120
+
121
121
  if model_name == "self"
122
122
  model_name = File.basename(file_name).sub(/\.rb$/,'').camelize
123
- table_name = model_name.constantize.table_name
123
+ table_name = model_name.constantize.table_name
124
124
  else
125
125
  if model_name.respond_to?(:constantize)
126
- if model_name.constantize.respond_to?(:table_name)
126
+ if model_name.constantize.respond_to?(:table_name)
127
127
  table_name = model_name.constantize.table_name
128
128
  else
129
129
  #puts "Unable to get the table_name for #{model_name.to_s}. it could be an ActiveResource"
@@ -134,10 +134,10 @@ module Indexer
134
134
  next
135
135
  end
136
136
  end
137
-
137
+
138
138
  primary_key = model_name.constantize.primary_key
139
139
  @indexes_required[table_name] += [primary_key] unless @indexes_required[table_name].include?(primary_key)
140
-
140
+
141
141
  if column_names.present?
142
142
  column_names = column_names.split('_and_')
143
143
 
@@ -158,11 +158,11 @@ module Indexer
158
158
  end
159
159
  end
160
160
  end
161
-
161
+
162
162
  @missing_indexes = {}
163
163
  @indexes_required.each do |table_name, foreign_keys|
164
164
 
165
- unless foreign_keys.blank?
165
+ unless foreign_keys.blank?
166
166
  begin
167
167
  if ActiveRecord::Base.connection.tables.include?(table_name.to_s)
168
168
  existing_indexes = ActiveRecord::Base.connection.indexes(table_name.to_sym).collect {|index| index.columns.size > 1 ? index.columns : index.columns.first}
@@ -176,15 +176,15 @@ module Indexer
176
176
  end
177
177
  end
178
178
  end
179
-
179
+
180
180
  @indexes_required
181
181
  end
182
-
183
- def self.key_exists?(table,key_columns)
182
+
183
+ def self.key_exists?(table,key_columns)
184
184
  result = (key_columns.to_a - ActiveRecord::Base.connection.indexes(table).map { |i| i.columns }.flatten)
185
185
  result.empty?
186
186
  end
187
-
187
+
188
188
  def self.simple_migration
189
189
  migration_format = true
190
190
  missing_indexes = check_for_indexes(migration_format)
@@ -204,14 +204,14 @@ module Indexer
204
204
  add << "add_index :#{table_name}, :#{key}"
205
205
  remove << "remove_index :#{table_name}, :#{key}"
206
206
  end
207
-
207
+
208
208
  end
209
209
  end
210
-
211
- migration = <<EOM
210
+
211
+ migration = <<EOM
212
212
  class AddMissingIndexes < ActiveRecord::Migration
213
213
  def self.up
214
-
214
+
215
215
  # These indexes were found by searching for AR::Base finds on your application
216
216
  # It is strongly recommanded that you will consult a professional DBA about your infrastucture and implemntation before
217
217
  # changing your database in that matter.
@@ -222,10 +222,10 @@ class AddMissingIndexes < ActiveRecord::Migration
222
222
  # http://www.railstutor.org
223
223
  # http://guides.rubyonrails.org
224
224
 
225
-
225
+
226
226
  #{add.uniq.join("\n ")}
227
227
  end
228
-
228
+
229
229
  def self.down
230
230
  #{remove.uniq.join("\n ")}
231
231
  end
@@ -234,18 +234,20 @@ EOM
234
234
 
235
235
  puts "## Drop this into a file in db/migrate ##"
236
236
  puts migration
237
+ else
238
+ puts "Didn't find any models requiring indexing in your app/models directory."
237
239
  end
238
240
  end
239
-
241
+
240
242
  def self.indexes_list
241
243
  check_for_indexes.each do |table_name, keys_to_add|
242
244
  puts "Table '#{table_name}' => #{keys_to_add.to_sentence}"
243
245
  end
244
246
  end
245
-
247
+
246
248
  def self.ar_find_indexes(migration_mode=true)
247
249
  find_indexes = self.scan_finds
248
-
250
+
249
251
  if migration_mode
250
252
  unless find_indexes.keys.empty?
251
253
  add = []
@@ -262,14 +264,14 @@ EOM
262
264
  add << "add_index :#{table_name}, :#{key}"
263
265
  remove << "remove_index :#{table_name}, :#{key}"
264
266
  end
265
-
267
+
266
268
  end
267
269
  end
268
-
269
- migration = <<EOM
270
+
271
+ migration = <<EOM
270
272
  class AddFindsMissingIndexes < ActiveRecord::Migration
271
273
  def self.up
272
-
274
+
273
275
  # These indexes were found by searching for AR::Base finds on your application
274
276
  # It is strongly recommanded that you will consult a professional DBA about your infrastucture and implemntation before
275
277
  # changing your database in that matter.
@@ -279,7 +281,7 @@ class AddFindsMissingIndexes < ActiveRecord::Migration
279
281
  # http://www.railsmentors.org
280
282
  # http://www.railstutor.org
281
283
  # http://guides.rubyonrails.org
282
-
284
+
283
285
  #{add.uniq.join("\n ")}
284
286
  end
285
287
 
@@ -288,9 +290,11 @@ class AddFindsMissingIndexes < ActiveRecord::Migration
288
290
  end
289
291
  end
290
292
  EOM
291
-
293
+
292
294
  puts "## Drop this into a file in db/migrate ##"
293
295
  puts migration
296
+ else
297
+ puts "Didn't find any models requiring indexing in your app/models directory."
294
298
  end
295
299
  end
296
300
  else
@@ -1,18 +1,16 @@
1
- require File.join(File.dirname(__FILE__), "../lib/indexer.rb")
2
-
3
1
  namespace :db do
4
2
  desc "collect indexes based on AR::Base.find calls."
5
3
  task :show_me_ar_find_indexes => :environment do
6
4
  Indexer.ar_find_indexes
7
5
  end
8
-
6
+
9
7
  desc "scan for possible required indexes"
10
8
  task :show_me_some_indexes => :environment do
11
9
  # Indexer.indexes_list
12
10
  puts "Sorry, simple report is deprecated.\nuse rake db:show_me_a_migration or db:show_me_ar_find_indexes instead"
13
11
  end
14
-
12
+
15
13
  task :show_me_a_migration => :environment do
16
14
  Indexer.simple_migration
17
15
  end
18
- end
16
+ end
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  require 'test/unit'
4
4
 
5
- require 'activerecord'
5
+ require 'active_record'
6
6
  require 'active_record/fixtures'
7
7
  require 'active_support'
8
8
  require 'active_support/test_case'
@@ -1,6 +1,6 @@
1
1
  begin
2
2
  # Try to include the rails initializer. If this isn't in a gem, this will fail.
3
- require 'initializer'
3
+ require 'initializer' unless REFINERY_ROOT == RAILS_ROOT # A Refinery gem install's RAILS_ROOT is not the REFINERY_ROOT.
4
4
  rescue LoadError => load_error
5
5
  end
6
6
 
@@ -12,11 +12,25 @@ module Refinery
12
12
  end
13
13
  end
14
14
  end
15
+ if defined? Rails::Plugin::Loader
16
+ class GemedPluginLoader < Rails::Plugin::Loader
17
+ def add_plugin_load_paths
18
+ super
19
+ # add plugin lib paths to the $LOAD_PATH so that rake tasks etc. can be run when using a gem.
20
+ plugins.each do |plugin|
21
+ plugin.load_paths.reject { |path| path.scan(/refinerycms.+?vendor\/plugins\/.+?\/lib/).empty? }.each do |path|
22
+ $LOAD_PATH.unshift path
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
15
28
  if defined? Rails::Initializer
16
29
  class Initializer < Rails::Initializer
17
30
  def self.run(command = :process, configuration = Configuration.new)
18
31
  Rails.configuration = configuration
19
32
  configuration.reload_plugins = true if RAILS_ENV =~ /development/ and REFINERY_ROOT == RAILS_ROOT # seems to work, don't in gem.
33
+ configuration.plugin_loader = Refinery::GemedPluginLoader unless REFINERY_ROOT == RAILS_ROOT # only do this in a gem.
20
34
  super
21
35
  end
22
36
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5.20
4
+ version: 0.9.5.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Resolve Digital
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-12-04 00:00:00 +13:00
14
+ date: 2009-12-07 00:00:00 +13:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -27,6 +27,7 @@ extra_rdoc_files:
27
27
  - CONTRIBUTORS
28
28
  - LICENSE
29
29
  - README
30
+ - VERSION
30
31
  files:
31
32
  - .gems
32
33
  - .gitignore