mack-data_mapper 0.6.1.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/doc/classes/Mack.html +6 -6
  2. data/doc/classes/Mack/Database.html +119 -18
  3. data/doc/classes/Mack/Database/Generators.html +140 -0
  4. data/doc/classes/Mack/Database/Migrations.html +206 -0
  5. data/doc/classes/Mack/Testing/DataMapperHelpers.html +6 -6
  6. data/doc/classes/Mack/ViewHelpers/DataMapperHelpers.html +30 -124
  7. data/doc/created.rid +1 -1
  8. data/doc/files/lib/mack-data_mapper/database_migrations_rb.html +115 -0
  9. data/doc/files/lib/mack-data_mapper/database_rb.html +1 -1
  10. data/doc/files/lib/mack-data_mapper/dm_patches/dm-timestamps_rb.html +1 -1
  11. data/doc/files/lib/mack-data_mapper/dm_patches/migrations_rb.html +1 -1
  12. data/doc/files/lib/mack-data_mapper/{genosaurus_helpers_rb.html → dm_patches/model_rb.html} +5 -5
  13. data/doc/files/lib/mack-data_mapper/{scaffold_generator/scaffold_generator_rb.html → dm_patches/property_set_rb.html} +4 -17
  14. data/doc/{classes/DataMapper/Timestamp.html → files/lib/mack-data_mapper/dm_patches/validations_rb.html} +16 -20
  15. data/doc/files/lib/mack-data_mapper/{model_column_rb.html → generators_rb.html} +4 -4
  16. data/doc/files/lib/mack-data_mapper/helpers/orm_helpers_rb.html +1 -1
  17. data/doc/files/lib/mack-data_mapper/migration_generator/migration_generator_rb.html +1 -1
  18. data/doc/files/lib/mack-data_mapper/model_generator/model_generator_rb.html +1 -1
  19. data/doc/files/lib/mack-data_mapper_rb.html +2 -1
  20. data/doc/files/lib/mack-data_mapper_tasks_rb.html +8 -1
  21. data/doc/fr_class_index.html +2 -2
  22. data/doc/fr_file_index.html +5 -3
  23. data/doc/fr_method_index.html +10 -7
  24. data/lib/mack-data_mapper.rb +4 -5
  25. data/lib/mack-data_mapper/database.rb +79 -38
  26. data/lib/mack-data_mapper/database_migrations.rb +35 -0
  27. data/lib/mack-data_mapper/dm_patches/dm-timestamps.rb +4 -4
  28. data/lib/mack-data_mapper/dm_patches/migrations.rb +24 -2
  29. data/lib/mack-data_mapper/dm_patches/model.rb +48 -0
  30. data/lib/mack-data_mapper/dm_patches/property_set.rb +15 -0
  31. data/lib/mack-data_mapper/dm_patches/validations.rb +15 -0
  32. data/lib/mack-data_mapper/generators.rb +11 -0
  33. data/lib/mack-data_mapper/helpers/orm_helpers.rb +8 -32
  34. data/lib/mack-data_mapper/migration_generator/migration_generator.rb +1 -1
  35. data/lib/mack-data_mapper/model_generator/manifest.yml +2 -2
  36. data/lib/mack-data_mapper/model_generator/model_generator.rb +1 -1
  37. data/lib/mack-data_mapper_tasks.rb +1 -0
  38. metadata +42 -29
  39. data/doc/classes/ScaffoldGenerator.html +0 -123
  40. data/lib/mack-data_mapper/genosaurus_helpers.rb +0 -40
  41. data/lib/mack-data_mapper/model_column.rb +0 -42
  42. data/lib/mack-data_mapper/scaffold_generator/manifest.yml +0 -35
  43. data/lib/mack-data_mapper/scaffold_generator/scaffold_generator.rb +0 -41
  44. data/lib/mack-data_mapper/scaffold_generator/templates/app/helpers/controllers/helper.rb.template +0 -7
  45. data/lib/mack-data_mapper/scaffold_generator/templates/app/views/edit.html.erb.template +0 -19
  46. data/lib/mack-data_mapper/scaffold_generator/templates/app/views/index.html.erb.template +0 -41
  47. data/lib/mack-data_mapper/scaffold_generator/templates/app/views/new.html.erb.template +0 -19
  48. data/lib/mack-data_mapper/scaffold_generator/templates/app/views/show.html.erb.template +0 -12
  49. data/lib/mack-data_mapper/scaffold_generator/templates/test/functional/rspec.rb.template +0 -47
  50. data/lib/mack-data_mapper/scaffold_generator/templates/test/functional/test_case.rb.template +0 -9
  51. data/lib/mack-data_mapper/tasks/db_create_drop_tasks.rake +0 -57
  52. data/lib/mack-data_mapper/tasks/db_migration_tasks.rake +0 -46
  53. data/lib/mack-data_mapper/tasks/test_tasks.rake +0 -12
