merb_activerecord 0.5 → 0.9.2
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.
- data/LICENSE +1 -1
- data/Rakefile +11 -6
- data/activerecord_generators/database_sessions_migration/database_sessions_migration_generator.rb +4 -2
- data/activerecord_generators/migration/migration_generator.rb +37 -9
- data/activerecord_generators/migration/templates/schema/migrations/%migration_file_name%.rb +17 -0
- data/activerecord_generators/model/model_generator.rb +36 -11
- data/activerecord_generators/model/templates/app/models/%model_file_name%.rb +2 -0
- data/activerecord_generators/resource_controller/resource_controller_generator.rb +65 -17
- data/activerecord_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb +68 -0
- data/activerecord_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb +16 -0
- data/activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb +3 -0
- data/activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb +3 -0
- data/activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb +3 -0
- data/activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb +3 -0
- data/lib/{merb/orms/active_record/tasks/databases.rb → active_record/merbtasks.rb} +131 -64
- data/lib/merb/orms/active_record/connection.rb +39 -16
- data/lib/merb/orms/active_record/{database.sample.yml → database.yml.sample} +1 -0
- data/lib/merb/session/active_record_session.rb +9 -3
- data/lib/merb_activerecord.rb +16 -10
- metadata +77 -61
- data/activerecord_generators/migration/templates/new_migration.erb +0 -15
- data/activerecord_generators/model/templates/new_model.erb +0 -2
- data/activerecord_generators/resource_controller/templates/controller.rb +0 -54
- data/activerecord_generators/resource_controller/templates/edit.html.erb +0 -1
- data/activerecord_generators/resource_controller/templates/helper.rb +0 -5
- data/activerecord_generators/resource_controller/templates/index.html.erb +0 -1
- data/activerecord_generators/resource_controller/templates/new.html.erb +0 -1
- data/activerecord_generators/resource_controller/templates/show.html.erb +0 -1
data/LICENSE
CHANGED
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
|
|
3
3
|
|
4
4
|
PLUGIN = "merb_activerecord"
|
5
5
|
NAME = "merb_activerecord"
|
6
|
-
VERSION = "0.
|
6
|
+
VERSION = "0.9.2"
|
7
7
|
AUTHOR = "Duane Johnson"
|
8
8
|
EMAIL = "canadaduane@gmail.com"
|
9
9
|
HOMEPAGE = "http://merbivore.com"
|
@@ -20,21 +20,26 @@ spec = Gem::Specification.new do |s|
|
|
20
20
|
s.author = AUTHOR
|
21
21
|
s.email = EMAIL
|
22
22
|
s.homepage = HOMEPAGE
|
23
|
-
s.add_dependency(
|
24
|
-
s.require_path =
|
23
|
+
s.add_dependency("merb-core", ">= 0.9.2")
|
24
|
+
s.require_path = "lib"
|
25
25
|
s.autorequire = PLUGIN
|
26
26
|
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,activerecord_generators}/**/*")
|
27
27
|
end
|
28
28
|
|
29
|
+
windows = (PLATFORM =~ /win32|cygwin/) rescue nil
|
30
|
+
|
31
|
+
SUDO = windows ? "" : "sudo"
|
32
|
+
|
29
33
|
Rake::GemPackageTask.new(spec) do |pkg|
|
30
34
|
pkg.gem_spec = spec
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
sh %{
|
37
|
+
desc "Install merb_activerecord"
|
38
|
+
task :install => :package do
|
39
|
+
sh %{#{SUDO} gem install pkg/#{NAME}-#{VERSION} --no-rdoc --no-ri --no-update-sources}
|
36
40
|
end
|
37
41
|
|
42
|
+
desc "Release the current version on rubyforge"
|
38
43
|
task :release => :package do
|
39
44
|
sh %{rubyforge add_release merb #{PLUGIN} #{VERSION} pkg/#{NAME}-#{VERSION}.gem}
|
40
45
|
end
|
data/activerecord_generators/database_sessions_migration/database_sessions_migration_generator.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
class DatabaseSessionsMigrationGenerator < RubiGen::Base
|
1
|
+
class DatabaseSessionsMigrationGenerator < Merb::GeneratorBase
|
3
2
|
|
4
3
|
default_options :author => nil
|
5
4
|
|
6
5
|
def initialize(runtime_args, runtime_options = {})
|
6
|
+
# put somthing into the runtime_args so that super doesn't show the
|
7
|
+
# description
|
8
|
+
runtime_args.push ""
|
7
9
|
super
|
8
10
|
@name = 'database_sessions'
|
9
11
|
end
|
@@ -1,14 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class MigrationGenerator < Merb::GeneratorHelpers::MigrationGeneratorBase
|
1
|
+
class MigrationGenerator < Merb::GeneratorBase
|
2
|
+
attr_reader :model_attributes, :model_class_name, :model_file_name, :table_name
|
4
3
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
4
|
+
def initialize(args, runtime_args = {})
|
5
|
+
@base = File.dirname(__FILE__)
|
6
|
+
super
|
7
|
+
@model_file_name = args.shift.snake_case
|
8
|
+
@table_name = @model_file_name.pluralize
|
9
|
+
@model_class_name = @model_file_name.to_const_string
|
10
|
+
@model_attributes = Hash[*(args.map{|a| a.split(":") }.flatten)]
|
8
11
|
end
|
9
12
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
+
def manifest
|
14
|
+
record do |m|
|
15
|
+
@m = m
|
16
|
+
|
17
|
+
m.directory "schema/migrations"
|
18
|
+
|
19
|
+
current_migration_number = Dir[Dir.pwd+'/schema/migrations/*'].map{|f| File.basename(f) =~ /^(\d+)/; $1}.max
|
20
|
+
@migration_file_name = format("%03d_%s", (current_migration_number.to_i+1), model_file_name) + "_migration"
|
13
21
|
|
22
|
+
@assigns = { :model_file_name => model_file_name,
|
23
|
+
:model_attributes => model_attributes,
|
24
|
+
:model_class_name => model_class_name,
|
25
|
+
:table_name => table_name,
|
26
|
+
:migration_file_name => @migration_file_name
|
27
|
+
}
|
28
|
+
copy_dirs
|
29
|
+
copy_files
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
def banner
|
35
|
+
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
|
36
|
+
Creates an Active Record Migration stub..
|
37
|
+
|
38
|
+
USAGE: #{spec.name}"
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
|
14
42
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class <%= model_class_name %>Migration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
<%= "create_table :#{table_name} do |t|" if table_name %>
|
4
|
+
<% for attribute in model_attributes -%>
|
5
|
+
t.<%= "%-11s" % attribute.last %> :<%= attribute.first %>
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
<%= "end" if table_name %>
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
<% if table_name -%>
|
14
|
+
drop_table :<%= table_name %>
|
15
|
+
<% end -%>
|
16
|
+
end
|
17
|
+
end
|
@@ -1,16 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class ModelGenerator < Merb::GeneratorHelpers::ModelGeneratorBase
|
1
|
+
class ModelGenerator < Merb::GeneratorBase
|
2
|
+
attr_reader :model_attributes, :model_class_name, :model_file_name, :migration_args
|
4
3
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
@
|
8
|
-
|
9
|
-
@
|
4
|
+
def initialize(args, runtime_args = {})
|
5
|
+
@base = File.dirname(__FILE__)
|
6
|
+
@migration_args = args.dup
|
7
|
+
super
|
8
|
+
@model_file_name = args.shift.snake_case
|
9
|
+
@model_class_name = @model_file_name.to_const_string
|
10
|
+
@model_attributes = Hash[*(args.map{|a| a.split(":") }.flatten)]
|
11
|
+
@model_file_name = "#{@model_class_name.snake_case}"
|
12
|
+
|
13
|
+
|
10
14
|
end
|
11
15
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
16
|
+
def manifest
|
17
|
+
record do |m|
|
18
|
+
@m = m
|
15
19
|
|
20
|
+
@assigns = { :model_file_name => model_file_name,
|
21
|
+
:model_attributes => model_attributes,
|
22
|
+
:model_class_name => model_class_name
|
23
|
+
}
|
24
|
+
copy_dirs
|
25
|
+
copy_files
|
26
|
+
|
27
|
+
m.dependency "migration", [*self.migration_args]
|
28
|
+
m.dependency "merb_model_test", [model_file_name], @assigns
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
def banner
|
34
|
+
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
|
35
|
+
Creates an Active Record Model stub..
|
36
|
+
|
37
|
+
USAGE: #{spec.name}"
|
38
|
+
EOS
|
39
|
+
end
|
40
|
+
|
16
41
|
end
|
@@ -1,26 +1,74 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class ResourceControllerGenerator < Merb::GeneratorBase
|
2
|
+
|
3
|
+
attr_reader :controller_class_name,
|
4
|
+
:controller_file_name,
|
5
|
+
:controller_base_path,
|
6
|
+
:controller_modules,
|
7
|
+
:model_class_name,
|
8
|
+
:full_controller_const,
|
9
|
+
:singular_model,
|
10
|
+
:plural_model
|
11
|
+
|
12
|
+
def initialize(args, runtime_args = {})
|
13
|
+
@base = File.dirname(__FILE__)
|
14
|
+
|
15
|
+
super
|
16
|
+
name = args.shift
|
17
|
+
nfp = name.snake_case.gsub("::", "/")
|
18
|
+
nfp = nfp.split("/")
|
19
|
+
@model_class_name = nfp.pop.singularize.to_const_string
|
20
|
+
@model_class_name = runtime_args[:model_class_name] if runtime_args[:model_class_name]
|
21
|
+
@singular_model = @model_class_name.snake_case
|
22
|
+
@plural_model = @singular_model.pluralize
|
23
|
+
|
24
|
+
nfp << @plural_model
|
25
|
+
|
26
|
+
@controller_file_name = nfp.join("/")
|
27
|
+
|
28
|
+
# Need to setup the directories
|
29
|
+
unless @controller_file_name == File.basename(@controller_file_name)
|
30
|
+
@controller_base_path = controller_file_name.split("/")[0..-2].join("/")
|
31
|
+
end
|
32
|
+
|
33
|
+
@controller_modules = @controller_file_name.to_const_string.split("::")[0..-2]
|
34
|
+
@controller_class_name = @controller_file_name.to_const_string.split("::").last
|
4
35
|
|
5
|
-
|
6
|
-
runtime_options = args.last.is_a?(Hash) ? args.pop : {}
|
7
|
-
name, *actions = args.flatten
|
8
|
-
runtime_options[:actions] = %w[index show new edit]
|
9
|
-
runtime_options[:test_stub_generator] = "merb_controller_test"
|
10
|
-
super( [name], runtime_options )
|
36
|
+
@full_controller_const = ((@controller_modules.dup || []) << @controller_class_name).join("::")
|
11
37
|
end
|
12
|
-
|
13
|
-
def
|
14
|
-
|
38
|
+
|
39
|
+
def manifest
|
40
|
+
record do |m|
|
41
|
+
@m = m
|
42
|
+
|
43
|
+
# Create the controller directory
|
44
|
+
m.directory File.join("app/controllers", controller_base_path) if controller_base_path
|
45
|
+
|
46
|
+
# Create the helpers directory
|
47
|
+
m.directory File.join("app/helpers", controller_base_path) if controller_base_path
|
48
|
+
|
49
|
+
@assigns = {
|
50
|
+
:controller_modules => controller_modules,
|
51
|
+
:controller_class_name => controller_class_name,
|
52
|
+
:controller_file_name => controller_file_name,
|
53
|
+
:controller_base_path => controller_base_path,
|
54
|
+
:full_controller_const => full_controller_const,
|
55
|
+
:model_class_name => model_class_name,
|
56
|
+
:singular_model => singular_model,
|
57
|
+
:plural_model => plural_model
|
58
|
+
}
|
59
|
+
copy_dirs
|
60
|
+
copy_files
|
61
|
+
|
62
|
+
m.dependency "merb_resource_controller_test", [@controller_class_name], @assigns
|
63
|
+
end
|
15
64
|
end
|
16
65
|
|
17
66
|
protected
|
18
67
|
def banner
|
19
|
-
|
20
|
-
|
68
|
+
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
|
69
|
+
Creates a basic Merb resource controller.
|
21
70
|
|
22
|
-
|
23
|
-
|
71
|
+
USAGE: #{spec.name} my_resource
|
72
|
+
EOS
|
24
73
|
end
|
25
|
-
|
26
74
|
end
|
data/activerecord_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
<% counter = 0 -%>
|
2
|
+
<% controller_modules.each_with_index do |mod, i| -%>
|
3
|
+
<%= " " * i %>module <%= mod %>
|
4
|
+
<% counter = i -%>
|
5
|
+
<% end -%>
|
6
|
+
<% counter = counter == 0 ? 0 : (counter + 1) -%>
|
7
|
+
<%= " " * counter %>class <%= controller_class_name %> < Application
|
8
|
+
<%= " " * counter %> # provides :xml, :yaml, :js
|
9
|
+
|
10
|
+
<%= " " * counter %> def index
|
11
|
+
<%= " " * counter %> @<%= plural_model %> = <%= model_class_name %>.find(:all)
|
12
|
+
<%= " " * counter %> display @<%= plural_model %>
|
13
|
+
<%= " " * counter %> end
|
14
|
+
|
15
|
+
<%= " " * counter %> def show
|
16
|
+
<%= " " * counter %> @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
|
17
|
+
<%= " " * counter %> raise NotFound unless @<%= singular_model %>
|
18
|
+
<%= " " * counter %> display @<%= singular_model %>
|
19
|
+
<%= " " * counter %> end
|
20
|
+
|
21
|
+
<%= " " * counter %> def new
|
22
|
+
<%= " " * counter %> only_provides :html
|
23
|
+
<%= " " * counter %> @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
|
24
|
+
<%= " " * counter %> render
|
25
|
+
<%= " " * counter %> end
|
26
|
+
|
27
|
+
<%= " " * counter %> def create
|
28
|
+
<%= " " * counter %> @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
|
29
|
+
<%= " " * counter %> if @<%= singular_model %>.save
|
30
|
+
<%= " " * counter %> redirect url(:<%= (controller_modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
|
31
|
+
<%= " " * counter %> else
|
32
|
+
<%= " " * counter %> render :new
|
33
|
+
<%= " " * counter %> end
|
34
|
+
<%= " " * counter %> end
|
35
|
+
|
36
|
+
<%= " " * counter %> def edit
|
37
|
+
<%= " " * counter %> only_provides :html
|
38
|
+
<%= " " * counter %> @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
|
39
|
+
<%= " " * counter %> raise NotFound unless @<%= singular_model %>
|
40
|
+
<%= " " * counter %> render
|
41
|
+
<%= " " * counter %> end
|
42
|
+
|
43
|
+
<%= " " * counter %> def update
|
44
|
+
<%= " " * counter %> @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
|
45
|
+
<%= " " * counter %> raise NotFound unless @<%= singular_model %>
|
46
|
+
<%= " " * counter %> if @<%= singular_model %>.update_attributes(params[:<%= singular_model %>])
|
47
|
+
<%= " " * counter %> redirect url(:<%= (controller_modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
|
48
|
+
<%= " " * counter %> else
|
49
|
+
<%= " " * counter %> raise BadRequest
|
50
|
+
<%= " " * counter %> end
|
51
|
+
<%= " " * counter %> end
|
52
|
+
|
53
|
+
<%= " " * counter %> def destroy
|
54
|
+
<%= " " * counter %> @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
|
55
|
+
<%= " " * counter %> raise NotFound unless @<%= singular_model %>
|
56
|
+
<%= " " * counter %> if @<%= singular_model %>.destroy
|
57
|
+
<%= " " * counter %> redirect url(:<%= (controller_modules.collect{|m| m.downcase} << singular_model).join("_") %>s)
|
58
|
+
<%= " " * counter %> else
|
59
|
+
<%= " " * counter %> raise BadRequest
|
60
|
+
<%= " " * counter %> end
|
61
|
+
<%= " " * counter %> end
|
62
|
+
|
63
|
+
<%= " " * counter %>end
|
64
|
+
<% counter = counter == 0 ? 0 : (counter - 1) -%>
|
65
|
+
<% controller_modules.reverse.each_with_index do |mod, i| -%>
|
66
|
+
<%= " " * counter %>end # <%= mod %>
|
67
|
+
<% counter = counter - 1 -%>
|
68
|
+
<% end -%>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% counter = 1 -%>
|
2
|
+
module Merb
|
3
|
+
<% controller_modules.each_with_index do |mod, i| -%>
|
4
|
+
<%= " " * i %>module <%= mod %>
|
5
|
+
<% counter = i -%>
|
6
|
+
<% end -%>
|
7
|
+
<% counter = counter == 0 ? 0 : (counter + 1) -%>
|
8
|
+
<%= " " * counter %>module <%= controller_class_name %>Helper
|
9
|
+
|
10
|
+
<%= " " * counter %>end
|
11
|
+
<% counter = counter == 0 ? 0 : (counter - 1) -%>
|
12
|
+
<% controller_modules.reverse.each_with_index do |mod, i| -%>
|
13
|
+
<%= " " * counter %>end # <%= mod %>
|
14
|
+
<% counter = counter - 1 -%>
|
15
|
+
<% end -%>
|
16
|
+
end
|
@@ -1,20 +1,21 @@
|
|
1
|
-
task :environment do
|
2
|
-
Merb.environment = ( ENV['Merb.environment'] || Merb.environment ).to_sym
|
3
|
-
end
|
4
|
-
|
5
1
|
namespace :db do
|
2
|
+
|
3
|
+
task :merb_start do
|
4
|
+
Merb.start :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'development', :log_file => Merb::Config[:log_file]
|
5
|
+
end
|
6
|
+
|
6
7
|
namespace :create do
|
7
8
|
desc 'Create all the local databases defined in config/database.yml'
|
8
|
-
task :all => :
|
9
|
-
ActiveRecord
|
9
|
+
task :all => :merb_start do
|
10
|
+
Merb::Orms::ActiveRecord.configurations.each_value do |config|
|
10
11
|
create_local_database(config)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
desc 'Create the local database defined in config/database.yml for the current Merb.environment'
|
16
|
-
task :create => :
|
17
|
-
create_local_database(ActiveRecord
|
17
|
+
task :create => :merb_start do
|
18
|
+
create_local_database(Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym])
|
18
19
|
end
|
19
20
|
|
20
21
|
def create_local_database(config)
|
@@ -26,15 +27,15 @@ namespace :db do
|
|
26
27
|
rescue
|
27
28
|
case config[:adapter]
|
28
29
|
when 'mysql'
|
29
|
-
|
30
|
-
|
30
|
+
@charset = ENV['CHARSET'] || 'utf8'
|
31
|
+
@collation = ENV['COLLATION'] || 'utf8_general_ci'
|
31
32
|
begin
|
32
33
|
ActiveRecord::Base.establish_connection(config.merge({:database => nil}))
|
33
|
-
ActiveRecord::Base.connection.create_database(config[:database]
|
34
|
+
ActiveRecord::Base.connection.create_database(config[:database], {:charset => (config[:charset] || @charset), :collation => (config[:collation] || @collation)})
|
34
35
|
ActiveRecord::Base.establish_connection(config)
|
35
|
-
|
36
|
+
puts "MySQL #{config[:database]} database successfully created"
|
36
37
|
rescue
|
37
|
-
$stderr.puts "Couldn't create database for #{config.inspect}"
|
38
|
+
$stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config[:charset] || @charset}, collation: #{config[:collation] || @collation} (if you set the charset manually, make sure you have a matching collation)"
|
38
39
|
end
|
39
40
|
when 'postgresql'
|
40
41
|
`createdb "#{config[:database]}" -E utf8`
|
@@ -44,70 +45,131 @@ namespace :db do
|
|
44
45
|
`sqlite3 "#{config[:database]}"`
|
45
46
|
end
|
46
47
|
else
|
47
|
-
|
48
|
+
puts "#{config[:database]} already exists"
|
48
49
|
end
|
49
50
|
else
|
50
|
-
|
51
|
+
puts "This task only creates local databases. #{config[:database]} is on a remote host."
|
51
52
|
end
|
52
53
|
end
|
53
|
-
|
54
|
-
|
55
|
-
task :drop => :environment do
|
56
|
-
config = ActiveRecord::Base.configurations[Merb.environment || :development]
|
57
|
-
p config
|
54
|
+
|
55
|
+
def drop_database(config)
|
58
56
|
case config[:adapter]
|
59
57
|
when 'mysql'
|
60
58
|
ActiveRecord::Base.connection.drop_database config[:database]
|
61
59
|
when /^sqlite/
|
62
|
-
FileUtils.
|
60
|
+
FileUtils.rm(File.join(RAILS_ROOT, config[:database]))
|
63
61
|
when 'postgresql'
|
62
|
+
ActiveRecord::Base.clear_active_connections!
|
64
63
|
`dropdb "#{config[:database]}"`
|
65
64
|
end
|
66
65
|
end
|
66
|
+
|
67
|
+
def local_database?(config, &block)
|
68
|
+
if %w( 127.0.0.1 localhost ).include?(config[:host]) || config[:host].blank?
|
69
|
+
yield
|
70
|
+
else
|
71
|
+
puts "This task only modifies local databases. #{config[:database]} is on a remote host."
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
namespace :drop do
|
76
|
+
desc 'Drops all the local databases defined in config/database.yml'
|
77
|
+
task :all => :merb_start do
|
78
|
+
Merb::Orms::ActiveRecord.configurations.each_value do |config|
|
79
|
+
# Skip entries that don't have a database key
|
80
|
+
next unless config[:database]
|
81
|
+
# Only connect to local databases
|
82
|
+
local_database?(config) { drop_database(config) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
67
86
|
|
87
|
+
desc 'Drops the database for the current environment (set MERB_ENV to target another environment)'
|
88
|
+
task :drop => :merb_start do
|
89
|
+
config = Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym]
|
90
|
+
begin
|
91
|
+
drop_database(config)
|
92
|
+
rescue Exception => e
|
93
|
+
puts "#{e.inspect} - #{config['database']} might have been already dropped"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
68
97
|
desc "Migrate the database through scripts in schema/migrations. Target specific version with VERSION=x"
|
69
|
-
task :migrate => :
|
98
|
+
task :migrate => :merb_start do
|
99
|
+
config = Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym]
|
100
|
+
ActiveRecord::Base.establish_connection(config)
|
70
101
|
ActiveRecord::Migrator.migrate("schema/migrations/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
71
102
|
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
72
103
|
end
|
73
104
|
|
74
|
-
|
75
|
-
|
105
|
+
namespace :migrate do
|
106
|
+
desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x'
|
107
|
+
task :redo => [ 'db:rollback', 'db:migrate' ]
|
76
108
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
109
|
+
desc 'Resets your database using your migrations for the current environment'
|
110
|
+
task :reset => ["db:drop", "db:create", "db:migrate"]
|
111
|
+
end
|
112
|
+
|
113
|
+
desc 'Drops and recreates the database from db/schema.rb for the current environment.'
|
114
|
+
task :reset => ['db:drop', 'db:create', 'db:schema:load']
|
115
|
+
|
116
|
+
desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
|
117
|
+
task :rollback => :merb_start do
|
118
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
119
|
+
version = ActiveRecord::Migrator.current_version - step
|
120
|
+
ActiveRecord::Migrator.migrate('schema/migrations/', version)
|
121
|
+
end
|
122
|
+
|
123
|
+
desc "Raises an error if there are pending migrations"
|
124
|
+
task :abort_if_pending_migrations => :merb_start do
|
125
|
+
if defined? ActiveRecord
|
126
|
+
pending_migrations = ActiveRecord::Migrator.new(:up, 'schema/migrations').pending_migrations
|
127
|
+
|
128
|
+
if pending_migrations.any?
|
129
|
+
puts "You have #{pending_migrations.size} pending migrations:"
|
130
|
+
pending_migrations.each do |pending_migration|
|
131
|
+
puts ' %4d %s' % [pending_migration.version, pending_migration.name]
|
132
|
+
end
|
133
|
+
abort "Run `rake db:migrate` to update your database then try again."
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
desc "Retrieves the charset for the current environment's database"
|
139
|
+
task :charset => :merb_start do
|
140
|
+
config = Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym]
|
141
|
+
case config[:adapter]
|
142
|
+
when 'mysql'
|
143
|
+
ActiveRecord::Base.establish_connection(config)
|
144
|
+
puts ActiveRecord::Base.connection.charset
|
145
|
+
else
|
146
|
+
puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
|
147
|
+
end
|
148
|
+
end
|
88
149
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
150
|
+
desc "Retrieves the collation for the current environment's database"
|
151
|
+
task :collation => :merb_start do
|
152
|
+
config = Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym]
|
153
|
+
case config[:adapter]
|
154
|
+
when 'mysql'
|
155
|
+
ActiveRecord::Base.establish_connection(config)
|
156
|
+
puts ActiveRecord::Base.connection.collation
|
157
|
+
else
|
158
|
+
puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
|
159
|
+
end
|
160
|
+
end
|
100
161
|
|
101
162
|
desc "Retrieves the current schema version number"
|
102
|
-
task :version => :
|
163
|
+
task :version => :merb_start do
|
103
164
|
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
104
165
|
end
|
105
166
|
|
106
167
|
namespace :fixtures do
|
107
168
|
desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
108
|
-
task :load => :
|
169
|
+
task :load => :merb_start do
|
109
170
|
require 'active_record/fixtures'
|
110
|
-
ActiveRecord
|
171
|
+
config = Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym]
|
172
|
+
ActiveRecord::Base.establish_connection(config)
|
111
173
|
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Merb.root, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
112
174
|
Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
|
113
175
|
end
|
@@ -116,7 +178,7 @@ namespace :db do
|
|
116
178
|
|
117
179
|
namespace :schema do
|
118
180
|
desc 'Create a schema/schema.rb file that can be portably used against any DB supported by AR'
|
119
|
-
task :dump do
|
181
|
+
task :dump => :merb_start do
|
120
182
|
require 'active_record/schema_dumper'
|
121
183
|
File.open(ENV['SCHEMA'] || "schema/schema.rb", "w") do |file|
|
122
184
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
@@ -124,7 +186,9 @@ namespace :db do
|
|
124
186
|
end
|
125
187
|
|
126
188
|
desc "Load a schema.rb file into the database"
|
127
|
-
task :load do
|
189
|
+
task :load => :merb_start do
|
190
|
+
config = Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym]
|
191
|
+
ActiveRecord::Base.establish_connection(config)
|
128
192
|
file = ENV['SCHEMA'] || "schema/schema.rb"
|
129
193
|
load(file)
|
130
194
|
end
|
@@ -132,11 +196,11 @@ namespace :db do
|
|
132
196
|
|
133
197
|
namespace :structure do
|
134
198
|
desc "Dump the database structure to a SQL file"
|
135
|
-
task :dump do
|
136
|
-
config = ActiveRecord
|
199
|
+
task :dump => :merb_start do
|
200
|
+
config = Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym]
|
137
201
|
case config[:adapter]
|
138
202
|
when "mysql", "oci", "oracle"
|
139
|
-
ActiveRecord::Base.establish_connection(config
|
203
|
+
ActiveRecord::Base.establish_connection(config)
|
140
204
|
File.open("schema/#{Merb.environment}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
141
205
|
when "postgresql"
|
142
206
|
ENV['PGHOST'] = config[:host] if config[:host]
|
@@ -153,8 +217,8 @@ namespace :db do
|
|
153
217
|
`scptxfr /s #{config[:host]} /d #{config[:database]} /I /f schema\\#{Merb.environment}_structure.sql /q /A /r`
|
154
218
|
`scptxfr /s #{config[:host]} /d #{config[:database]} /I /F schema\ /q /A /r`
|
155
219
|
when "firebird"
|
156
|
-
set_firebird_env(config
|
157
|
-
db_string = firebird_db_string(config
|
220
|
+
set_firebird_env(config)
|
221
|
+
db_string = firebird_db_string(config)
|
158
222
|
sh "isql -a #{db_string} > schema/#{Merb.environment}_structure.sql"
|
159
223
|
else
|
160
224
|
raise "Task not supported by '#{config[:adapter]}'"
|
@@ -167,19 +231,21 @@ namespace :db do
|
|
167
231
|
end
|
168
232
|
|
169
233
|
namespace :test do
|
234
|
+
|
170
235
|
desc "Recreate the test database from the current environment's database schema"
|
171
236
|
task :clone => %w(db:schema:dump db:test:purge) do
|
172
|
-
ActiveRecord::Base.establish_connection(ActiveRecord
|
237
|
+
ActiveRecord::Base.establish_connection(Merb::Orms::ActiveRecord.configurations[:test])
|
173
238
|
ActiveRecord::Schema.verbose = false
|
239
|
+
Merb.environment = 'test'
|
174
240
|
Rake::Task["db:schema:load"].invoke
|
175
241
|
end
|
176
242
|
|
177
243
|
desc "Recreate the test databases from the development structure"
|
178
244
|
task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
|
179
|
-
config = ActiveRecord
|
245
|
+
config = Merb::Orms::ActiveRecord.configurations[:test]
|
180
246
|
case config[:adapter]
|
181
247
|
when "mysql"
|
182
|
-
ActiveRecord::Base.establish_connection(
|
248
|
+
ActiveRecord::Base.establish_connection(config)
|
183
249
|
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
|
184
250
|
IO.readlines("schema/#{Merb.environment}_structure.sql").join.split("\n\n").each do |table|
|
185
251
|
ActiveRecord::Base.connection.execute(table)
|
@@ -209,11 +275,12 @@ namespace :db do
|
|
209
275
|
end
|
210
276
|
|
211
277
|
desc "Empty the test database"
|
212
|
-
task :purge do
|
213
|
-
config = ActiveRecord
|
278
|
+
task :purge => :merb_start do
|
279
|
+
config = Merb::Orms::ActiveRecord.configurations[:test]
|
280
|
+
puts "config => #{config.inspect}"
|
214
281
|
case config[:adapter]
|
215
282
|
when "mysql"
|
216
|
-
ActiveRecord::Base.establish_connection(
|
283
|
+
ActiveRecord::Base.establish_connection(config)
|
217
284
|
ActiveRecord::Base.connection.recreate_database(config[:database])
|
218
285
|
when "postgresql"
|
219
286
|
ENV['PGHOST'] = config[:host] if config[:host]
|
@@ -241,7 +308,7 @@ namespace :db do
|
|
241
308
|
|
242
309
|
desc "Prepare the test database and load the schema"
|
243
310
|
task :prepare => ["db:test:clone_structure", "db:test:clone"] do
|
244
|
-
if defined?(ActiveRecord::Base) && !ActiveRecord
|
311
|
+
if defined?(ActiveRecord::Base) && !Merb::Orms::ActiveRecord.configurations.blank?
|
245
312
|
Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke
|
246
313
|
end
|
247
314
|
end
|
@@ -257,7 +324,7 @@ namespace :db do
|
|
257
324
|
# end
|
258
325
|
|
259
326
|
desc "Clear the sessions table"
|
260
|
-
task :clear => :
|
327
|
+
task :clear => :merb_start do
|
261
328
|
session_table = 'session'
|
262
329
|
session_table = Inflector.pluralize(session_table) if ActiveRecord::Base.pluralize_table_names
|
263
330
|
ActiveRecord::Base.connection.execute "DELETE FROM #{session_table}"
|
@@ -4,31 +4,54 @@ require 'active_record'
|
|
4
4
|
module Merb
|
5
5
|
module Orms
|
6
6
|
module ActiveRecord
|
7
|
+
|
8
|
+
# Start a transaction.
|
9
|
+
#
|
10
|
+
# Used by Merb::Rack::Console#open_sandbox!
|
11
|
+
def self.open_sandbox!
|
12
|
+
::ActiveRecord::Base.send :increment_open_transactions
|
13
|
+
::ActiveRecord::Base.connection.begin_db_transaction
|
14
|
+
end
|
15
|
+
|
16
|
+
# Rollback a transaction.
|
17
|
+
#
|
18
|
+
# Used by Merb::Rack::Console#open_sandbox!
|
19
|
+
def self.close_sandbox!
|
20
|
+
::ActiveRecord::Base.connection.rollback_db_transaction
|
21
|
+
::ActiveRecord::Base.send :decrement_open_transactions
|
22
|
+
end
|
23
|
+
|
7
24
|
class << self
|
8
|
-
def config_file() Merb.
|
9
|
-
def sample_dest() Merb.
|
10
|
-
def sample_source() File.dirname(__FILE__) / "database.sample
|
25
|
+
def config_file() Merb.dir_for(:config) / "database.yml" end
|
26
|
+
def sample_dest() Merb.dir_for(:config) / "database.yml.sample" end
|
27
|
+
def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
|
11
28
|
|
12
29
|
def copy_sample_config
|
13
30
|
FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
|
14
31
|
end
|
15
32
|
|
16
33
|
def config
|
17
|
-
@config ||=
|
34
|
+
@config ||= (Merb::Plugins.config[:merb_active_record] = configurations[Merb.environment.to_sym])
|
35
|
+
end
|
36
|
+
|
37
|
+
def configurations
|
38
|
+
@configurations ||=
|
18
39
|
begin
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
40
|
+
#A proc that will recursively intern(a.k.a symbolize) the keys of the hash
|
41
|
+
intern_keys = lambda { |x|
|
42
|
+
x.inject({}) do |y, (k,v)|
|
43
|
+
y[k.to_sym || k] = v.is_a?(Hash) ? intern_keys.call(v) : v
|
44
|
+
y
|
45
|
+
end
|
46
|
+
}
|
47
|
+
intern_keys.call(Erubis.load_yaml_file(config_file))
|
25
48
|
end
|
26
49
|
end
|
27
50
|
|
28
51
|
# Database connects as soon as the gem is loaded
|
29
52
|
def connect
|
30
53
|
if File.exists?(config_file)
|
31
|
-
|
54
|
+
Merb.logger.info!("Connecting to database...")
|
32
55
|
|
33
56
|
Thread.new{ loop{ sleep(60*60); ::ActiveRecord::Base.verify_active_connections! } }.priority = -10
|
34
57
|
|
@@ -37,8 +60,8 @@ module Merb
|
|
37
60
|
::ActiveRecord::Base.establish_connection config
|
38
61
|
else
|
39
62
|
copy_sample_config
|
40
|
-
|
41
|
-
|
63
|
+
Merb.logger.error! "No database.yml file found in #{Merb.root}/config."
|
64
|
+
Merb.logger.error! "A sample file was created called database.sample.yml for you to copy and edit."
|
42
65
|
exit(1)
|
43
66
|
end
|
44
67
|
end
|
@@ -46,9 +69,9 @@ module Merb
|
|
46
69
|
# Registering this ORM lets the user choose active_record as a session
|
47
70
|
# in merb.yml's session_store: option.
|
48
71
|
def register_session_type
|
49
|
-
Merb
|
50
|
-
|
51
|
-
|
72
|
+
Merb.register_session_type("activerecord",
|
73
|
+
"merb/session/active_record_session",
|
74
|
+
"Using ActiveRecord database sessions")
|
52
75
|
end
|
53
76
|
end
|
54
77
|
end
|
@@ -3,7 +3,6 @@ require "active_record"
|
|
3
3
|
module Merb
|
4
4
|
module SessionMixin
|
5
5
|
def setup_session
|
6
|
-
Merb.logger.info("Setting up session")
|
7
6
|
before = cookies[_session_id_key]
|
8
7
|
request.session, cookies[_session_id_key] = Merb::ActiveRecordSession.persist(cookies[_session_id_key])
|
9
8
|
@_fingerprint = Marshal.dump(request.session.data).hash
|
@@ -11,9 +10,12 @@ module Merb
|
|
11
10
|
end
|
12
11
|
|
13
12
|
def finalize_session
|
14
|
-
Merb.logger.info("Finalize session")
|
15
13
|
request.session.save if @_fingerprint != Marshal.dump(request.session.data).hash
|
16
|
-
set_cookie(_session_id_key, request.session.session_id, _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
|
14
|
+
set_cookie(_session_id_key, request.session.session_id, Time.now + _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
|
15
|
+
end
|
16
|
+
|
17
|
+
def session_store_type
|
18
|
+
"activerecord"
|
17
19
|
end
|
18
20
|
end # ActiveRecordMixin
|
19
21
|
|
@@ -99,6 +101,10 @@ module Merb
|
|
99
101
|
def each(&b)
|
100
102
|
data.each(&b)
|
101
103
|
end
|
104
|
+
|
105
|
+
def each_with_index(&b)
|
106
|
+
data.each_with_index(&b)
|
107
|
+
end
|
102
108
|
|
103
109
|
def []=(key, val)
|
104
110
|
data[key] = val
|
data/lib/merb_activerecord.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
if defined?(Merb::Plugins)
|
2
|
+
dependency "activerecord"
|
3
|
+
require File.join(File.dirname(__FILE__) / "merb" / "orms" / "active_record" / "connection")
|
4
|
+
Merb::Plugins.add_rakefiles(File.join(File.dirname(__FILE__) / "active_record" / "merbtasks"))
|
5
|
+
|
6
|
+
class Merb::Orms::ActiveRecord::Connect < Merb::BootLoader
|
7
|
+
|
8
|
+
after BeforeAppRuns
|
9
|
+
|
10
|
+
def self.run
|
11
|
+
Merb::Orms::ActiveRecord.connect
|
12
|
+
Merb::Orms::ActiveRecord.register_session_type
|
13
|
+
end
|
14
|
+
|
9
15
|
end
|
10
|
-
|
11
|
-
end
|
16
|
+
|
17
|
+
end
|
metadata
CHANGED
@@ -1,96 +1,112 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: merb_activerecord
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version:
|
7
|
-
date: 2008-01-09 00:00:00 -08:00
|
8
|
-
summary: Merb plugin that provides ActiveRecord support for Merb
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: canadaduane@gmail.com
|
12
|
-
homepage: http://merbivore.com
|
13
|
-
rubyforge_project:
|
14
|
-
description: Merb plugin that provides ActiveRecord support for Merb
|
15
|
-
autorequire: merb_activerecord
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.9.2
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Duane Johnson
|
8
|
+
autorequire: merb_activerecord
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-24 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.2
|
23
|
+
version:
|
24
|
+
description: Merb plugin that provides ActiveRecord support for Merb
|
25
|
+
email: canadaduane@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- LICENSE
|
33
|
+
- TODO
|
31
34
|
files:
|
32
35
|
- LICENSE
|
33
36
|
- README
|
34
37
|
- Rakefile
|
35
38
|
- TODO
|
39
|
+
- lib/active_record
|
40
|
+
- lib/active_record/merbtasks.rb
|
36
41
|
- lib/merb
|
37
|
-
- lib/merb_activerecord.rb
|
38
42
|
- lib/merb/orms
|
39
|
-
- lib/merb/session
|
40
43
|
- lib/merb/orms/active_record
|
41
44
|
- lib/merb/orms/active_record/connection.rb
|
42
|
-
- lib/merb/orms/active_record/database.sample
|
43
|
-
- lib/merb/
|
44
|
-
- lib/merb/orms/active_record/tasks/databases.rb
|
45
|
+
- lib/merb/orms/active_record/database.yml.sample
|
46
|
+
- lib/merb/session
|
45
47
|
- lib/merb/session/active_record_session.rb
|
48
|
+
- lib/merb_activerecord.rb
|
46
49
|
- specs/merb_active_record_spec.rb
|
47
50
|
- specs/spec_helper.rb
|
48
51
|
- activerecord_generators/database_sessions_migration
|
49
|
-
- activerecord_generators/migration
|
50
|
-
- activerecord_generators/model
|
51
|
-
- activerecord_generators/resource_controller
|
52
52
|
- activerecord_generators/database_sessions_migration/database_sessions_migration_generator.rb
|
53
53
|
- activerecord_generators/database_sessions_migration/templates
|
54
|
-
- activerecord_generators/database_sessions_migration/USAGE
|
55
54
|
- activerecord_generators/database_sessions_migration/templates/sessions_migration.erb
|
55
|
+
- activerecord_generators/database_sessions_migration/USAGE
|
56
|
+
- activerecord_generators/migration
|
56
57
|
- activerecord_generators/migration/migration_generator.rb
|
57
58
|
- activerecord_generators/migration/templates
|
59
|
+
- activerecord_generators/migration/templates/schema
|
60
|
+
- activerecord_generators/migration/templates/schema/migrations
|
61
|
+
- activerecord_generators/migration/templates/schema/migrations/%migration_file_name%.rb
|
58
62
|
- activerecord_generators/migration/USAGE
|
59
|
-
- activerecord_generators/
|
63
|
+
- activerecord_generators/model
|
60
64
|
- activerecord_generators/model/model_generator.rb
|
61
65
|
- activerecord_generators/model/templates
|
66
|
+
- activerecord_generators/model/templates/app
|
67
|
+
- activerecord_generators/model/templates/app/models
|
68
|
+
- activerecord_generators/model/templates/app/models/%model_file_name%.rb
|
62
69
|
- activerecord_generators/model/USAGE
|
63
|
-
- activerecord_generators/
|
70
|
+
- activerecord_generators/resource_controller
|
64
71
|
- activerecord_generators/resource_controller/resource_controller_generator.rb
|
65
72
|
- activerecord_generators/resource_controller/templates
|
73
|
+
- activerecord_generators/resource_controller/templates/app
|
74
|
+
- activerecord_generators/resource_controller/templates/app/controllers
|
75
|
+
- activerecord_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb
|
76
|
+
- activerecord_generators/resource_controller/templates/app/helpers
|
77
|
+
- activerecord_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb
|
78
|
+
- activerecord_generators/resource_controller/templates/app/views
|
79
|
+
- activerecord_generators/resource_controller/templates/app/views/%controller_file_name%
|
80
|
+
- activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb
|
81
|
+
- activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb
|
82
|
+
- activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb
|
83
|
+
- activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb
|
66
84
|
- activerecord_generators/resource_controller/USAGE
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
- activerecord_generators/resource_controller/templates/index.html.erb
|
71
|
-
- activerecord_generators/resource_controller/templates/new.html.erb
|
72
|
-
- activerecord_generators/resource_controller/templates/show.html.erb
|
73
|
-
test_files: []
|
74
|
-
|
85
|
+
has_rdoc: true
|
86
|
+
homepage: http://merbivore.com
|
87
|
+
post_install_message:
|
75
88
|
rdoc_options: []
|
76
89
|
|
77
|
-
|
78
|
-
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
version:
|
85
104
|
requirements: []
|
86
105
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: "0.5"
|
96
|
-
version:
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.0.1
|
108
|
+
signing_key:
|
109
|
+
specification_version: 2
|
110
|
+
summary: Merb plugin that provides ActiveRecord support for Merb
|
111
|
+
test_files: []
|
112
|
+
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class <%= class_name.snake_case.camel_case %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
<%= "create_table :#{table_name} do |t|" if table_name %>
|
4
|
-
<% for attribute in table_attributes -%>
|
5
|
-
t.column :<%= attribute.name %>, :<%= attribute.type %>
|
6
|
-
<% end -%>
|
7
|
-
<%= "end" if table_name %>
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.down
|
11
|
-
<% if table_name -%>
|
12
|
-
drop_table :<%= table_name %>
|
13
|
-
<% end -%>
|
14
|
-
end
|
15
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
<% klass = class_name.singularize -%>
|
2
|
-
<% ivar = class_name.snake_case.singularize -%>
|
3
|
-
class <%= class_name %> < Application
|
4
|
-
provides :xml, :js, :yaml
|
5
|
-
|
6
|
-
def index
|
7
|
-
@<%= ivar.pluralize %> = <%= klass %>.find(:all)
|
8
|
-
render @<%= ivar.pluralize %>
|
9
|
-
end
|
10
|
-
|
11
|
-
def show
|
12
|
-
@<%= ivar %> = <%= klass %>.find(params[:id])
|
13
|
-
render @<%= ivar %>
|
14
|
-
end
|
15
|
-
|
16
|
-
def new
|
17
|
-
only_provides :html
|
18
|
-
@<%= ivar %> = <%= klass %>.new(params[:<%= ivar %>])
|
19
|
-
render
|
20
|
-
end
|
21
|
-
|
22
|
-
def create
|
23
|
-
@<%= ivar %> = <%= klass %>.new(params[:<%= ivar %>])
|
24
|
-
if @<%= ivar %>.save
|
25
|
-
redirect url(:<%= ivar %>, @<%= ivar %>)
|
26
|
-
else
|
27
|
-
render :action => :new
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def edit
|
32
|
-
only_provides :html
|
33
|
-
@<%= ivar %> = <%= klass %>.find(params[:id])
|
34
|
-
render
|
35
|
-
end
|
36
|
-
|
37
|
-
def update
|
38
|
-
@<%= ivar %> = <%= klass %>.find(params[:id])
|
39
|
-
if @<%= ivar %>.update_attributes(params[:<%= ivar %>])
|
40
|
-
redirect url(:<%= ivar %>, @<%= ivar %>)
|
41
|
-
else
|
42
|
-
raise BadRequest
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def destroy
|
47
|
-
@<%= ivar %> = <%= klass %>.find(params[:id])
|
48
|
-
if @<%= ivar %>.destroy
|
49
|
-
redirect url(:<%= ivar %>s)
|
50
|
-
else
|
51
|
-
raise BadRequest
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Edit for <%= class_name %>
|
@@ -1 +0,0 @@
|
|
1
|
-
Index for <%= class_name %>
|
@@ -1 +0,0 @@
|
|
1
|
-
New for <%= class_name %>
|
@@ -1 +0,0 @@
|
|
1
|
-
Show for <%= class_name %>
|