mack-active_record 0.6.1.2 → 0.7.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 (42) hide show
  1. data/doc/classes/Mack/Database/Generators.html +140 -0
  2. data/doc/classes/Mack/Database/{Migrator.html → Migrations.html} +74 -39
  3. data/doc/classes/Mack/Database.html +158 -61
  4. data/doc/classes/Mack/Testing/ActiveRecordHelpers.html +168 -0
  5. data/doc/classes/Mack/ViewHelpers/ActiveRecordHelpers.html +52 -52
  6. data/doc/classes/Mack.html +8 -15
  7. data/doc/created.rid +1 -1
  8. data/doc/files/lib/mack-active_record/{genosaurus_helpers_rb.html → database_migrations_rb.html} +4 -4
  9. data/doc/files/lib/mack-active_record/database_rb.html +1 -11
  10. data/doc/files/lib/mack-active_record/{model_column_rb.html → generators_rb.html} +4 -4
  11. data/doc/files/lib/mack-active_record/helpers/orm_helpers_rb.html +1 -1
  12. data/doc/files/lib/mack-active_record/{scaffold_generator/scaffold_generator_rb.html → test_extensions_rb.html} +12 -17
  13. data/doc/files/lib/mack-active_record_rb.html +2 -1
  14. data/doc/files/lib/mack-active_record_tasks_rb.html +8 -1
  15. data/doc/fr_class_index.html +3 -5
  16. data/doc/fr_file_index.html +3 -3
  17. data/doc/fr_method_index.html +11 -14
  18. data/lib/mack-active_record/database.rb +81 -59
  19. data/lib/mack-active_record/database_migrations.rb +29 -0
  20. data/lib/mack-active_record/generators.rb +11 -0
  21. data/lib/mack-active_record/helpers/orm_helpers.rb +9 -12
  22. data/lib/mack-active_record/model_generator/manifest.yml +2 -2
  23. data/lib/mack-active_record/tasks/db_migration_tasks.rake +2 -15
  24. data/lib/mack-active_record/test_extensions.rb +101 -0
  25. data/lib/mack-active_record.rb +4 -3
  26. data/lib/mack-active_record_tasks.rb +1 -0
  27. metadata +22 -22
  28. data/doc/classes/Mack/Genosaurus/ActiveRecord/Helpers.html +0 -225
  29. data/doc/classes/Mack/Genosaurus/ActiveRecord/ModelColumn.html +0 -299
  30. data/doc/classes/Mack/ViewHelpers.html +0 -111
  31. data/doc/classes/ScaffoldGenerator.html +0 -123
  32. data/lib/mack-active_record/genosaurus_helpers.rb +0 -40
  33. data/lib/mack-active_record/model_column.rb +0 -55
  34. data/lib/mack-active_record/scaffold_generator/manifest.yml +0 -31
  35. data/lib/mack-active_record/scaffold_generator/scaffold_generator.rb +0 -42
  36. data/lib/mack-active_record/scaffold_generator/templates/app/views/edit.html.erb.template +0 -19
  37. data/lib/mack-active_record/scaffold_generator/templates/app/views/index.html.erb.template +0 -41
  38. data/lib/mack-active_record/scaffold_generator/templates/app/views/new.html.erb.template +0 -19
  39. data/lib/mack-active_record/scaffold_generator/templates/app/views/show.html.erb.template +0 -12
  40. data/lib/mack-active_record/scaffold_generator/templates/spec.rb.template +0 -47
  41. data/lib/mack-active_record/scaffold_generator/templates/test.rb.template +0 -9
  42. data/lib/mack-active_record/tasks/db_create_drop_tasks.rake +0 -52