@@ -1,42 +0,0 @@
1
- module Mack
2
- module Genosaurus # :nodoc:
3
- module DataMapper # :nodoc:
4
- # Used to represent a 'column' from the param cols or columns for generators.
5
- class ModelColumn # :nodoc:
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
- # Generates the appropriate HTML form field for the type of column represented.
23
- #
24
- # Examples:
25
- # Mack::Generator::ColumnObject.new("user", "username:string").form_field
26
- # => "<%= model_text_field(@user, :username) %>"
27
- # Mack::Generator::ColumnObject.new("Post", "body:text").form_field
28
- # => "<%= model_textarea(@user, :username) %>"
29
- def form_field
30
- case self.column_type
31
- when "text"
32
- %{<%= model_textarea(@#{self.model_name}, :#{self.column_name}) %>}
33
- else
34
- %{<%= model_text_field(@#{self.model_name}, :#{self.column_name}) %>}
35
- end
36
- end
37
-
38
- end # ModelColumn
39
- end # DataMapper
40
-
41
- end # Generator
42
- end # Mack
@@ -1,35 +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
- helper_template:
22
- type: file
23
- template_path: <%= File.join(templates_directory_path, "app", "helpers", "controllers", "helper.rb.template") %>
24
- output_path: <%= File.join("app", "helpers", "controllers", "#{@name_plural}_controller_helper.rb") %>
25
- <% if app_config.mack.testing_framework == "test_case" -%>
26
- functional_test_template:
27
- type: file
28
- template_path: <%= File.join(templates_directory_path, "test", "functional", "test_case.rb.template") %>
29
- output_path: <%= File.join("test", "functional", "#{@name_plural}_controller_test.rb") %>
30
- <% elsif app_config.mack.testing_framework == "rspec" -%>
31
- functional_test_template:
32
- type: file
33
- template_path: <%= File.join(templates_directory_path, "test", "functional", "rspec.rb.template") %>
34
- output_path: <%= File.join("test", "functional", "#{@name_plural}_controller_spec.rb") %>
35
- <% end -%>
@@ -1,41 +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
- end
15
-
16
- def after_generate # :nodoc:
17
- ModelGenerator.run(@options)
18
- update_routes_file
19
- end
20
-
21
- def update_routes_file # :nodoc:
22
- # update routes.rb
23
- routes = File.join(Mack.root, "config", "routes.rb")
24
- rf = File.open(routes).read
25
- unless rf.match(".resource :#{@name_plural}")
26
- puts "Updating routes.rb"
27
- nrf = ""
28
- rf.each do |line|
29
- if line.match("Mack::Routes.build")
30
- x = line.match(/\|(.+)\|/).captures
31
- line << "\n #{x}.resource :#{@name_plural} # Added by rake generate:scaffold name=#{param(:name)}\n"
32
- end
33
- nrf << line
34
- end
35
- File.open(routes, "w") do |f|
36
- f.puts nrf
37
- end
38
- end
39
- end
40
-
41
- end
@@ -1,7 +0,0 @@
1
- module Mack
2
- module ControllerHelpers
3
- module <%= @name_plural_camel %>Controller
4
- # methods here will automatically be included as protected methods into <%= @name_plural_camel %>Controller
5
- end
6
- end
7
- 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 %>), :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
- <%%= submit_tag("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 %>)) %></td>
33
- <td><%%= link_to("Edit", <%= @name_plural %>_edit_url(:id => <%= @name_singular %>)) %></td>
34
- <td><%%= link_to("Delete", <%= @name_plural %>_delete_url(:id => <%= @name_singular %>), :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
- <%%= submit_tag("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 %>)) %> |
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,57 +0,0 @@
1
- require 'rake'
2
- namespace :db do
3
-
4
- desc "Drops (if it exists) the database and then creates it for your environment."
5
- task :recreate => :environment do
6
- Mack::Database.drop(Mack.env, repis)
7
- Mack::Database.create(Mack.env, repis)
8
- end
9
-
10
- desc "Creates the database for your environment."
11
- task :create => :environment do
12
- Mack::Database.create(Mack.env, repis)
13
- end
14
-
15
- desc "Drops the database for your environment."
16
- task :drop => :environment do
17
- Mack::Database.drop(Mack.env, repis)
18
- end
19
-
20
- namespace :create do
21
-
22
- desc "Creates your test and development databases. Does NOT create your production database!"
23
- task :all => :environment do
24
- Mack::Database.create("test", repis)
25
- Mack::Database.create("development", repis)
26
- end
27
-
28
- end
29
-
30
- namespace :drop do
31
-
32
- desc "Drops your test and development databases. Does NOT create your production database!"
33
- task :all => :environment do
34
- Mack::Database.drop("test", repis)
35
- Mack::Database.drop("development", repis)
36
- end
37
-
38
- end
39
-
40
- namespace :recreate do
41
-
42
- desc "Drops and creates your test and development databases. Does NOT create your production database!"
43
- task :all => :environment do
44
- Mack::Database.drop("test", repis)
45
- Mack::Database.create("test", repis)
46
- Mack::Database.drop("development", repis)
47
- Mack::Database.create("development", repis)
48
- end
49
-
50
- end
51
-
52
- private
53
- def repis
54
- (ENV["REPO"] ||= "default").to_sym
55
- end
56
-
57
- end
@@ -1,46 +0,0 @@
1
- require 'rake'
2
- namespace :db do
3
-
4
-
5
-
6
- desc "Migrate the database through scripts in db/migrations."
7
- task :migrate => "mack:environment" do
8
- require 'migration_runner'
9
- include DataMapper::Types
10
- DataMapper::MigrationRunner.reset!
11
- migration_files.each { |mig| load mig }
12
- DataMapper::MigrationRunner.migrate_up!
13
- end # migrate
14
-
15
- desc "Rolls the schema back to the previous version. Specify the number of steps with STEP=n."
16
- task :rollback => ["mack:environment", "db:abort_if_pending_migrations"] do
17
- require 'dm-core/types'
18
- require 'migration_runner'
19
- include DataMapper::Types
20
- DataMapper::MigrationRunner.reset!
21
- migration_files.each { |mig| load mig }
22
- step = (ENV["STEP"] || 1).to_i
23
- migrations = DataMapper::MigrationRunner.migrations.sort.reverse
24
- step.times do |i|
25
- migrations[migrations.size - (i + 1)].perform_down
26
- end
27
- end # rollback
28
-
29
- desc "Raises an error if there are pending migrations."
30
- task :abort_if_pending_migrations do
31
- require 'dm-core/types'
32
- require 'migration_runner'
33
- migration_files.each { |mig| load mig }
34
- DataMapper::MigrationRunner.migrations.each do |mig|
35
- raise Mack::Errors::UnrunMigrations.new(mig.name) if mig.send("needs_up?")
36
- end
37
- DataMapper::MigrationRunner.migrations.clear
38
- end
39
-
40
- private
41
-
42
- def migration_files
43
- Dir.glob(File.join(Mack.root, "db", "migrations", "*.rb"))
44
- end
45
-
46
- end # db
@@ -1,12 +0,0 @@
1
- namespace :test do
2
-
3
- task :setup do
4
- unless ENV["MACK_TEST_ENV_SETUP?"] == "true"
5
- ENV["MACK_ENV"] = "test"
6
- Rake::Task["db:recreate"].invoke
7
- Rake::Task["db:migrate"].invoke
8
- ENV["MACK_TEST_ENV_SETUP?"] = "true"
9
- end
10
- end
11
-
12
- end