diff options
-rw-r--r-- | app/models/incoming_message.rb | 16 | ||||
-rw-r--r-- | app/models/info_request.rb | 15 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 17 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 18 | ||||
-rw-r--r-- | app/models/public_body.rb | 19 | ||||
-rw-r--r-- | app/models/user.rb | 17 | ||||
-rw-r--r-- | vendor/plugins/annotate_models/ChangeLog | 46 | ||||
-rw-r--r-- | vendor/plugins/annotate_models/README | 31 | ||||
-rw-r--r-- | vendor/plugins/annotate_models/lib/annotate_models.rb | 127 | ||||
-rw-r--r-- | vendor/plugins/annotate_models/tasks/annotate_models_tasks.rake | 6 |
10 files changed, 306 insertions, 6 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 30cd1f74e..31b6eca35 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -1,3 +1,17 @@ +# == Schema Information +# Schema version: 21 +# +# Table name: incoming_messages +# +# id :integer not null, primary key +# info_request_id :integer +# raw_data :text +# created_at :datetime +# updated_at :datetime +# user_classified :boolean +# contains_information :boolean +# + # models/incoming_message.rb: # An (email) message from really anybody to be logged with a request. e.g. A # response from the public body. @@ -5,7 +19,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.5 2007-11-14 01:01:39 francis Exp $ +# $Id: incoming_message.rb,v 1.6 2007-12-11 12:16:29 francis Exp $ class IncomingMessage < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 910519add..c295a57a8 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1,10 +1,23 @@ +# == Schema Information +# Schema version: 21 +# +# Table name: info_requests +# +# id :integer not null, primary key +# title :text +# user_id :integer +# public_body_id :integer +# created_at :datetime +# updated_at :datetime +# + # models/info_request.rb: # A Freedom of Information request. # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.15 2007-11-23 12:01:20 francis Exp $ +# $Id: info_request.rb,v 1.16 2007-12-11 12:16:29 francis Exp $ require 'digest/sha1' diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index e944c5b87..e6d716b0f 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -1,3 +1,18 @@ +# == Schema Information +# Schema version: 21 +# +# Table name: outgoing_messages +# +# id :integer not null, primary key +# info_request_id :integer +# body :text +# status :string(255) +# message_type :string(255) +# created_at :datetime +# updated_at :datetime +# sent_at :datetime +# + # models/outgoing_message.rb: # A message, associated with a request, from the user of the site to somebody # else. e.g. An initial request for information, or a complaint. @@ -5,7 +20,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: outgoing_message.rb,v 1.10 2007-11-09 02:11:36 francis Exp $ +# $Id: outgoing_message.rb,v 1.11 2007-12-11 12:16:29 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 9ae5e337d..06d6d108d 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -1,3 +1,19 @@ +# == Schema Information +# Schema version: 21 +# +# Table name: post_redirects +# +# id :integer not null, primary key +# token :text +# uri :text +# post_params_yaml :text +# created_at :datetime +# updated_at :datetime +# email_token :text +# reason_params_yaml :text +# user_id :integer +# + # models/postredirect.rb: # Saves an HTTP POST request, so it can be redirected to later. # For example, after registering / logging in. @@ -5,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: post_redirect.rb,v 1.5 2007-11-23 12:01:20 francis Exp $ +# $Id: post_redirect.rb,v 1.6 2007-12-11 12:16:29 francis Exp $ require 'openssl' # for random bytes function diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 6a5134396..e22500d79 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -1,10 +1,27 @@ +# == Schema Information +# Schema version: 21 +# +# Table name: public_bodies +# +# id :integer not null, primary key +# name :text +# short_name :text +# request_email :text +# complaint_email :text +# version :integer +# last_edit_editor :string(255) +# last_edit_comment :string(255) +# created_at :datetime +# updated_at :datetime +# + # models/public_body.rb: # A public body, from which information can be requested. # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.9 2007-10-31 17:25:29 francis Exp $ +# $Id: public_body.rb,v 1.10 2007-12-11 12:16:29 francis Exp $ class PublicBody < ActiveRecord::Base validates_presence_of :name diff --git a/app/models/user.rb b/app/models/user.rb index 51f47164e..39a28620f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,10 +1,25 @@ +# == Schema Information +# Schema version: 21 +# +# Table name: users +# +# id :integer not null, primary key +# email :string(255) +# name :string(255) +# hashed_password :string(255) +# salt :string(255) +# created_at :datetime +# updated_at :datetime +# email_confirmed :boolean +# + # models/user.rb: # Model of people who use the site to file requests, make comments etc. # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.12 2007-11-07 10:26:30 francis Exp $ +# $Id: user.rb,v 1.13 2007-12-11 12:16:29 francis Exp $ require 'digest/sha1' diff --git a/vendor/plugins/annotate_models/ChangeLog b/vendor/plugins/annotate_models/ChangeLog new file mode 100644 index 000000000..e6630a87c --- /dev/null +++ b/vendor/plugins/annotate_models/ChangeLog @@ -0,0 +1,46 @@ +2007-03-05: Dave Thomas <dave@pragprog.com> + * Forgot to call the quote method + +2007-03-02: Dave Thomas <dave@pragprog.com> + * Allow non-printing characters in column defaults (suggested by Ben Booth) + +2007-02-28: Dave Thomas <dave@pragprog.com> + * Report errors loading model classes better. Change suggested by Niels Knacke + +2007-02-22: Dave Thomas <dave@pragprog.com> +* Ignore models with no underlying database table (based on patch from Jamie van Dyke) +* Handle case where database has no session_info table (patch by David Vrensk) + + +2006-07-13: Dave Thomas <dave@pragprog.com> + * Support :scale for decimal columns + +2006-07-13: Wes Gamble + * Don't annotate abstract models + +2006-06-13: Dave Thomas <dave@pragprog.com> + * Fix bug where we corrupted the PREFIX string and therefore duplicated + the header + * No longer include the datetime, so we don't trigger a commit + back into repos + + -- NOTE -- just this once, you'll get a duplicate header after you run + a_m on an already-annotated model. Sorry.... Dave + + + +2006-06-11 Dave Thomas <dave@pragprog.com> + * lib/annotate_models.rb: At Kian Wright's suggestion, document the table + name and primary key. Also make the timestamp prettier + +2006-04-17 Dave Thomas <dave@pragprog.com> + + * lib/annnotate_models.rb: Include Bruce William's patch to allow + models in subdirectories + +2006-03-11 Dave Thomas <dave@pragprog.com> + + * lib/annotate_models.rb: Use camelize, not classify, to construct + class names (Grant Hollingworth) + +3/3/06 Now annotates fixture files too (thanks to Josha Susser) diff --git a/vendor/plugins/annotate_models/README b/vendor/plugins/annotate_models/README new file mode 100644 index 000000000..f1f1dff55 --- /dev/null +++ b/vendor/plugins/annotate_models/README @@ -0,0 +1,31 @@ +AnnotateSchema +============== + +Add a comment summarizing the current schema to the top +of each ActiveRecord model source file: + + # Schema as of Sun Feb 26 21:58:32 CST 2006 (schema version 7) + # + # id :integer(11) not null + # quantity :integer(11) + # product_id :integer(11) + # unit_price :float + # order_id :integer(11) + # + + class LineItem < ActiveRecord::Base belongs_to :product + + . . . + +Note that this code will blow away the initial comment block in your models if it looks ike it was +previously added by annotate models, so you don't want to add additional text to an automatically +created comment block. + +Author: + Dave Thomas + Pragmatic Programmers, LLC + +Released under the same license as Ruby. No Support. No Warranty. + +Back up your model files before using... + diff --git a/vendor/plugins/annotate_models/lib/annotate_models.rb b/vendor/plugins/annotate_models/lib/annotate_models.rb new file mode 100644 index 000000000..1d84113af --- /dev/null +++ b/vendor/plugins/annotate_models/lib/annotate_models.rb @@ -0,0 +1,127 @@ +require "config/environment" + +MODEL_DIR = File.join(RAILS_ROOT, "app/models") +FIXTURE_DIR = File.join(RAILS_ROOT, "test/fixtures") + +module AnnotateModels + + PREFIX = "== Schema Information" + + # Simple quoting for the default column value + def self.quote(value) + case value + when NilClass then "NULL" + when TrueClass then "TRUE" + when FalseClass then "FALSE" + when Float, Fixnum, Bignum then value.to_s + # BigDecimals need to be output in a non-normalized form and quoted. + when BigDecimal then value.to_s('F') + else + value.inspect + end + end + + # Use the column information in an ActiveRecord class + # to create a comment block containing a line for + # each column. The line contains the column name, + # the type (and length), and any optional attributes + def self.get_schema_info(klass, header) + info = "# #{header}\n#\n" + info << "# Table name: #{klass.table_name}\n#\n" + + max_size = klass.column_names.collect{|name| name.size}.max + 1 + klass.columns.each do |col| + attrs = [] + attrs << "default(#{quote(col.default)})" if col.default + attrs << "not null" unless col.null + attrs << "primary key" if col.name == klass.primary_key + + col_type = col.type.to_s + if col_type == "decimal" + col_type << "(#{col.precision}, #{col.scale})" + else + col_type << "(#{col.limit})" if col.limit + end + info << sprintf("# %-#{max_size}.#{max_size}s:%-15.15s %s\n", col.name, col_type, attrs.join(", ")) + end + + info << "#\n\n" + end + + # Add a schema block to a file. If the file already contains + # a schema info block (a comment starting + # with "Schema as of ..."), remove it first. + + def self.annotate_one_file(file_name, info_block) + if File.exist?(file_name) + content = File.read(file_name) + + # Remove old schema info + content.sub!(/^# #{PREFIX}.*?\n(#.*\n)*\n/, '') + + # Write it back + File.open(file_name, "w") { |f| f.puts info_block + content } + end + end + + # Given the name of an ActiveRecord class, create a schema + # info block (basically a comment containing information + # on the columns and their types) and put it at the front + # of the model and fixture source files. + + def self.annotate(klass, header) + info = get_schema_info(klass, header) + + model_file_name = File.join(MODEL_DIR, klass.name.underscore + ".rb") + annotate_one_file(model_file_name, info) + + fixture_file_name = File.join(FIXTURE_DIR, klass.table_name + ".yml") + annotate_one_file(fixture_file_name, info) + end + + # Return a list of the model files to annotate. If we have + # command line arguments, they're assumed to be either + # the underscore or CamelCase versions of model names. + # Otherwise we take all the model files in the + # app/models directory. + def self.get_model_names + models = ARGV.dup + models.shift + + if models.empty? + Dir.chdir(MODEL_DIR) do + models = Dir["**/*.rb"] + end + end + models + end + + # We're passed a name of things that might be + # ActiveRecord models. If we can find the class, and + # if its a subclass of ActiveRecord::Base, + # then pas it to the associated block + + def self.do_annotations + header = PREFIX.dup + version = ActiveRecord::Migrator.current_version rescue 0 + if version > 0 + header << "\n# Schema version: #{version}" + end + + self.get_model_names.each do |m| + class_name = m.sub(/\.rb$/,'').camelize + begin + klass = class_name.split('::').inject(Object){ |klass,part| klass.const_get(part) } + if klass < ActiveRecord::Base && !klass.abstract_class? + puts "Annotating #{class_name}" + self.annotate(klass, header) + else + puts "Skipping #{class_name}" + end + rescue Exception => e + puts "Unable to annotate #{class_name}: #{e.message}" + end + + end + end +end diff --git a/vendor/plugins/annotate_models/tasks/annotate_models_tasks.rake b/vendor/plugins/annotate_models/tasks/annotate_models_tasks.rake new file mode 100644 index 000000000..0faee208a --- /dev/null +++ b/vendor/plugins/annotate_models/tasks/annotate_models_tasks.rake @@ -0,0 +1,6 @@ +desc "Add schema information (as comments) to model files" + +task :annotate_models do + require File.join(File.dirname(__FILE__), "../lib/annotate_models.rb") + AnnotateModels.do_annotations +end
\ No newline at end of file |