@@ -1,123 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Class: ScaffoldGenerator</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Class</strong></td>
53
- <td class="class-name-in-header">ScaffoldGenerator</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../files/lib/mack-active_record/scaffold_generator/scaffold_generator_rb.html">
59
- lib/mack-active_record/scaffold_generator/scaffold_generator.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- <tr class="top-aligned-row">
66
- <td><strong>Parent:</strong></td>
67
- <td>
68
- Genosaurus
69
- </td>
70
- </tr>
71
- </table>
72
- </div>
73
- <!-- banner header -->
74
-
75
- <div id="bodyContent">
76
-
77
-
78
-
79
- <div id="contextContent">
80
-
81
- <div id="description">
82
- <p>
83
- Generates scaffold for <a href="Mack.html">Mack</a> applications.
84
- </p>
85
- <p>
86
- Example:
87
- </p>
88
- <pre>
89
- rake generate:scaffold name=post
90
- </pre>
91
-
92
- </div>
93
-
94
-
95
- </div>
96
-
97
-
98
- </div>
99
-
100
-
101
- <!-- if includes -->
102
-
103
- <div id="section">
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
- <!-- if method_list -->
113
-
114
-
115
- </div>
116
-
117
-
118
- <div id="validator-badges">
119
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
120
- </div>
121
-
122
- </body>
123
- </html>
@@ -1,40 +0,0 @@
1
- module Mack
2
- module Genosaurus # :nodoc:
3
- module ActiveRecord # :nodoc:
4
- module Helpers
5
-
6
- def columns(name = param(:name))
7
- ivar_cache("form_columns") do
8
- cs = []
9
- cols = (param(:cols) || param(:columns))
10
- if cols
11
- cols.split(",").each do |x|
12
- cs << Mack::Genosaurus::ActiveRecord::ModelColumn.new(name, x)
13
- end
14
- end
15
- cs
16
- end
17
- end
18
-
19
- def db_directory
20
- File.join(Mack.root, "db")
21
- end
22
-
23
- def migrations_directory
24
- File.join(db_directory, "migrations")
25
- end
26
-
27
- def next_migration_number
28
- last = Dir.glob(File.join(migrations_directory, "*.rb")).last
29
- if last
30
- return File.basename(last).match(/^\d+/).to_s.succ
31
- end
32
- return "001"
33
- end
34
-
35
- ::Genosaurus.send(:include, self)
36
-
37
- end # Helpers
38
- end # ActiveRecord
39
- end # Genosaurus
40
- end # Mack
@@ -1,55 +0,0 @@
1
- module Mack
2
- module Genosaurus
3
- module ActiveRecord
4
- # Used to represent a 'column' from the param cols or columns for generators.
5
- class ModelColumn
6
-
7
- # The name of the column.
8
- attr_accessor :column_name
9
- # The type of the column. Ie. string, integer, datetime, etc...
10
- attr_accessor :column_type
11
- # The name of the model associated with the column. Ie. user, post, etc...
12
- attr_accessor :model_name
13
-
14
- # Takes in the model_name (user, post, etc...) and the column (username:string, body:text, etc...)
15
- def initialize(model_name, column_unsplit)
16
- self.model_name = model_name.singular.underscore
17
- cols = column_unsplit.split(":")
18
- self.column_name = cols.first#.underscore
19
- self.column_type = cols.last#.underscore
20
- end
21
-
22
- # Examples:
23
- # Mack::Generator::ColumnObject.new("user", "username:string").form_element_name # => "user[username]"
24
- # Mack::Generator::ColumnObject.new("Post", "body:text").form_element_name # => "post[body]"
25
- def form_element_name
26
- "#{self.model_name}[#{self.column_name}]"
27
- end
28
-
29
- # Examples:
30
- # Mack::Generator::ColumnObject.new("user", "username:string").form_element_id # => "user_username"
31
- # Mack::Generator::ColumnObject.new("Post", "body:text").form_element_id # => "post_body"
32
- def form_element_id
33
- "#{self.model_name}_#{self.column_name}"
34
- end
35
-
36
- # Generates the appropriate HTML form field for the type of column represented.
37
- #
38
- # Examples:
39
- # Mack::Generator::ColumnObject.new("user", "username:string").form_field
40
- # => "<input type="text" name="user[username]" id="user_username" size="30" value="<%= user.username %>" />"
41
- # Mack::Generator::ColumnObject.new("Post", "body:text").form_field
42
- # => "<textarea name="post[body]" id="post_id"><%= post.body %></textarea>"
43
- def form_field
44
- case self.column_type
45
- when "text"
46
- %{<textarea name="#{self.form_element_name}" id="#{self.form_element_id}" cols="60" rows="20"><%= @#{self.model_name}.#{self.column_name} %></textarea>}
47
- else
48
- %{<input type="text" name="#{self.form_element_name}" id="#{self.form_element_id}" size="30" value="<%= @#{self.model_name}.#{self.column_name} %>" />}
49
- end
50
- end
51
-
52
- end # ModelColumn
53
- end # ActiveRecord
54
- end # Generator
55
- end # Mack
@@ -1,31 +0,0 @@
1
- controller_template:
2
- type: file
3
- template_path: <%= File.join(templates_directory_path, "app", "controllers", "controller.rb.template") %>
4
- output_path: <%= File.join("app", "controllers", "#{@name_plural}_controller.rb") %>
5
- edit_template:
6
- type: file
7
- template_path: <%= File.join(templates_directory_path, "app", "views", "edit.html.erb.template") %>
8
- output_path: <%= File.join("app", "views", @name_plural, "edit.html.erb") %>
9
- index_template:
10
- type: file
11
- template_path: <%= File.join(templates_directory_path, "app", "views", "index.html.erb.template") %>
12
- output_path: <%= File.join("app", "views", @name_plural, "index.html.erb") %>
13
- new_template:
14
- type: file
15
- template_path: <%= File.join(templates_directory_path, "app", "views", "new.html.erb.template") %>
16
- output_path: <%= File.join("app", "views", @name_plural, "new.html.erb") %>
17
- show_template:
18
- type: file
19
- template_path: <%= File.join(templates_directory_path, "app", "views", "show.html.erb.template") %>
20
- output_path: <%= File.join("app", "views", @name_plural, "show.html.erb") %>
21
- <% if @test_framework == "test_case" -%>
22
- functional_test_template:
23
- type: file
24
- template_path: <%= File.join(templates_directory_path, "test.rb.template") %>
25
- output_path: <%= File.join("test", "functional", "#{@name_plural}_controller_test.rb") %>
26
- <% elsif @test_framework == "rspec" -%>
27
- functional_test_template:
28
- type: file
29
- template_path: <%= File.join(templates_directory_path, "spec.rb.template") %>
30
- output_path: <%= File.join("test", "functional", "#{@name_plural}_controller_spec.rb") %>
31
- <% end -%>
@@ -1,42 +0,0 @@
1
- # Generates scaffold for Mack applications.
2
- #
3
- # Example:
4
- # rake generate:scaffold name=post
5
- class ScaffoldGenerator < Genosaurus
6
-
7
- require_param :name
8
-
9
- def setup # :nodoc:
10
- @name_singular = param(:name).singular.underscore
11
- @name_plural = param(:name).plural.underscore
12
- @name_singular_camel = @name_singular.camelcase
13
- @name_plural_camel = @name_plural.camelcase
14
- @test_framework = app_config.mack.testing_framework
15
- end
16
-
17
- def after_generate # :nodoc:
18
- ModelGenerator.run(@options)
19
- update_routes_file
20
- end
21
-
22
- def update_routes_file # :nodoc:
23
- # update routes.rb
24
- routes = File.join(Mack.root, "config", "routes.rb")
25
- rf = File.open(routes).read
26
- unless rf.match(".resource :#{@name_plural}")
27
- puts "Updating routes.rb"
28
- nrf = ""
29
- rf.each do |line|
30
- if line.match("Mack::Routes.build")
31
- x = line.match(/\|(.+)\|/).captures
32
- line << "\n #{x}.resource :#{@name_plural} # Added by rake generate:scaffold name=#{param(:name)}\n"
33
- end
34
- nrf << line
35
- end
36
- File.open(routes, "w") do |f|
37
- f.puts nrf
38
- end
39
- end
40
- end
41
-
42
- end
@@ -1,19 +0,0 @@
1
- <h1>Edit <%= @name_singular_camel %></h1>
2
-
3
- <%%= error_messages_for :<%= @name_singular %> %>
4
-
5
- <%% form(<%= @name_singular %>s_update_url(:id => @<%= @name_singular %>.id), :class => "edit_<%= @name_singular %>", :id => "edit_<%= @name_singular %>", :method => :put) do %>
6
- <% for column in columns -%>
7
- <% unless column.column_name == "created_at" || column.column_name == "updated_at" -%>
8
- <p>
9
- <b><%= column.column_name.singular.camelcase %></b><br />
10
- <%= column.form_field %>
11
- </p>
12
- <% end -%>
13
- <% end -%>
14
- <p>
15
- <input id="<%= @name_singular %>_submit" name="commit" type="submit" value="Update" />
16
- </p>
17
- <%% end %>
18
-
19
- <%%= link_to("Back", <%= @name_singular %>s_index_url) %>
@@ -1,41 +0,0 @@
1
- <h1>Listing <%= @name_plural_camel %></h1>
2
-
3
- <table>
4
- <tr>
5
- <%
6
- unless columns.empty?
7
- columns.each do |col|
8
- -%>
9
- <th><%= col.column_name.camelcase %></th>
10
- <%
11
- end
12
- else
13
- -%>
14
- <th>&nbsp;</th>
15
- <%
16
- end
17
- -%>
18
- </tr>
19
-
20
- <%% for <%= @name_singular %> in @<%= @name_plural %> %>
21
- <tr>
22
- <%
23
- unless columns.empty?
24
- columns.each do |col| -%>
25
- <td><%%= <%= @name_singular %>.<%= col.column_name %> %></td>
26
- <%
27
- end
28
- else
29
- -%>
30
- <td>&nbsp;</td>
31
- <% end -%>
32
- <td><%%= link_to("Show", <%= @name_plural %>_show_url(:id => <%= @name_singular %>.id)) %></td>
33
- <td><%%= link_to("Edit", <%= @name_plural %>_edit_url(:id => <%= @name_singular %>.id)) %></td>
34
- <td><%%= link_to("Delete", <%= @name_plural %>_delete_url(:id => <%= @name_singular %>.id), :method => :delete, :confirm => "Are you sure?") %></td>
35
- </tr>
36
- <%% end %>
37
- </table>
38
-
39
- <br />
40
-
41
- <%%= link_to("New <%= @name_singular_camel %>", <%= @name_plural %>_new_url) %>
@@ -1,19 +0,0 @@
1
- <h1>New <%= @name_singular_camel %></h1>
2
-
3
- <%%= error_messages_for :<%= @name_singular %> %>
4
-
5
- <%% form(<%= @name_singular %>s_create_url, :class => "new_<%= @name_singular %>", :id => "new_<%= @name_singular %>") do %>
6
- <% for column in columns -%>
7
- <% unless column.column_name == "created_at" || column.column_name == "updated_at" -%>
8
- <p>
9
- <b><%= column.column_name.singular.camelcase %></b><br />
10
- <%= column.form_field %>
11
- </p>
12
- <% end -%>
13
- <% end -%>
14
- <p>
15
- <input id="<%= @name_singular %>_submit" name="commit" type="submit" value="Create" />
16
- </p>
17
- <%% end %>
18
-
19
- <%%= link_to("Back", <%= @name_singular %>s_index_url) %>
@@ -1,12 +0,0 @@
1
- <p>
2
- <h1><%= @name_singular_camel %></h1>
3
- </p>
4
- <% for column in columns -%>
5
- <p>
6
- <b><%= column.column_name.singular.camelcase %></b><br />
7
- <%%= @<%= @name_singular %>.<%= column.column_name %> %>
8
- </p>
9
- <% end -%>
10
-
11
- <%%= link_to("Edit", <%= @name_plural %>_edit_url(:id => @<%= @name_singular %>.id)) %> |
12
- <%%= link_to("Back", <%= @name_plural %>_index_url) %>
@@ -1,47 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
-
3
- describe <%= @name_plural_camel %>Controller do
4
-
5
- describe "index" do
6
-
7
- it "should list <%= @name_plural %>"
8
-
9
- end
10
-
11
- describe "show" do
12
-
13
- it "should show a <%= @name_singular %>"
14
-
15
- end
16
-
17
- describe "new" do
18
-
19
- it "should show a form to create a new <%= @name_singular %>"
20
-
21
- end
22
-
23
- describe "edit" do
24
-
25
- it "should edit a <%= @name_singular %>"
26
-
27
- end
28
-
29
- describe "create" do
30
-
31
- it "should create a <%= @name_singular %>"
32
-
33
- end
34
-
35
- describe "update" do
36
-
37
- it "should update a <%= @name_singular %>"
38
-
39
- end
40
-
41
- describe "delete" do
42
-
43
- it "should delete a <%= @name_singular %>"
44
-
45
- end
46
-
47
- end
@@ -1,9 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- class <%= @name_plural_camel %>ControllerTest < Test::Unit::TestCase
4
-
5
- def test_truth
6
- assert true
7
- end
8
-
9
- end
@@ -1,52 +0,0 @@
1
- require 'rake'
2
- namespace :db do
3
-
4
- task :drop => :environment do
5
- Mack::Database.drop_or_create_database(Mack.env, :drop)
6
- end
7
-
8
- namespace :drop do
9
- desc "Drop databases for both development and test environemnt"
10
- task :all => :environment do
11
- Mack::Database.drop_or_create_database("development", :drop)
12
- Mack::Database.drop_or_create_database("test", :drop)
13
- end
14
- end
15
-
16
- task :create do
17
- puts Mack.env
18
- Mack::Database.drop_or_create_database(Mack.env, :create)
19
- end
20
-
21
- task :recreate do
22
- puts Mack.env
23
- Mack::Database.drop_or_create_database(Mack.env, :drop_and_create)
24
- end
25
-
26
- namespace :create do
27
- desc "Creates your Full environment. Does NOT create your production database!"
28
- task :all => :environment do
29
- abcs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
30
- db_settings = abcs[Mack.env]
31
-
32
- Mack::Database.drop_or_create_database("development", :create)
33
- Mack::Database.drop_or_create_database("test", :create)
34
- ActiveRecord::Base.establish_connection(db_settings)
35
- Rake::Task["db:migrate"].invoke
36
- end
37
- end
38
-
39
- namespace :recreate do
40
- desc "Creates your Full environment. Does NOT create your production database!"
41
- task :all => :environment do
42
- abcs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
43
- db_settings = abcs[Mack.env]
44
-
45
- Mack::Database.drop_or_create_database("development")
46
- Mack::Database.drop_or_create_database("test")
47
- ActiveRecord::Base.establish_connection(db_settings)
48
- Rake::Task["db:migrate"].invoke
49
- end
50
- end
51
-
52
- end