table_renamable 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +3 -1
  3. data/Rakefile +32 -0
  4. data/lib/table_renamable.rb +6 -15
  5. data/lib/table_renamable/connection_adapters.rb +8 -2
  6. data/lib/table_renamable/connection_adapters/mysql2_adapter.rb +21 -29
  7. data/lib/table_renamable/connection_adapters/sqlite3_adapter.rb +62 -0
  8. data/lib/table_renamable/engine.rb +22 -0
  9. data/lib/table_renamable/model.rb +5 -3
  10. data/lib/table_renamable/version.rb +1 -1
  11. data/spec/dummy/README.rdoc +261 -0
  12. data/spec/dummy/Rakefile +3 -6
  13. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  14. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  15. data/spec/dummy/app/controllers/application_controller.rb +1 -8
  16. data/spec/dummy/app/helpers/application_helper.rb +0 -1
  17. data/spec/dummy/app/models/post.rb +1 -3
  18. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/spec/dummy/config.ru +4 -0
  20. data/spec/dummy/config/application.rb +65 -0
  21. data/spec/dummy/config/boot.rb +7 -111
  22. data/spec/dummy/config/database.yml +3 -3
  23. data/spec/dummy/config/environment.rb +4 -40
  24. data/spec/dummy/config/environments/development.rb +33 -13
  25. data/spec/dummy/config/environments/production.rb +59 -20
  26. data/spec/dummy/config/environments/test.rb +37 -28
  27. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -2
  28. data/spec/dummy/config/initializers/inflections.rb +6 -1
  29. data/spec/dummy/config/initializers/{cookie_verification_secret.rb → secret_token.rb} +2 -2
  30. data/spec/dummy/config/initializers/session_store.rb +3 -10
  31. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  32. data/spec/dummy/config/locales/en.yml +2 -2
  33. data/spec/dummy/config/routes.rb +2 -41
  34. data/spec/dummy/public/404.html +15 -19
  35. data/spec/dummy/public/422.html +15 -19
  36. data/spec/dummy/public/500.html +14 -19
  37. data/spec/dummy/script/rails +6 -0
  38. data/spec/spec_helper.rb +29 -3
  39. metadata +34 -76
  40. data/spec/dummy/README +0 -243
  41. data/spec/dummy/config/initializers/new_rails_defaults.rb +0 -21
  42. data/spec/dummy/db/seeds.rb +0 -7
  43. data/spec/dummy/doc/README_FOR_APP +0 -2
  44. data/spec/dummy/public/images/rails.png +0 -0
  45. data/spec/dummy/public/index.html +0 -275
  46. data/spec/dummy/public/javascripts/application.js +0 -2
  47. data/spec/dummy/public/javascripts/controls.js +0 -963
  48. data/spec/dummy/public/javascripts/dragdrop.js +0 -973
  49. data/spec/dummy/public/javascripts/effects.js +0 -1128
  50. data/spec/dummy/public/javascripts/prototype.js +0 -4320
  51. data/spec/dummy/public/robots.txt +0 -5
  52. data/spec/dummy/script/about +0 -4
  53. data/spec/dummy/script/console +0 -3
  54. data/spec/dummy/script/dbconsole +0 -3
  55. data/spec/dummy/script/destroy +0 -3
  56. data/spec/dummy/script/generate +0 -3
  57. data/spec/dummy/script/performance/benchmarker +0 -3
  58. data/spec/dummy/script/performance/profiler +0 -3
  59. data/spec/dummy/script/plugin +0 -3
  60. data/spec/dummy/script/runner +0 -3
  61. data/spec/dummy/script/server +0 -3
  62. data/spec/dummy/test/performance/browsing_test.rb +0 -9
  63. data/spec/dummy/test/test_helper.rb +0 -38
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c8337c36c33f84de862d6116b5cc96a2f2902b2
4
+ data.tar.gz: 50a742652c08e654d417a6a224c6f353eb11e92a
5
+ SHA512:
6
+ metadata.gz: 5e2d42a3bed3511653edd935beac543e9ffaef8d5cf0032a3f9a451578a7d297313a263a99e121db07bf80c13fc546c08bc80e209be93273eda43d3daa9b5df4
7
+ data.tar.gz: a999ecb89df026da144d6a6584eeca50de92d447ac43c137dd262c7d7970c90b5716c57d85caf7c18be54b282e6cbe7fbbdd5f319d6961ec1a2781605b4fb453
data/README.rdoc CHANGED
@@ -1,3 +1,5 @@
1
1
  = TableRenamable
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ {<img src="https://codeclimate.com/repos/526ae72f13d637486e058092/badges/c6fbdb72bdc4b463058d/gpa.png" />}[https://codeclimate.com/repos/526ae72f13d637486e058092/feed]
4
+
5
+ This project rocks and uses MIT-LICENSE.
data/Rakefile CHANGED
@@ -4,5 +4,37 @@ begin
4
4
  rescue LoadError
5
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
6
  end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'TableRenamable'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
7
27
 
8
28
  Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -1,20 +1,11 @@
1
- require "table_renamable/connection_adapters"
2
- require "table_renamable/deprecated_table"
3
- require "table_renamable/model"
1
+ require "table_renamable/engine"
4
2
 
5
3
  module TableRenamable
6
4
 
7
- end
8
-
9
- # hook to set up rails
10
- # set up our reload behavior for when table names change for MySQL
11
- if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
12
- ActiveRecord::ConnectionAdapters::Mysql2Adapter.send(
13
- :include,
14
- TableRenamable::ConnectionAdapters::Mysql2Adapter
15
- )
16
- else
17
- raise 'TableRenamable requires Mysql2'
18
- end
5
+ extend ActiveSupport::Autoload
19
6
 
7
+ autoload :ConnectionAdapters
8
+ autoload :DeprecatedTable
9
+ autoload :Model
20
10
 
11
+ end
@@ -1,7 +1,13 @@
1
- require 'table_renamable/connection_adapters/mysql2_adapter'
2
-
3
1
  module TableRenamable
4
2
  module ConnectionAdapters
5
3
 
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :Mysql2Adapter
7
+ autoload(
8
+ :SQLite3Adapter,
9
+ 'table_renamable/connection_adapters/sqlite3_adapter'
10
+ )
11
+
6
12
  end
7
13
  end
@@ -2,35 +2,27 @@ module TableRenamable
2
2
  module ConnectionAdapters
3
3
  module Mysql2Adapter
4
4
 
5
- def self.included(klass)
6
- klass.send(:include, InstanceMethods)
7
- klass.alias_method_chain(:execute, :table_renamable)
8
- end
9
-
10
-
11
- module InstanceMethods
12
- #
13
- # Override execute to reload database info
14
- # @param *args [Array<Mixed>] Just here so we can call super
15
- #
16
- # @return [type] [description]
17
- def execute_with_table_renamable(sql, name = nil)
18
- # set up tries so we don't keep retrying
19
- tries = 0
20
- begin
21
- tries += 1
22
- # call the actual execut behavior
23
- self.execute_without_table_renamable(sql, name)
24
- rescue ActiveRecord::StatementInvalid => e
25
- # only try once
26
- raise e if tries > 1
27
- # re-raise if it's not an error we care about
28
- raise e unless e.message =~ /Table.*doesn't exist/
29
- # otherwise we reload and retry
30
- TableRenamable::Model.reload_tables
31
- sql = TableRenamable::Model.process_sql(sql)
32
- retry
33
- end
5
+ #
6
+ # Override execute to reload database info
7
+ # @param *args [Array<Mixed>] Just here so we can call super
8
+ #
9
+ # @return [type] [description]
10
+ def execute(sql, name = nil)
11
+ # set up tries so we don't keep retrying
12
+ tries = 0
13
+ begin
14
+ tries += 1
15
+ # call the actual execut behavior
16
+ super(sql, name)
17
+ rescue ActiveRecord::StatementInvalid => e
18
+ # only try once
19
+ raise e if tries > 1
20
+ # re-raise if it's not an error we care about
21
+ raise e unless e.message =~ /Table.*doesn't exist/
22
+ # otherwise we reload and retry
23
+ TableRenamable::Model.reload_tables
24
+ sql = TableRenamable::Model.process_sql(sql)
25
+ retry
34
26
  end
35
27
  end
36
28
 
@@ -0,0 +1,62 @@
1
+ module TableRenamable
2
+ module ConnectionAdapters
3
+ module SQLite3Adapter
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ # when we are included we add our behavior
8
+ self.included do |klass|
9
+ klass.alias_method_chain(:exec_query, :table_renamable)
10
+ klass.alias_method_chain(:execute, :table_renamable)
11
+ klass.alias_method_chain(:table_structure, :table_renamable)
12
+ end
13
+
14
+ def exec_query_with_table_renamable(*args, &block)
15
+ self.with_retry do
16
+ self.exec_query_without_table_renamable(*args, &block)
17
+ end
18
+ end
19
+
20
+ #
21
+ # Override execute to reload database info
22
+ # @param *args [Array<Mixed>] Just here so we can call super
23
+ #
24
+ # @return [type] [description]
25
+ def execute_with_table_renamable(*args, &block)
26
+ self.with_retry do
27
+ self.execute_without_table_renamable(*args, &block)
28
+ end
29
+ end
30
+
31
+ def table_structure_with_table_renamable(table_name)
32
+ self.with_retry do
33
+ # get the correct table name to check - otherwise this will fail
34
+ # on retry
35
+ current_table_name = TableRenamable::Model.get_current_table_name(
36
+ table_name
37
+ )
38
+ self.table_structure_without_table_renamable(current_table_name)
39
+ end
40
+ end
41
+
42
+
43
+ def with_retry(&block)
44
+ # set up tries so we don't keep retrying
45
+ tries = 0
46
+ begin
47
+ tries += 1
48
+ # call the actual execute behavior
49
+ yield
50
+ rescue ActiveRecord::StatementInvalid => e
51
+ # only try once
52
+ raise e if tries > 1
53
+ # re-raise if it's not an error we care about
54
+ raise e unless e.message =~ /Could not find table/
55
+ # otherwise we reload and retry
56
+ TableRenamable::Model.reload_tables
57
+ retry
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ module TableRenamable
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace TableRenamable
4
+
5
+ config.after_initialize do
6
+ # set up our reload behavior for when table names change for MySQL
7
+ if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
8
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter.send(
9
+ :include,
10
+ TableRenamable::ConnectionAdapters::Mysql2Adapter
11
+ )
12
+ # same thing for SQLite
13
+ elsif defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
14
+ ActiveRecord::ConnectionAdapters::SQLite3Adapter.send(
15
+ :include,
16
+ TableRenamable::ConnectionAdapters::SQLite3Adapter
17
+ )
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -6,15 +6,17 @@ module TableRenamable
6
6
  #
7
7
  module Model
8
8
 
9
+ extend ActiveSupport::Concern
10
+
9
11
  class NoTableError < Exception; end;
10
12
 
11
13
 
12
- def self.included(klass)
13
- klass.send(:extend, ClassMethods)
14
- klass.class_inheritable_accessor :deprecated_columns
14
+ included do |klass|
15
+ klass.class_attribute :deprecated_columns
15
16
  klass.deprecated_columns = []
16
17
  end
17
18
 
19
+
18
20
  #
19
21
  # Return our list of deprecated tables
20
22
  #
@@ -1,3 +1,3 @@
1
1
  module TableRenamable
2
- VERSION = "2.0.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | | |-- images
161
+ | | |-- javascripts
162
+ | | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | |-- assets
177
+ | `-- tasks
178
+ |-- log
179
+ |-- public
180
+ |-- script
181
+ |-- test
182
+ | |-- fixtures
183
+ | |-- functional
184
+ | |-- integration
185
+ | |-- performance
186
+ | `-- unit
187
+ |-- tmp
188
+ | `-- cache
189
+ | `-- assets
190
+ `-- vendor
191
+ |-- assets
192
+ | |-- javascripts
193
+ | `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.