radiant-tags-extension 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HELP.md +50 -0
- data/HELP_admin.md +30 -0
- data/README +38 -0
- data/Rakefile +25 -0
- data/app/models/meta_tag.rb +53 -0
- data/app/models/radius_tags.rb +328 -0
- data/app/models/tag_search_page.rb +87 -0
- data/app/models/tagging.rb +10 -0
- data/app/views/admin/help/_using_tags.html.haml +4 -0
- data/app/views/admin/pages/_tag_field.html.haml +8 -0
- data/db/migrate/001_add_tag_support.rb +20 -0
- data/lib/tagging_methods.rb +128 -0
- data/lib/tasks/tags_extension_tasks.rake +32 -0
- data/public/stylesheets/tags.css +11 -0
- data/tags_extension.rb +57 -0
- data/test/fixtures/meta_tags.yml +12 -0
- data/test/fixtures/page_parts.yml +17 -0
- data/test/fixtures/pages.yml +43 -0
- data/test/fixtures/taggings.yml +20 -0
- data/test/functional/tag_search_page_test.rb +44 -0
- data/test/functional/tags_extension_test.rb +19 -0
- data/test/helpers/render_test_helper.rb +60 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/page_taggability_test.rb +20 -0
- data/vendor/plugins/has_many_polymorphs/.gitignore +1 -0
- data/vendor/plugins/has_many_polymorphs/CHANGELOG +86 -0
- data/vendor/plugins/has_many_polymorphs/LICENSE +184 -0
- data/vendor/plugins/has_many_polymorphs/Manifest +173 -0
- data/vendor/plugins/has_many_polymorphs/README +205 -0
- data/vendor/plugins/has_many_polymorphs/Rakefile +28 -0
- data/vendor/plugins/has_many_polymorphs/TODO +2 -0
- data/vendor/plugins/has_many_polymorphs/examples/hmph.rb +69 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/tagging_generator.rb +97 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/templates/migration.rb +28 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/templates/tag.rb +39 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/templates/tag_test.rb +15 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/templates/tagging.rb +16 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/templates/tagging_extensions.rb +203 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/templates/tagging_test.rb +85 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/templates/taggings.yml +23 -0
- data/vendor/plugins/has_many_polymorphs/generators/tagging/templates/tags.yml +7 -0
- data/vendor/plugins/has_many_polymorphs/init.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/association.rb +160 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/autoload.rb +69 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/base.rb +60 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/class_methods.rb +600 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/configuration.rb +19 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/debugging_tools.rb +103 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/rake_task_redefine_task.rb +35 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/reflection.rb +58 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/support_methods.rb +88 -0
- data/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs.rb +27 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/bow_wows.yml +10 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/cats.yml +18 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/eaters_foodstuffs.yml +0 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/fish.yml +12 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/frogs.yml +5 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/keep_your_enemies_close.yml +0 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/little_whale_pupils.yml +0 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/people.yml +7 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/petfoods.yml +11 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/whales.yml +5 -0
- data/vendor/plugins/has_many_polymorphs/test/fixtures/wild_boars.yml +10 -0
- data/vendor/plugins/has_many_polymorphs/test/generator/tagging_generator_test.rb +42 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/README +182 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/Rakefile +19 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/controllers/application.rb +7 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/controllers/bones_controller.rb +5 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/helpers/addresses_helper.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/helpers/application_helper.rb +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/helpers/bones_helper.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/helpers/sellers_helper.rb +28 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/helpers/states_helper.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/helpers/users_helper.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/models/bone.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/models/double_sti_parent.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/models/double_sti_parent_relationship.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/models/organic_substance.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/models/single_sti_parent.rb +4 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/models/single_sti_parent_relationship.rb +4 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/models/stick.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/models/stone.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/addresses/edit.html.erb +12 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/addresses/index.html.erb +18 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/addresses/new.html.erb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/addresses/show.html.erb +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/bones/index.rhtml +5 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/layouts/addresses.html.erb +17 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/layouts/sellers.html.erb +17 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/layouts/states.html.erb +17 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/layouts/users.html.erb +17 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/sellers/edit.html.erb +12 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/sellers/index.html.erb +20 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/sellers/new.html.erb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/sellers/show.html.erb +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/states/edit.html.erb +12 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/states/index.html.erb +19 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/states/new.html.erb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/states/show.html.erb +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/users/edit.html.erb +12 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/users/index.html.erb +22 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/users/new.html.erb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/app/views/users/show.html.erb +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/boot.rb +110 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/database.yml +17 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/environment.rb +19 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/environment.rb.canonical +19 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/environments/development.rb +9 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/environments/production.rb +18 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/environments/test.rb +19 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/locomotive.yml +6 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/routes.rb +33 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/ultrasphinx/default.base +56 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/config/ultrasphinx/development.conf.canonical +155 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/001_create_sticks.rb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/002_create_stones.rb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/003_create_organic_substances.rb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/004_create_bones.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/005_create_single_sti_parents.rb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/006_create_double_sti_parents.rb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb +13 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb +14 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/db/migrate/009_create_library_model.rb +11 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/doc/README_FOR_APP +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/generators/commenting_generator_test.rb +83 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/lib/library_model.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/.htaccess +40 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/404.html +30 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/500.html +30 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.cgi +10 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.fcgi +24 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.rb +10 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/favicon.ico +0 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/images/rails.png +0 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/index.html +277 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/javascripts/application.js +2 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/javascripts/controls.js +833 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/javascripts/dragdrop.js +942 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/javascripts/effects.js +1088 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/javascripts/prototype.js +2515 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/robots.txt +1 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/public/stylesheets/scaffold.css +74 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/about +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/breakpointer +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/console +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/destroy +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/generate +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/performance/benchmarker +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/performance/profiler +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/plugin +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/process/inspector +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/process/reaper +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/process/spawner +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/runner +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/script/server +3 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/fixtures/double_sti_parent_relationships.yml +7 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/fixtures/double_sti_parents.yml +7 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/fixtures/organic_substances.yml +5 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/fixtures/single_sti_parent_relationships.yml +7 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/fixtures/single_sti_parents.yml +7 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/fixtures/sticks.yml +7 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/fixtures/stones.yml +7 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/addresses_controller_test.rb +57 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/bones_controller_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/sellers_controller_test.rb +57 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/states_controller_test.rb +57 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/users_controller_test.rb +57 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/test_helper.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/bone_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/double_sti_parent_relationship_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/double_sti_parent_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/organic_substance_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/single_sti_parent_relationship_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/single_sti_parent_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/stick_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/stone_test.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/integration/server_test.rb +43 -0
- data/vendor/plugins/has_many_polymorphs/test/models/aquatic/fish.rb +5 -0
- data/vendor/plugins/has_many_polymorphs/test/models/aquatic/pupils_whale.rb +7 -0
- data/vendor/plugins/has_many_polymorphs/test/models/aquatic/whale.rb +15 -0
- data/vendor/plugins/has_many_polymorphs/test/models/beautiful_fight_relationship.rb +26 -0
- data/vendor/plugins/has_many_polymorphs/test/models/canine.rb +9 -0
- data/vendor/plugins/has_many_polymorphs/test/models/cat.rb +5 -0
- data/vendor/plugins/has_many_polymorphs/test/models/dog.rb +18 -0
- data/vendor/plugins/has_many_polymorphs/test/models/eaters_foodstuff.rb +8 -0
- data/vendor/plugins/has_many_polymorphs/test/models/frog.rb +4 -0
- data/vendor/plugins/has_many_polymorphs/test/models/kitten.rb +3 -0
- data/vendor/plugins/has_many_polymorphs/test/models/parentship.rb +4 -0
- data/vendor/plugins/has_many_polymorphs/test/models/person.rb +9 -0
- data/vendor/plugins/has_many_polymorphs/test/models/petfood.rb +39 -0
- data/vendor/plugins/has_many_polymorphs/test/models/tabby.rb +2 -0
- data/vendor/plugins/has_many_polymorphs/test/models/wild_boar.rb +3 -0
- data/vendor/plugins/has_many_polymorphs/test/modules/extension_module.rb +9 -0
- data/vendor/plugins/has_many_polymorphs/test/modules/other_extension_module.rb +9 -0
- data/vendor/plugins/has_many_polymorphs/test/patches/symlinked_plugins_1.2.6.diff +46 -0
- data/vendor/plugins/has_many_polymorphs/test/schema.rb +87 -0
- data/vendor/plugins/has_many_polymorphs/test/setup.rb +14 -0
- data/vendor/plugins/has_many_polymorphs/test/test_helper.rb +52 -0
- data/vendor/plugins/has_many_polymorphs/test/unit/has_many_polymorphs_test.rb +713 -0
- metadata +421 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
|
2
|
+
=begin rdoc
|
3
|
+
|
4
|
+
Debugging tools for Has_many_polymorphs.
|
5
|
+
|
6
|
+
Enable the different tools by setting the environment variable HMP_DEBUG. Settings with special meaning are <tt>"ruby-debug"</tt>, <tt>"trace"</tt>, and <tt>"dependencies"</tt>.
|
7
|
+
|
8
|
+
== Code generation
|
9
|
+
|
10
|
+
Enabled by default when HMP_DEBUG is set.
|
11
|
+
|
12
|
+
Ouputs a folder <tt>generated_models/</tt> in RAILS_ROOT containing valid Ruby files explaining all the ActiveRecord relationships set up by the plugin, as well as listing the line in the plugin that called each particular association method.
|
13
|
+
|
14
|
+
== Ruby-debug
|
15
|
+
|
16
|
+
Enable by setting HMP_DEBUG to <tt>"ruby-debug"</tt>.
|
17
|
+
|
18
|
+
Starts <tt>ruby-debug</tt> for the life of the process.
|
19
|
+
|
20
|
+
== Trace
|
21
|
+
|
22
|
+
Enable by setting HMP_DEBUG to <tt>"ruby-debug"</tt>.
|
23
|
+
|
24
|
+
Outputs an indented trace of relevant method calls as they occur.
|
25
|
+
|
26
|
+
== Dependencies
|
27
|
+
|
28
|
+
Enable by setting HMP_DEBUG to <tt>"dependencies"</tt>.
|
29
|
+
|
30
|
+
Turns on Rails' default dependency logging.
|
31
|
+
|
32
|
+
=end
|
33
|
+
|
34
|
+
_logger_warn "debug mode enabled"
|
35
|
+
|
36
|
+
class << ActiveRecord::Base
|
37
|
+
COLLECTION_METHODS = [:belongs_to, :has_many, :has_and_belongs_to_many, :has_one,
|
38
|
+
:has_many_polymorphs, :acts_as_double_polymorphic_join].each do |method_name|
|
39
|
+
alias_method "original_#{method_name}".to_sym, method_name
|
40
|
+
undef_method method_name
|
41
|
+
end
|
42
|
+
|
43
|
+
unless defined? GENERATED_CODE_DIR
|
44
|
+
GENERATED_CODE_DIR = "#{RAILS_ROOT}/generated_models"
|
45
|
+
|
46
|
+
begin
|
47
|
+
system "rm -rf #{GENERATED_CODE_DIR}"
|
48
|
+
Dir.mkdir GENERATED_CODE_DIR
|
49
|
+
rescue Errno::EACCES
|
50
|
+
_logger_warn "no permissions for generated code dir: #{GENERATED_CODE_DIR}"
|
51
|
+
end
|
52
|
+
|
53
|
+
if File.exist? GENERATED_CODE_DIR
|
54
|
+
alias :original_method_missing :method_missing
|
55
|
+
def method_missing(method_name, *args, &block)
|
56
|
+
if COLLECTION_METHODS.include? method_name.to_sym
|
57
|
+
Dir.chdir GENERATED_CODE_DIR do
|
58
|
+
filename = "#{demodulate(self.name.underscore)}.rb"
|
59
|
+
contents = File.open(filename).read rescue "\nclass #{self.name}\n\nend\n"
|
60
|
+
line = caller[1][/\:(\d+)\:/, 1]
|
61
|
+
contents[-5..-5] = "\n #{method_name} #{args[0..-2].inspect[1..-2]},\n #{args[-1].inspect[1..-2].gsub(" :", "\n :").gsub("=>", " => ")}\n#{ block ? " #{block.inspect.sub(/\@.*\//, '@')}\n" : ""} # called from line #{line}\n\n"
|
62
|
+
File.open(filename, "w") do |file|
|
63
|
+
file.puts contents
|
64
|
+
end
|
65
|
+
end
|
66
|
+
# doesn't actually display block contents
|
67
|
+
self.send("original_#{method_name}", *args, &block)
|
68
|
+
else
|
69
|
+
self.send(:original_method_missing, method_name, *args, &block)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
case ENV['HMP_DEBUG']
|
78
|
+
|
79
|
+
when "ruby-debug"
|
80
|
+
require 'rubygems'
|
81
|
+
require 'ruby-debug'
|
82
|
+
Debugger.start
|
83
|
+
_logger_warn "ruby-debug enabled."
|
84
|
+
|
85
|
+
when "trace"
|
86
|
+
_logger_warn "method tracing enabled"
|
87
|
+
$debug_trace_indent = 0
|
88
|
+
set_trace_func (proc do |event, file, line, id, binding, classname|
|
89
|
+
if id.to_s =~ /instantiate/ #/IRB|Wirble|RubyLex|RubyToken|Logger|ConnectionAdapters|SQLite3|MonitorMixin|Benchmark|Inflector|Inflections/
|
90
|
+
if event == 'call'
|
91
|
+
puts (" " * $debug_trace_indent) + "#{event}ed #{classname}\##{id} from #{file.split('/').last}::#{line}"
|
92
|
+
$debug_trace_indent += 1
|
93
|
+
elsif event == 'return'
|
94
|
+
$debug_trace_indent -= 1 unless $debug_trace_indent == 0
|
95
|
+
puts (" " * $debug_trace_indent) + "#{event}ed #{classname}\##{id}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end)
|
99
|
+
|
100
|
+
when "dependencies"
|
101
|
+
_logger_warn "dependency activity being logged"
|
102
|
+
(::Dependencies.log_activity = true) rescue nil
|
103
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
# Redefine instead of chain a Rake task
|
3
|
+
# http://www.bigbold.com/snippets/posts/show/2032
|
4
|
+
|
5
|
+
module Rake
|
6
|
+
module TaskManager
|
7
|
+
def redefine_task(task_class, args, &block)
|
8
|
+
task_name, deps = resolve_args(args)
|
9
|
+
task_name = task_class.scope_name(@scope, task_name)
|
10
|
+
deps = [deps] unless deps.respond_to?(:to_ary)
|
11
|
+
deps = deps.collect {|d| d.to_s }
|
12
|
+
task = @tasks[task_name.to_s] = task_class.new(task_name, self)
|
13
|
+
task.application = self
|
14
|
+
task.add_comment(@last_comment)
|
15
|
+
@last_comment = nil
|
16
|
+
task.enhance(deps, &block)
|
17
|
+
task
|
18
|
+
end
|
19
|
+
end
|
20
|
+
class Task
|
21
|
+
class << self
|
22
|
+
def redefine_task(args, &block)
|
23
|
+
Rake.application.redefine_task(self, args, &block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Object
|
30
|
+
def silently
|
31
|
+
stderr, stdout, $stderr, $stdout = $stderr, $stdout, StringIO.new, StringIO.new
|
32
|
+
yield
|
33
|
+
$stderr, $stdout = stderr, stdout
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module ActiveRecord #:nodoc:
|
2
|
+
module Reflection #:nodoc:
|
3
|
+
|
4
|
+
module ClassMethods #:nodoc:
|
5
|
+
|
6
|
+
# Update the default reflection switch so that <tt>:has_many_polymorphs</tt> types get instantiated.
|
7
|
+
# It's not a composed method so we have to override the whole thing.
|
8
|
+
def create_reflection(macro, name, options, active_record)
|
9
|
+
case macro
|
10
|
+
when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
|
11
|
+
klass = options[:through] ? ThroughReflection : AssociationReflection
|
12
|
+
reflection = klass.new(macro, name, options, active_record)
|
13
|
+
when :composed_of
|
14
|
+
reflection = AggregateReflection.new(macro, name, options, active_record)
|
15
|
+
# added by has_many_polymorphs #
|
16
|
+
when :has_many_polymorphs
|
17
|
+
reflection = PolymorphicReflection.new(macro, name, options, active_record)
|
18
|
+
end
|
19
|
+
write_inheritable_hash :reflections, name => reflection
|
20
|
+
reflection
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class PolymorphicError < ActiveRecordError #:nodoc:
|
26
|
+
end
|
27
|
+
|
28
|
+
=begin rdoc
|
29
|
+
|
30
|
+
The reflection built by the <tt>has_many_polymorphs</tt> method.
|
31
|
+
|
32
|
+
Inherits from ActiveRecord::Reflection::AssociationReflection.
|
33
|
+
|
34
|
+
=end
|
35
|
+
|
36
|
+
class PolymorphicReflection < ThroughReflection
|
37
|
+
# Stub out the validity check. Has_many_polymorphs checks validity on macro creation, not on reflection.
|
38
|
+
def check_validity!
|
39
|
+
# nothing
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return the source reflection.
|
43
|
+
def source_reflection
|
44
|
+
# normally is the has_many to the through model, but we return ourselves,
|
45
|
+
# since there isn't a real source class for a polymorphic target
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
# Set the classname of the target. Uses the join class name.
|
50
|
+
def class_name
|
51
|
+
# normally is the classname of the association target
|
52
|
+
@class_name ||= options[:join_class_name]
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
class String
|
3
|
+
|
4
|
+
# Changes an underscored string into a class reference.
|
5
|
+
def _as_class
|
6
|
+
# classify expects self to be plural
|
7
|
+
self.classify.constantize
|
8
|
+
end
|
9
|
+
|
10
|
+
# For compatibility with the Symbol extensions.
|
11
|
+
alias :_singularize :singularize
|
12
|
+
alias :_pluralize :pluralize
|
13
|
+
alias :_classify :classify
|
14
|
+
end
|
15
|
+
|
16
|
+
class Symbol
|
17
|
+
|
18
|
+
# Changes an underscored symbol into a class reference.
|
19
|
+
def _as_class; self.to_s._as_class; end
|
20
|
+
|
21
|
+
# Changes a plural symbol into a singular symbol.
|
22
|
+
def _singularize; self.to_s.singularize.to_sym; end
|
23
|
+
|
24
|
+
# Changes a singular symbol into a plural symbol.
|
25
|
+
def _pluralize; self.to_s.pluralize.to_sym; end
|
26
|
+
|
27
|
+
# Changes a symbol into a class name string.
|
28
|
+
def _classify; self.to_s.classify; end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Array
|
32
|
+
|
33
|
+
# Flattens the first level of self.
|
34
|
+
def _flatten_once
|
35
|
+
self.inject([]){|r, el| r + Array(el)}
|
36
|
+
end
|
37
|
+
|
38
|
+
# Rails 1.2.3 compatibility method. Copied from http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/array/extract_options.rb?rev=7217
|
39
|
+
def _extract_options!
|
40
|
+
last.is_a?(::Hash) ? pop : {}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Hash
|
45
|
+
|
46
|
+
# An implementation of select that returns a Hash.
|
47
|
+
def _select
|
48
|
+
if RUBY_VERSION >= "1.9"
|
49
|
+
Hash[*self.select {|k, v| yield k, v }.flatten]
|
50
|
+
else
|
51
|
+
Hash[*self.select do |key, value|
|
52
|
+
yield key, value
|
53
|
+
end._flatten_once]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Object
|
59
|
+
|
60
|
+
# Returns the metaclass of self.
|
61
|
+
def _metaclass; (class << self; self; end); end
|
62
|
+
|
63
|
+
# Logger shortcut.
|
64
|
+
def _logger_debug s
|
65
|
+
s = "** has_many_polymorphs: #{s}"
|
66
|
+
RAILS_DEFAULT_LOGGER.debug(s) if RAILS_DEFAULT_LOGGER
|
67
|
+
end
|
68
|
+
|
69
|
+
# Logger shortcut.
|
70
|
+
def _logger_warn s
|
71
|
+
s = "** has_many_polymorphs: #{s}"
|
72
|
+
if RAILS_DEFAULT_LOGGER
|
73
|
+
RAILS_DEFAULT_LOGGER.warn(s)
|
74
|
+
else
|
75
|
+
$stderr.puts(s)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
class ActiveRecord::Base
|
82
|
+
|
83
|
+
# Return the base class name as a string.
|
84
|
+
def _base_class_name
|
85
|
+
self.class.base_class.name.to_s
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
RAILS_DEFAULT_LOGGER = nil unless defined? RAILS_DEFAULT_LOGGER
|
5
|
+
|
6
|
+
require 'has_many_polymorphs/reflection'
|
7
|
+
require 'has_many_polymorphs/association'
|
8
|
+
require 'has_many_polymorphs/class_methods'
|
9
|
+
|
10
|
+
require 'has_many_polymorphs/support_methods'
|
11
|
+
require 'has_many_polymorphs/base'
|
12
|
+
|
13
|
+
class ActiveRecord::Base
|
14
|
+
extend ActiveRecord::Associations::PolymorphicClassMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
if ENV['HMP_DEBUG'] || ENV['RAILS_ENV'] =~ /development|test/ && ENV['USER'] == 'eweaver'
|
18
|
+
require 'has_many_polymorphs/debugging_tools'
|
19
|
+
end
|
20
|
+
|
21
|
+
if defined? Rails and RAILS_ENV and RAILS_ROOT
|
22
|
+
_logger_warn "rails environment detected"
|
23
|
+
require 'has_many_polymorphs/configuration'
|
24
|
+
require 'has_many_polymorphs/autoload'
|
25
|
+
end
|
26
|
+
|
27
|
+
_logger_debug "loaded ok"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
chloe:
|
2
|
+
id: 1
|
3
|
+
cat_type: Kitten
|
4
|
+
name: Chloe
|
5
|
+
created_at: "2007-04-01 12:00:00"
|
6
|
+
updated_at: "2007-04-04 10:00:00"
|
7
|
+
alice:
|
8
|
+
id: 2
|
9
|
+
cat_type: Kitten
|
10
|
+
name: Alice
|
11
|
+
created_at: "2007-04-02 12:00:00"
|
12
|
+
updated_at: "2007-04-03 10:00:00"
|
13
|
+
toby:
|
14
|
+
id: 3
|
15
|
+
cat_type: Tabby
|
16
|
+
name: Toby
|
17
|
+
created_at: "2007-04-02 12:00:00"
|
18
|
+
updated_at: "2007-04-03 10:00:00"
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
|
4
|
+
class TaggingGeneratorTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
Dir.chdir RAILS_ROOT do
|
8
|
+
truncate
|
9
|
+
|
10
|
+
# Revert environment lib requires
|
11
|
+
FileUtils.cp "config/environment.rb.canonical", "config/environment.rb"
|
12
|
+
|
13
|
+
# Delete generator output
|
14
|
+
["app/models/tag.rb", "app/models/tagging.rb",
|
15
|
+
"test/unit/tag_test.rb", "test/unit/tagging_test.rb",
|
16
|
+
"test/fixtures/tags.yml", "test/fixtures/taggings.yml",
|
17
|
+
"lib/tagging_extensions.rb",
|
18
|
+
"db/migrate/010_create_tags_and_taggings.rb"].each do |file|
|
19
|
+
File.delete file if File.exist? file
|
20
|
+
end
|
21
|
+
|
22
|
+
# Rebuild database
|
23
|
+
Echoe.silence do
|
24
|
+
system("ruby #{HERE}/setup.rb")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
alias :teardown :setup
|
30
|
+
|
31
|
+
def test_generator
|
32
|
+
Dir.chdir RAILS_ROOT do
|
33
|
+
Echoe.silence do
|
34
|
+
assert system("script/generate tagging Stick Stone -q -f")
|
35
|
+
assert system("rake db:migrate")
|
36
|
+
assert system("rake db:fixtures:load")
|
37
|
+
assert system("rake test:units")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application and persistence framework that includes everything
|
4
|
+
needed to create database-backed web-applications according to the
|
5
|
+
Model-View-Control pattern of separation. This pattern splits the view (also
|
6
|
+
called the presentation) into "dumb" templates that are primarily responsible
|
7
|
+
for inserting pre-built data in between HTML tags. The model contains the
|
8
|
+
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
9
|
+
the business logic and knows how to persist themselves to a database. The
|
10
|
+
controller handles the incoming requests (such as Save New Account, Update
|
11
|
+
Product, Show Post) by manipulating the model and directing data to the view.
|
12
|
+
|
13
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
14
|
+
layer entitled Active Record. This layer allows you to present the data from
|
15
|
+
database rows as objects and embellish these data objects with business logic
|
16
|
+
methods. You can read more about Active Record in
|
17
|
+
link:files/vendor/rails/activerecord/README.html.
|
18
|
+
|
19
|
+
The controller and view are handled by the Action Pack, which handles both
|
20
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
21
|
+
are bundled in a single package due to their heavy interdependence. This is
|
22
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
23
|
+
more separate. Each of these packages can be used independently outside of
|
24
|
+
Rails. You can read more about Action Pack in
|
25
|
+
link:files/vendor/rails/actionpack/README.html.
|
26
|
+
|
27
|
+
|
28
|
+
== Getting started
|
29
|
+
|
30
|
+
1. At the command prompt, start a new rails application using the rails command
|
31
|
+
and your application name. Ex: rails myapp
|
32
|
+
(If you've downloaded rails in a complete tgz or zip, this step is already done)
|
33
|
+
2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
|
34
|
+
3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
|
35
|
+
4. Follow the guidelines to start developing your application
|
36
|
+
|
37
|
+
|
38
|
+
== Web Servers
|
39
|
+
|
40
|
+
By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
|
41
|
+
Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server,
|
42
|
+
Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
|
43
|
+
that you can always get up and running quickly.
|
44
|
+
|
45
|
+
Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is
|
46
|
+
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
|
47
|
+
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
|
48
|
+
More info at: http://mongrel.rubyforge.org
|
49
|
+
|
50
|
+
If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
|
51
|
+
Mongrel and WEBrick and also suited for production use, but requires additional
|
52
|
+
installation and currently only works well on OS X/Unix (Windows users are encouraged
|
53
|
+
to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
|
54
|
+
http://www.lighttpd.net.
|
55
|
+
|
56
|
+
And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
|
57
|
+
web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
|
58
|
+
for production.
|
59
|
+
|
60
|
+
But of course its also possible to run Rails on any platform that supports FCGI.
|
61
|
+
Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
|
62
|
+
please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
|
63
|
+
|
64
|
+
|
65
|
+
== Debugging Rails
|
66
|
+
|
67
|
+
Have "tail -f" commands running on the server.log and development.log. Rails will
|
68
|
+
automatically display debugging and runtime information to these files. Debugging
|
69
|
+
info will also be shown in the browser on requests from 127.0.0.1.
|
70
|
+
|
71
|
+
|
72
|
+
== Breakpoints
|
73
|
+
|
74
|
+
Breakpoint support is available through the script/breakpointer client. This
|
75
|
+
means that you can break out of execution at any point in the code, investigate
|
76
|
+
and change the model, AND then resume execution! Example:
|
77
|
+
|
78
|
+
class WeblogController < ActionController::Base
|
79
|
+
def index
|
80
|
+
@posts = Post.find(:all)
|
81
|
+
breakpoint "Breaking out from the list"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
So the controller will accept the action, run the first line, then present you
|
86
|
+
with a IRB prompt in the breakpointer window. Here you can do things like:
|
87
|
+
|
88
|
+
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
89
|
+
|
90
|
+
>> @posts.inspect
|
91
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
92
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
93
|
+
>> @posts.first.title = "hello from a breakpoint"
|
94
|
+
=> "hello from a breakpoint"
|
95
|
+
|
96
|
+
...and even better is that you can examine how your runtime objects actually work:
|
97
|
+
|
98
|
+
>> f = @posts.first
|
99
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
100
|
+
>> f.
|
101
|
+
Display all 152 possibilities? (y or n)
|
102
|
+
|
103
|
+
Finally, when you're ready to resume execution, you press CTRL-D
|
104
|
+
|
105
|
+
|
106
|
+
== Console
|
107
|
+
|
108
|
+
You can interact with the domain model by starting the console through <tt>script/console</tt>.
|
109
|
+
Here you'll have all parts of the application configured, just like it is when the
|
110
|
+
application is running. You can inspect domain models, change values, and save to the
|
111
|
+
database. Starting the script without arguments will launch it in the development environment.
|
112
|
+
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
113
|
+
|
114
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
115
|
+
|
116
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
== Description of contents
|
121
|
+
|
122
|
+
app
|
123
|
+
Holds all the code that's specific to this particular application.
|
124
|
+
|
125
|
+
app/controllers
|
126
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
127
|
+
automated URL mapping. All controllers should descend from ApplicationController
|
128
|
+
which itself descends from ActionController::Base.
|
129
|
+
|
130
|
+
app/models
|
131
|
+
Holds models that should be named like post.rb.
|
132
|
+
Most models will descend from ActiveRecord::Base.
|
133
|
+
|
134
|
+
app/views
|
135
|
+
Holds the template files for the view that should be named like
|
136
|
+
weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby
|
137
|
+
syntax.
|
138
|
+
|
139
|
+
app/views/layouts
|
140
|
+
Holds the template files for layouts to be used with views. This models the common
|
141
|
+
header/footer method of wrapping views. In your views, define a layout using the
|
142
|
+
<tt>layout :default</tt> and create a file named default.rhtml. Inside default.rhtml,
|
143
|
+
call <% yield %> to render the view using this layout.
|
144
|
+
|
145
|
+
app/helpers
|
146
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are generated
|
147
|
+
for you automatically when using script/generate for controllers. Helpers can be used to
|
148
|
+
wrap functionality for your views into methods.
|
149
|
+
|
150
|
+
config
|
151
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
152
|
+
|
153
|
+
components
|
154
|
+
Self-contained mini-applications that can bundle together controllers, models, and views.
|
155
|
+
|
156
|
+
db
|
157
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
158
|
+
the sequence of Migrations for your schema.
|
159
|
+
|
160
|
+
doc
|
161
|
+
This directory is where your application documentation will be stored when generated
|
162
|
+
using <tt>rake doc:app</tt>
|
163
|
+
|
164
|
+
lib
|
165
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
166
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
167
|
+
|
168
|
+
public
|
169
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
170
|
+
and javascripts. Also contains the dispatchers and the default HTML files. This should be
|
171
|
+
set as the DOCUMENT_ROOT of your web server.
|
172
|
+
|
173
|
+
script
|
174
|
+
Helper scripts for automation and generation.
|
175
|
+
|
176
|
+
test
|
177
|
+
Unit and functional tests along with fixtures. When using the script/generate scripts, template
|
178
|
+
test files will be generated for you and placed in this directory.
|
179
|
+
|
180
|
+
vendor
|
181
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
182
|
+
This directory is in the load path.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
require 'tasks/rails'
|
11
|
+
|
12
|
+
namespace :test do
|
13
|
+
desc "a new rake task to include generators"
|
14
|
+
Rake::TestTask.new(:generators) do |t|
|
15
|
+
t.libs << 'lib'
|
16
|
+
t.test_files = FileList['test/generators/*_test.rb']
|
17
|
+
t.verbose = true
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
# Pick a unique cookie name to distinguish our session data from others'
|
6
|
+
session :session_key => '_testapp_session_id'
|
7
|
+
end
|