advertnet 1.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 (159) hide show
  1. data/LICENSE +674 -0
  2. data/README +257 -0
  3. data/Rakefile +10 -0
  4. data/app/controllers/application.rb +40 -0
  5. data/app/controllers/container_controller.rb +83 -0
  6. data/app/controllers/content_controller.rb +61 -0
  7. data/app/controllers/furnitures_controller.rb +87 -0
  8. data/app/controllers/networks_controller.rb +269 -0
  9. data/app/controllers/objects_in_world_controller.rb +27 -0
  10. data/app/controllers/panels_controller.rb +186 -0
  11. data/app/helpers/application_helper.rb +31 -0
  12. data/app/helpers/container_helper.rb +2 -0
  13. data/app/helpers/content_helper.rb +2 -0
  14. data/app/helpers/furnitures_helper.rb +2 -0
  15. data/app/helpers/network_helper.rb +2 -0
  16. data/app/helpers/networks_helper.rb +2 -0
  17. data/app/helpers/objects_in_world_helper.rb +2 -0
  18. data/app/helpers/panels_helper.rb +2 -0
  19. data/app/models/container.rb +51 -0
  20. data/app/models/furniture.rb +60 -0
  21. data/app/models/mailer.rb +22 -0
  22. data/app/models/network.rb +38 -0
  23. data/app/models/object_in_world.rb +60 -0
  24. data/app/models/object_off_world.rb +77 -0
  25. data/app/models/panel.rb +136 -0
  26. data/app/models/panel_revision.rb +108 -0
  27. data/app/views/container/list.rhtml +27 -0
  28. data/app/views/container/show.rhtml +8 -0
  29. data/app/views/content/_form.rhtml +12 -0
  30. data/app/views/content/edit.rhtml +8 -0
  31. data/app/views/content/list.rhtml +26 -0
  32. data/app/views/content/new.rhtml +8 -0
  33. data/app/views/furnitures/list.rhtml +51 -0
  34. data/app/views/furnitures/show.rhtml +7 -0
  35. data/app/views/layouts/default.rhtml +30 -0
  36. data/app/views/mailer/avtouch.rhtml +1 -0
  37. data/app/views/networks/_form.rhtml +11 -0
  38. data/app/views/networks/_parameters_form.rhtml +8 -0
  39. data/app/views/networks/edit.rhtml +9 -0
  40. data/app/views/networks/list.rhtml +25 -0
  41. data/app/views/networks/new.rhtml +8 -0
  42. data/app/views/networks/show.rhtml +72 -0
  43. data/app/views/networks/show_parameters_form.rjs +5 -0
  44. data/app/views/objects_in_world/list.rhtml +30 -0
  45. data/app/views/objects_in_world/show.rhtml +8 -0
  46. data/app/views/panels/list.rhtml +48 -0
  47. data/app/views/panels/show.rhtml +8 -0
  48. data/bin/advertnet-install +144 -0
  49. data/config/boot.rb +45 -0
  50. data/config/database.yml.default +43 -0
  51. data/config/environment.rb +67 -0
  52. data/config/environments/development.rb +21 -0
  53. data/config/environments/production.rb +21 -0
  54. data/config/environments/test.rb +19 -0
  55. data/config/routes.rb +23 -0
  56. data/db/migrate/001_create_networks.rb +14 -0
  57. data/db/migrate/002_create_furnitures.rb +17 -0
  58. data/db/migrate/003_create_containers.rb +16 -0
  59. data/db/migrate/004_create_objects_in_world.rb +16 -0
  60. data/db/migrate/005_create_objects_off_world.rb +16 -0
  61. data/db/migrate/006_create_panels.rb +17 -0
  62. data/db/migrate/007_join_objects_in_world_panels.rb +17 -0
  63. data/db/migrate/008_join_objects_off_world_panels.rb +17 -0
  64. data/db/migrate/009_add_sessions.rb +19 -0
  65. data/db/migrate/010_add_or_rename_fields.rb +25 -0
  66. data/db/migrate/011_move_texture_to_object_in_world.rb +25 -0
  67. data/db/migrate/012_add_permanent_furniture_id.rb +18 -0
  68. data/db/migrate/013_create_panel_revisions.rb +42 -0
  69. data/db/schema.rb +102 -0
  70. data/doc/README_FOR_APP +108 -0
  71. data/lib/advertnet.rb +13 -0
  72. data/lib/second_life_validators.rb +89 -0
  73. data/lib/tasks/documentation.rake +16 -0
  74. data/lib/tasks/extract_fixtures.rake +23 -0
  75. data/lib/tasks/load_exported_fixtures.rake +14 -0
  76. data/public/404.html +30 -0
  77. data/public/500.html +30 -0
  78. data/public/dispatch.cgi +10 -0
  79. data/public/dispatch.fcgi +24 -0
  80. data/public/dispatch.rb +10 -0
  81. data/public/favicon.ico +0 -0
  82. data/public/images/rails.png +0 -0
  83. data/public/javascripts/application.js +2 -0
  84. data/public/javascripts/controls.js +833 -0
  85. data/public/javascripts/dragdrop.js +942 -0
  86. data/public/javascripts/effects.js +1088 -0
  87. data/public/javascripts/prototype.js +2515 -0
  88. data/public/robots.txt +1 -0
  89. data/public/stylesheets/application.css +25 -0
  90. data/public/stylesheets/scaffold.css +74 -0
  91. data/script/about +3 -0
  92. data/script/breakpointer +3 -0
  93. data/script/console +3 -0
  94. data/script/destroy +3 -0
  95. data/script/generate +3 -0
  96. data/script/performance/benchmarker +3 -0
  97. data/script/performance/profiler +3 -0
  98. data/script/plugin +3 -0
  99. data/script/process/inspector +3 -0
  100. data/script/process/reaper +3 -0
  101. data/script/process/spawner +3 -0
  102. data/script/runner +3 -0
  103. data/script/server +3 -0
  104. data/test/fixtures/containers.yml +44 -0
  105. data/test/fixtures/furnitures.yml +47 -0
  106. data/test/fixtures/mailer/avtouch +1 -0
  107. data/test/fixtures/networks.yml +31 -0
  108. data/test/fixtures/objects_in_world.yml +71 -0
  109. data/test/fixtures/objects_in_world_panels.yml +43 -0
  110. data/test/fixtures/objects_off_world.yml +55 -0
  111. data/test/fixtures/objects_off_world_panels.yml +20 -0
  112. data/test/fixtures/panel_revisions.yml +28 -0
  113. data/test/fixtures/panels.yml +79 -0
  114. data/test/functional/container_controller_test.rb +167 -0
  115. data/test/functional/content_controller_test.rb +91 -0
  116. data/test/functional/furnitures_controller_test.rb +134 -0
  117. data/test/functional/networks_controller_test.rb +248 -0
  118. data/test/functional/objects_in_world_controller_test.rb +42 -0
  119. data/test/functional/panels_controller_test.rb +173 -0
  120. data/test/test_helper.rb +53 -0
  121. data/test/unit/container_test.rb +53 -0
  122. data/test/unit/furniture_test.rb +68 -0
  123. data/test/unit/mailer_test.rb +40 -0
  124. data/test/unit/network_test.rb +42 -0
  125. data/test/unit/object_in_world_test.rb +33 -0
  126. data/test/unit/object_off_world_test.rb +26 -0
  127. data/test/unit/panel_revision_test.rb +148 -0
  128. data/test/unit/panel_test.rb +63 -0
  129. data/vendor/plugins/annotate_models/ChangeLog +46 -0
  130. data/vendor/plugins/annotate_models/README +31 -0
  131. data/vendor/plugins/annotate_models/lib/annotate_models.rb +132 -0
  132. data/vendor/plugins/annotate_models/tasks/annotate_models_tasks.rake +7 -0
  133. data/vendor/plugins/foreign_key_migrations/CHANGELOG +99 -0
  134. data/vendor/plugins/foreign_key_migrations/MIT-LICENSE +20 -0
  135. data/vendor/plugins/foreign_key_migrations/README +87 -0
  136. data/vendor/plugins/foreign_key_migrations/about.yml +5 -0
  137. data/vendor/plugins/foreign_key_migrations/init.rb +3 -0
  138. data/vendor/plugins/foreign_key_migrations/install.rb +1 -0
  139. data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/base.rb +22 -0
  140. data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/abstract_adapter.rb +22 -0
  141. data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/table_definition.rb +28 -0
  142. data/vendor/plugins/redhillonrails_core/CHANGELOG +154 -0
  143. data/vendor/plugins/redhillonrails_core/MIT-LICENSE +20 -0
  144. data/vendor/plugins/redhillonrails_core/README +139 -0
  145. data/vendor/plugins/redhillonrails_core/init.rb +19 -0
  146. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb +54 -0
  147. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb +31 -0
  148. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/column.rb +21 -0
  149. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb +26 -0
  150. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/index_definition.rb +11 -0
  151. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_adapter.rb +82 -0
  152. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_column.rb +8 -0
  153. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/postgresql_adapter.rb +107 -0
  154. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/schema_statements.rb +23 -0
  155. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/sqlite3_adapter.rb +9 -0
  156. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/table_definition.rb +27 -0
  157. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb +27 -0
  158. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb +47 -0
  159. metadata +290 -0
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class PanelTest < Test::Unit::TestCase
4
+ fixtures :furnitures, :panels, :containers, :networks
5
+ fixtures :objects_in_world, :objects_off_world
6
+ fixtures :objects_in_world_panels, :objects_off_world_panels
7
+ fixtures :panel_revisions
8
+
9
+ def setup
10
+ @panel1 = Panel.new
11
+ @panel1.name = "test panel"
12
+ @panel1.panel_key = "88888888-4444-4444-4444-222222222222"
13
+ @panel1.furniture = Furniture.find(:first)
14
+ end
15
+
16
+ def test_all_empty
17
+ panel = Panel.new
18
+ assert(!panel.valid?, "Un Panel vide doit être invalide")
19
+ end
20
+
21
+ def test_panel_valid
22
+ assert @panel1.valid?
23
+ assert @panel1.save
24
+ end
25
+
26
+ def test_default_texture
27
+ panel = Panel.new
28
+ panel.name = "test panel"
29
+ panel.panel_key = "88888888-4444-4444-4444-222222222222"
30
+ panel.furniture = Furniture.find(:first)
31
+ assert panel.valid?
32
+ assert panel.save
33
+ assert_equal "caaf0b85-b869-d344-8573-d260a50f635d", panel.objects_in_world.find_by_otype("texture").object_key
34
+ end
35
+
36
+ def test_key_uniqueness
37
+ assert @panel1.save
38
+
39
+ panel2 = Panel.new
40
+ panel2.name = "test panel 2"
41
+ panel2.panel_key = "88888888-4444-4444-4444-222222222222"
42
+ panel2.furniture = Furniture.find(:first)
43
+ assert !panel2.valid?
44
+ assert_equal "must be unique", panel2.errors.on(:panel_key)
45
+
46
+ panel2.panel_key = "88888888-0000-4444-4444-222222222222"
47
+ assert panel2.valid?
48
+ assert panel2.save
49
+ end
50
+
51
+ def test_foreign_key
52
+ @panel1.network_id = 42
53
+ assert_raise(ActiveRecord::StatementInvalid) { @panel1.save }
54
+ @panel1.network_id = 1
55
+ assert_nothing_raised { @panel1.save }
56
+ # FIXME : Ce test devrait échouer car 42 n'est pas un ID de média valide et les
57
+ # contraintes des clés étrangères devraient s'appliquer.
58
+ ##@panel1.furniture_id = 42
59
+ ##assert_raise(ActiveRecord::StatementInvalid) { @panel1.save }
60
+ @panel1.furniture_id = 1
61
+ assert_nothing_raised { @panel1.save }
62
+ end
63
+ end
@@ -0,0 +1,46 @@
1
+ 2007-03-05: Dave Thomas <dave@pragprog.com>
2
+ * Forgot to call the quote method
3
+
4
+ 2007-03-02: Dave Thomas <dave@pragprog.com>
5
+ * Allow non-printing characters in column defaults (suggested by Ben Booth)
6
+
7
+ 2007-02-28: Dave Thomas <dave@pragprog.com>
8
+ * Report errors loading model classes better. Change suggested by Niels Knacke
9
+
10
+ 2007-02-22: Dave Thomas <dave@pragprog.com>
11
+ * Ignore models with no underlying database table (based on patch from Jamie van Dyke)
12
+ * Handle case where database has no session_info table (patch by David Vrensk)
13
+
14
+
15
+ 2006-07-13: Dave Thomas <dave@pragprog.com>
16
+ * Support :scale for decimal columns
17
+
18
+ 2006-07-13: Wes Gamble
19
+ * Don't annotate abstract models
20
+
21
+ 2006-06-13: Dave Thomas <dave@pragprog.com>
22
+ * Fix bug where we corrupted the PREFIX string and therefore duplicated
23
+ the header
24
+ * No longer include the datetime, so we don't trigger a commit
25
+ back into repos
26
+
27
+ -- NOTE -- just this once, you'll get a duplicate header after you run
28
+ a_m on an already-annotated model. Sorry.... Dave
29
+
30
+
31
+
32
+ 2006-06-11 Dave Thomas <dave@pragprog.com>
33
+ * lib/annotate_models.rb: At Kian Wright's suggestion, document the table
34
+ name and primary key. Also make the timestamp prettier
35
+
36
+ 2006-04-17 Dave Thomas <dave@pragprog.com>
37
+
38
+ * lib/annnotate_models.rb: Include Bruce William's patch to allow
39
+ models in subdirectories
40
+
41
+ 2006-03-11 Dave Thomas <dave@pragprog.com>
42
+
43
+ * lib/annotate_models.rb: Use camelize, not classify, to construct
44
+ class names (Grant Hollingworth)
45
+
46
+ 3/3/06 Now annotates fixture files too (thanks to Josha Susser)
@@ -0,0 +1,31 @@
1
+ AnnotateSchema
2
+ ==============
3
+
4
+ Add a comment summarizing the current schema to the top
5
+ of each ActiveRecord model source file:
6
+
7
+ # Schema as of Sun Feb 26 21:58:32 CST 2006 (schema version 7)
8
+ #
9
+ # id :integer(11) not null
10
+ # quantity :integer(11)
11
+ # product_id :integer(11)
12
+ # unit_price :float
13
+ # order_id :integer(11)
14
+ #
15
+
16
+ class LineItem < ActiveRecord::Base belongs_to :product
17
+
18
+ . . .
19
+
20
+ Note that this code will blow away the initial comment block in your models if it looks ike it was
21
+ previously added by annotate models, so you don't want to add additional text to an automatically
22
+ created comment block.
23
+
24
+ Author:
25
+ Dave Thomas
26
+ Pragmatic Programmers, LLC
27
+
28
+ Released under the same license as Ruby. No Support. No Warranty.
29
+
30
+ Back up your model files before using...
31
+
@@ -0,0 +1,132 @@
1
+ require "config/environment"
2
+
3
+ MODEL_DIR = File.join(RAILS_ROOT, "app/models")
4
+ FIXTURE_DIR = File.join(RAILS_ROOT, "test/fixtures")
5
+
6
+ module AnnotateModels
7
+
8
+ PREFIX = "== Schema Information"
9
+
10
+ # Simple quoting for the default column value
11
+ def self.quote(value)
12
+ case value
13
+ when NilClass then "NULL"
14
+ when TrueClass then "TRUE"
15
+ when FalseClass then "FALSE"
16
+ when Float, Fixnum, Bignum then value.to_s
17
+ # BigDecimals need to be output in a non-normalized form and quoted.
18
+ when BigDecimal then value.to_s('F')
19
+ else
20
+ value.inspect
21
+ end
22
+ end
23
+
24
+ # Use the column information in an ActiveRecord class
25
+ # to create a comment block containing a line for
26
+ # each column. The line contains the column name,
27
+ # the type (and length), and any optional attributes
28
+ def self.get_schema_info(klass, header)
29
+ info = "# #{header}\n#\n"
30
+ info << "# Table name: #{klass.table_name}\n#\n"
31
+
32
+ max_size = klass.column_names.collect{|name| name.size}.max + 1
33
+ klass.columns.each do |col|
34
+ attrs = []
35
+ attrs << "default(#{quote(col.default)})" if col.default
36
+ attrs << "not null" unless col.null
37
+ attrs << "primary key" if col.name == klass.primary_key
38
+
39
+ col_type = col.type.to_s
40
+ if col_type == "decimal"
41
+ col_type << "(#{col.precision}, #{col.scale})"
42
+ else
43
+ col_type << "(#{col.limit})" if col.limit
44
+ end
45
+ info << sprintf("# %-#{max_size}.#{max_size}s:%-13.13s %s\n", col.name, col_type, attrs.join(", "))
46
+ end
47
+
48
+ info << "#\n\n"
49
+ end
50
+
51
+ # Add a schema block to a file. If the file already contains
52
+ # a schema info block (a comment starting
53
+ # with "Schema as of ..."), remove it first.
54
+
55
+ def self.annotate_one_file(file_name, info_block)
56
+ if File.exist?(file_name)
57
+ content = File.read(file_name)
58
+
59
+ if content.match(/^# #{PREFIX}.*?\n(#.*\n)*\n/)
60
+ # Remove old schema info, if present, and replace with the new one
61
+ content.sub!(/^# #{PREFIX}.*?\n(#.*\n)*\n/, info_block)
62
+ else
63
+ # Otherwise add the block at the beginning of the file
64
+ content = info_block + content
65
+ end
66
+
67
+ # Write it back
68
+ File.open(file_name, "w") { |f| f.puts content }
69
+ end
70
+ end
71
+
72
+ # Given the name of an ActiveRecord class, create a schema
73
+ # info block (basically a comment containing information
74
+ # on the columns and their types) and put it at the front
75
+ # of the model and fixture source files.
76
+
77
+ def self.annotate(klass, header)
78
+ info = get_schema_info(klass, header)
79
+
80
+ model_file_name = File.join(MODEL_DIR, klass.name.underscore + ".rb")
81
+ annotate_one_file(model_file_name, info)
82
+
83
+ fixture_file_name = File.join(FIXTURE_DIR, klass.table_name + ".yml")
84
+ annotate_one_file(fixture_file_name, info)
85
+ end
86
+
87
+ # Return a list of the model files to annotate. If we have
88
+ # command line arguments, they're assumed to be either
89
+ # the underscore or CamelCase versions of model names.
90
+ # Otherwise we take all the model files in the
91
+ # app/models directory.
92
+ def self.get_model_names
93
+ models = ARGV.dup
94
+ models.shift
95
+
96
+ if models.empty?
97
+ Dir.chdir(MODEL_DIR) do
98
+ models = Dir["**/*.rb"]
99
+ end
100
+ end
101
+ models
102
+ end
103
+
104
+ # We're passed a name of things that might be
105
+ # ActiveRecord models. If we can find the class, and
106
+ # if its a subclass of ActiveRecord::Base,
107
+ # then pas it to the associated block
108
+
109
+ def self.do_annotations
110
+ header = PREFIX.dup
111
+ version = ActiveRecord::Migrator.current_version rescue 0
112
+ if version > 0
113
+ header << "\n# Schema version: #{version}"
114
+ end
115
+
116
+ self.get_model_names.each do |m|
117
+ class_name = m.sub(/\.rb$/,'').camelize
118
+ begin
119
+ klass = class_name.split('::').inject(Object){ |klass,part| klass.const_get(part) }
120
+ if klass < ActiveRecord::Base && !klass.abstract_class?
121
+ puts "Annotating #{class_name}"
122
+ self.annotate(klass, header)
123
+ else
124
+ puts "Skipping #{class_name}"
125
+ end
126
+ rescue Exception => e
127
+ puts "Unable to annotate #{class_name}: #{e.message}"
128
+ end
129
+
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,7 @@
1
+ namespace :db do
2
+ desc "Add schema information (as comments) to model files"
3
+ task :annotate_models do
4
+ require File.join(File.dirname(__FILE__), "../lib/annotate_models.rb")
5
+ AnnotateModels.do_annotations
6
+ end
7
+ end
@@ -0,0 +1,99 @@
1
+ [REVISION 20070905]
2
+
3
+ [FIXED] "some_column_name" referenced in foreign key constraint does not exist.
4
+
5
+ [REVISION 20070904]
6
+
7
+ [NEW] Support :references keyword when calling primary_key().
8
+
9
+ [NEW] [#11995] the parameter :references needs the second argument referencing the field name.
10
+
11
+ [REVISION 20070707]
12
+
13
+ [NEW] Support acts_as_tree convention: if a column is named parent_id it will be treated as a circular reference to the table in which it is defined.
14
+
15
+ [REVISION 20070703]
16
+
17
+ [FIXED] Foreign-keys not created when using add_column.
18
+
19
+ [REVISION 20070628]
20
+
21
+ [FIXED] Stack level too deep in 'add_column_without_foreign_key_migrations' (Ronen Barzel).
22
+
23
+ [REVISION 20070503]
24
+
25
+ [NEW] Support for SQL92 [NOT] DEFERRABLE on foreign keys.
26
+
27
+ [REVISION 20061202]
28
+
29
+ [CHANGED] Use Rails 1.2 alias_method_chain.
30
+
31
+ [CHANGED] Separate modules into individual files.
32
+
33
+ [REVISION 20061013]
34
+
35
+ [NEW] install.rb informs user of missing dependencies.
36
+
37
+ [REVISION 20060909]
38
+
39
+ [CHANGED] Replaced dependence on defunct Foreign Key Support and Schema Defining plugins with a single dependece on RedHill on Rails Core.
40
+
41
+ [REVISION 20060831]
42
+
43
+ [CHANGED] Separated out generic foreign-key functionality into new foreign key support plugin.
44
+
45
+ [REVISION 20060629]
46
+
47
+ [NEW] Added foreign_key method to table to allow t.foreign_key(columns, references_table_name, references_column_names, options).
48
+
49
+ [NEW] Support foreign keys in add_column as we do for initial table columns.
50
+
51
+ [NEW] Support :on_update and :on_delete as options--with values of :set_null, :cascade, or :restrict--for all foreign key creation mechanisms.
52
+
53
+ [REVISION 20060627]
54
+
55
+ [CHANGED] Reverted to overloaded column method with optional :references as the preferred mechanism with belongs_to a "nicety". This is really as a result of using it in a large-scale production application where belongs_to just didn't feel right in many cases and was semantically ambiguous.
56
+
57
+ [REVISION 20060824]
58
+
59
+ [CHANGED] Replaced method and column option :references with :belongs_to in keeping with the rails model keywords. The references variations are still available but have been deprecated and will be removed.
60
+
61
+ [NEW] Added options :dependent => :nullify to SET NULL or :dependent => :delete_all | :destroy to CASCADE DELETE.
62
+
63
+ [REVISION 20060812]
64
+
65
+ [NEW] Added new table method references(table, options) which is essentially an alias for column(:table_id, :integer, options).
66
+
67
+ [REVISION 20060803]
68
+
69
+ [FIXED] The method proper_pluralized_table_name tries to call pluralize_table_name where it should call pluralized_table_name.
70
+
71
+ [REVISION 20060623]
72
+
73
+ [FIXED] Another try at a hack-around for a "feature" of pluralize that when called to pluralize a word that is already in the plural, acts as singularize.
74
+
75
+ [REVISION 20060616]
76
+
77
+ [FIXED] Hack-around for a "feature" of pluralize that when called to pluralize a word that is already in the plural, acts as singularize. Ie. "countries".pluralize becomes "country"!
78
+
79
+ [REVISION 200606004]
80
+
81
+ [CHANGED] This plugin now depends on Schema Defining!
82
+
83
+ [REVISION 20060602]
84
+
85
+ [CHANGED] Simplified static method overriding thanks to Ryan Tomayko.
86
+
87
+ [REVISION 20060525]
88
+
89
+ [CHANGED] Disabled foreign-key generation when executing a schema dump. This is a temporary measure until I get around to batching up the foreign keys at the end of the script.
90
+
91
+ [REVISION 20060523]
92
+
93
+ [NEW] Support :references => nil to prevent unwanted foreign-keys.
94
+
95
+ [FIXED] Pluralization.
96
+
97
+ [REVISION 20060522]
98
+
99
+ [FIXED] Infinite recursion caused by bug in 1.8.4 method_alias on windows.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 RedHill Consulting, Pty. Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ = Foreign Key Migrations
2
+
3
+ Foreign Key Migrations is a plugin that automatically generates foreign-key
4
+ constraints when creating tables. It uses SQL-92 syntax and as such should be
5
+ compatible with most databases that support foreign-key constraints.
6
+
7
+ In the simplest case, the plugin assumes that if you have a column named
8
+ +customer_id+ that you want a foreign-key constraint generated that references
9
+ the +id+ column in the +customers+ table:
10
+
11
+ create_table :orders do |t|
12
+ t.column :customer_id, :integer, :null => false
13
+ ...
14
+ end
15
+
16
+ If you have multiple columns referencing a table or for whatever reason, your
17
+ column name isn't the same as the referenced table name, you can use the
18
+ <code>:references</code> option:
19
+
20
+ create_table :orders do |t|
21
+ t.column :ordered_by_id, :integer, :null => false, :references => :customers
22
+ ...
23
+ end
24
+
25
+ If you have a column with a name ending in +_id+ for which you do not wish a
26
+ foreign-key to be generated, you can use <code>:references => nil</code>:
27
+
28
+ create_table :orders do |t|
29
+ t.column :external_id, :integer, :null => false, :references => nil
30
+ ...
31
+ end
32
+
33
+ Sometimes you may (for legacy reasons) need to reference a primary key column that is
34
+ named something other than +id+. In this case you can specify the name of the column:
35
+
36
+ create_table :orders do |t|
37
+ t.column :ordered_by_pk, :integer, :null => false, :references => [:customers, :pk]
38
+ ...
39
+ end
40
+
41
+ You also have the option of specifying what to do on delete/update using
42
+ <code>:on_delete</code>/<code>:on_update</code>, respectively to one of:
43
+ <code>:cascade</code>; <code>:restrict</code>; and <code>:set_null</code>:
44
+
45
+ create_table :orders do |t|
46
+ t.column :customer_id, :integer, :on_delete => :set_null, :on_update => :cascade
47
+ ...
48
+ end
49
+
50
+ If your database supports it (for example PostgreSQL) you can also mark the constraint as deferrable:
51
+
52
+ create_table :orders do |t|
53
+ t.column :customer_id, :integer, :deferrable => true
54
+ ...
55
+ end
56
+
57
+ By convention, if a column is named +parent_id+ it will be treated as a circular reference to
58
+ the table in which it is defined.
59
+
60
+ Sometimes you may (for legacy reasons) need to name your primary key column such that it
61
+ would be misinterpreted as a foreign-key (say for example if you named the primary key
62
+ +order_id+). In this case you can manually create the primary key as follows:
63
+
64
+ create_table :orders, :id => false do |t|
65
+ ...
66
+ t.primary_key :order_id, :references => nil
67
+ end
68
+
69
+ The plugin fully supports and understands the following active-record
70
+ configuration properties:
71
+
72
+ * <code>config.active_record.pluralize_table_names</code>
73
+ * <code>config.active_record.table_name_prefix</code>
74
+ * <code>config.active_record.table_name_suffix</code>
75
+
76
+ === Dependencies
77
+
78
+ * RedHill on Rails Core (redhillonrails_core).
79
+
80
+ === See Also
81
+
82
+ * Foreign Key Associations (foreign_key_associations).
83
+
84
+ === License
85
+
86
+ This plugin is copyright 2006 by RedHill Consulting, Pty. Ltd. and is released
87
+ under the MIT license.