merb_activerecord 0.9.3 → 0.9.4

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 (36) hide show
  1. data/Rakefile +48 -29
  2. data/lib/active_record/merbtasks.rb +8 -10
  3. data/lib/generators/migration.rb +4 -0
  4. data/lib/generators/model.rb +8 -0
  5. data/lib/generators/resource_controller.rb +12 -0
  6. data/lib/generators/session_migration.rb +4 -0
  7. data/lib/generators/templates/migration/schema/migrations/%file_name%.rb +19 -0
  8. data/lib/generators/templates/model/app/models/%file_name%.rb +4 -0
  9. data/lib/generators/templates/resource_controller/app/controllers/%file_name%.rb +57 -0
  10. data/lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb +3 -0
  11. data/lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb +3 -0
  12. data/lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb +3 -0
  13. data/lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb +3 -0
  14. data/lib/generators/templates/session_migration/schema/migrations/%version%_sessions.rb +14 -0
  15. data/lib/merb/orms/active_record/connection.rb +8 -2
  16. data/lib/merb/orms/active_record/database.yml.sample +4 -1
  17. data/lib/merb/session/active_record_session.rb +1 -1
  18. data/lib/merb_activerecord.rb +7 -1
  19. metadata +35 -40
  20. data/activerecord_generators/database_sessions_migration/USAGE +0 -5
  21. data/activerecord_generators/database_sessions_migration/database_sessions_migration_generator.rb +0 -53
  22. data/activerecord_generators/database_sessions_migration/templates/sessions_migration.erb +0 -15
  23. data/activerecord_generators/migration/USAGE +0 -5
  24. data/activerecord_generators/migration/migration_generator.rb +0 -42
  25. data/activerecord_generators/migration/templates/schema/migrations/%migration_file_name%.rb +0 -17
  26. data/activerecord_generators/model/USAGE +0 -4
  27. data/activerecord_generators/model/model_generator.rb +0 -41
  28. data/activerecord_generators/model/templates/app/models/%model_file_name%.rb +0 -2
  29. data/activerecord_generators/resource_controller/USAGE +0 -0
  30. data/activerecord_generators/resource_controller/resource_controller_generator.rb +0 -74
  31. data/activerecord_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb +0 -68
  32. data/activerecord_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb +0 -16
  33. data/activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb +0 -3
  34. data/activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb +0 -3
  35. data/activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb +0 -3
  36. data/activerecord_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb +0 -3
data/Rakefile CHANGED
@@ -1,45 +1,64 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
+ require "extlib"
4
+ require 'merb-core/tasks/merb_rake_helper'
5
+ require "spec/rake/spectask"
3
6
 
4
- PLUGIN = "merb_activerecord"
5
- NAME = "merb_activerecord"
6
- VERSION = "0.9.3"
7
- AUTHOR = "Duane Johnson"
8
- EMAIL = "canadaduane@gmail.com"
9
- HOMEPAGE = "http://merbivore.com"
10
- SUMMARY = "Merb plugin that provides ActiveRecord support for Merb"
7
+ ##############################################################################
8
+ # Package && release
9
+ ##############################################################################
10
+ RUBY_FORGE_PROJECT = "merb"
11
+ PROJECT_URL = "http://merbivore.com"
12
+ PROJECT_SUMMARY = "Merb plugin that provides ActiveRecord support for Merb"
13
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY
14
+
15
+ GEM_AUTHOR = "Duane Johnson"
16
+ GEM_EMAIL = "canadaduane@gmail.com"
17
+
18
+ GEM_NAME = "merb_activerecord"
19
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
+ GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
21
+
22
+ RELEASE_NAME = "REL #{GEM_VERSION}"
23
+
24
+ require "extlib/tasks/release"
11
25
 
12
26
  spec = Gem::Specification.new do |s|
13
- s.name = NAME
14
- s.version = VERSION
27
+ s.rubyforge_project = RUBY_FORGE_PROJECT
28
+ s.name = GEM_NAME
29
+ s.version = GEM_VERSION
15
30
  s.platform = Gem::Platform::RUBY
16
31
  s.has_rdoc = true
17
32
  s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
18
- s.summary = SUMMARY
19
- s.description = s.summary
20
- s.author = AUTHOR
21
- s.email = EMAIL
22
- s.homepage = HOMEPAGE
23
- s.add_dependency("merb-core", ">= 0.9.3")
24
- s.require_path = "lib"
25
- s.autorequire = PLUGIN
26
- s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,activerecord_generators}/**/*")
27
- end
28
-
29
- windows = (PLATFORM =~ /win32|cygwin/) rescue nil
30
-
31
- SUDO = windows ? "" : "sudo"
33
+ s.summary = PROJECT_SUMMARY
34
+ s.description = PROJECT_DESCRIPTION
35
+ s.author = GEM_AUTHOR
36
+ s.email = GEM_EMAIL
37
+ s.homepage = PROJECT_URL
38
+ s.add_dependency('merb-core', '>= 0.9.4')
39
+ s.require_path = 'lib'
40
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*") end
32
41
 
33
42
  Rake::GemPackageTask.new(spec) do |pkg|
34
43
  pkg.gem_spec = spec
35
44
  end
36
45
 
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}
46
+ desc "Install the gem"
47
+ task :install => [:package] do
48
+ sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
49
+ end
50
+
51
+ namespace :jruby do
52
+
53
+ desc "Run :package and install the resulting .gem with jruby"
54
+ task :install => :package do
55
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
56
+ end
57
+
40
58
  end
41
59
 
42
- desc "Release the current version on rubyforge"
43
- task :release => :package do
44
- sh %{rubyforge add_release merb #{PLUGIN} #{VERSION} pkg/#{NAME}-#{VERSION}.gem}
60
+ desc "Run all specs"
61
+ Spec::Rake::SpecTask.new("specs") do |t|
62
+ t.spec_opts = ["--format", "specdoc", "--colour"]
63
+ t.spec_files = Dir["spec/**/*_spec.rb"].sort
45
64
  end
@@ -57,7 +57,7 @@ namespace :db do
57
57
  when 'mysql'
58
58
  ActiveRecord::Base.connection.drop_database config[:database]
59
59
  when /^sqlite/
60
- FileUtils.rm(File.join(RAILS_ROOT, config[:database]))
60
+ FileUtils.rm(File.join(Merb.root, config[:database]))
61
61
  when 'postgresql'
62
62
  ActiveRecord::Base.clear_active_connections!
63
63
  `dropdb "#{config[:database]}"`
@@ -170,8 +170,9 @@ namespace :db do
170
170
  require 'active_record/fixtures'
171
171
  config = Merb::Orms::ActiveRecord.configurations[Merb.environment.to_sym]
172
172
  ActiveRecord::Base.establish_connection(config)
173
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Merb.root, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
174
- Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
173
+ test_folder = (Merb.test_framework_generator_scope == :rspec) ? 'spec' : 'test'
174
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Merb.root, test_folder, 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
175
+ Fixtures.create_fixtures(File.join(test_folder, 'fixtures'), File.basename(fixture_file, '.*'))
175
176
  end
176
177
  end
177
178
  end
@@ -315,13 +316,10 @@ namespace :db do
315
316
  end
316
317
 
317
318
  namespace :sessions do
318
- # desc "Creates a sessions migration for use with CGI::Session::ActiveRecordStore"
319
- # task :create => :environment do
320
- # raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
321
- # require 'rails_generator'
322
- # require 'rails_generator/scripts/generate'
323
- # Rails::Generator::Scripts::Generate.new.run(["session_migration", ENV["MIGRATION"] || "AddSessions"])
324
- # end
319
+ desc "Create sessions table"
320
+ task :create => :merb_start do
321
+ Merb::ActiveRecordSession.create_table!
322
+ end
325
323
 
326
324
  desc "Clear the sessions table"
327
325
  task :clear => :merb_start do
@@ -0,0 +1,4 @@
1
+ Merb::Generators::MigrationGenerator.template :migration_activerecord, :orm => :activerecord do
2
+ source(File.dirname(__FILE__), 'templates/migration/schema/migrations/%file_name%.rb')
3
+ destination("#{destination_directory}/#{file_name}.rb")
4
+ end
@@ -0,0 +1,8 @@
1
+ Merb::Generators::ModelGenerator.template :model_activerecord, :orm => :activerecord do
2
+ source(File.dirname(__FILE__), "templates/model/app/models/%file_name%.rb")
3
+ destination("app/models", base_path, "#{file_name}.rb")
4
+ end
5
+
6
+ Merb::Generators::ModelGenerator.invoke :migration, :orm => :activerecord do |generator|
7
+ generator.new(destination_root, options.merge(:model => true), file_name, attributes)
8
+ end
@@ -0,0 +1,12 @@
1
+ Merb::Generators::ResourceControllerGenerator.template :controller_activerecord, :orm => :activerecord do
2
+ source(File.dirname(__FILE__), "templates/resource_controller/app/controllers/%file_name%.rb")
3
+ destination("app/controllers", base_path, "#{file_name}.rb")
4
+ end
5
+
6
+ [:index, :show, :edit, :new].each do |view|
7
+ Merb::Generators::ResourceControllerGenerator.template "view_#{view}_activerecord".to_sym,
8
+ :orm => :activerecord, :template_engine => :erb do
9
+ source(File.dirname(__FILE__), "templates/resource_controller/app/views/%file_name%/#{view}.html.erb")
10
+ destination("app/views", base_path, "#{file_name}/#{view}.html.erb")
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ Merb::Generators::SessionMigrationGenerator.template :session_migration_activerecord, :orm => :activerecord do
2
+ source(File.dirname(__FILE__), 'templates/session_migration/schema/migrations/%version%_sessions.rb')
3
+ destination("schema/migrations/#{version}_sessions.rb")
4
+ end
@@ -0,0 +1,19 @@
1
+ class <%= class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ <% if model -%>
4
+ create_table :<%= table_name %> do |t|
5
+ <% attributes.each do |name, type| -%>
6
+ t.<%= name %> :<%= type %>
7
+ <% end -%>
8
+
9
+ t.timestamps
10
+ end
11
+ <% end -%>
12
+ end
13
+
14
+ def self.down
15
+ <% if model -%>
16
+ drop_table :<%= table_name %>
17
+ <% end -%>
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %> < ActiveRecord::Base
3
+ end
4
+ <% end -%>
@@ -0,0 +1,57 @@
1
+ class <%= class_name %> < Application
2
+ # provides :xml, :yaml, :js
3
+
4
+ def index
5
+ @<%= plural_model %> = <%= model_class_name %>.find(:all)
6
+ display @<%= plural_model %>
7
+ end
8
+
9
+ def show
10
+ @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
11
+ raise NotFound unless @<%= singular_model %>
12
+ display @<%= singular_model %>
13
+ end
14
+
15
+ def new
16
+ only_provides :html
17
+ @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
18
+ render
19
+ end
20
+
21
+ def create
22
+ @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
23
+ if @<%= singular_model %>.save
24
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
25
+ else
26
+ render :new
27
+ end
28
+ end
29
+
30
+ def edit
31
+ only_provides :html
32
+ @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
33
+ raise NotFound unless @<%= singular_model %>
34
+ render
35
+ end
36
+
37
+ def update
38
+ @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
39
+ raise NotFound unless @<%= singular_model %>
40
+ if @<%= singular_model %>.update_attributes(params[:<%= singular_model %>])
41
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
42
+ else
43
+ raise BadRequest
44
+ end
45
+ end
46
+
47
+ def destroy
48
+ @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
49
+ raise NotFound unless @<%= singular_model %>
50
+ if @<%= singular_model %>.destroy
51
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>s)
52
+ else
53
+ raise BadRequest
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, edit action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/edit.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, index action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/index.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, new action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/new.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, show action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/show.html.erb</tt></p>
@@ -0,0 +1,14 @@
1
+ class DatabaseSessions < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :sessions do |t|
4
+ t.column :session_id, :string
5
+ t.column :data, :text
6
+ end
7
+ add_index :sessions, :session_id
8
+ end
9
+
10
+ def self.down
11
+ remove_index :sessions, :session_id
12
+ drop_table :sessions
13
+ end
14
+ end
@@ -31,7 +31,13 @@ module Merb
31
31
  end
32
32
 
33
33
  def config
34
- @config ||= (Merb::Plugins.config[:merb_active_record] = configurations[Merb.environment.to_sym])
34
+ #If Merb#runs_like specifies a differnt db env, use it.
35
+ env_sym = (Merb.environment_info.nil?) ?
36
+ Merb.environment.to_sym :
37
+ Merb.environment_info[:db_env].to_sym
38
+
39
+ raise ArgumentError, "missing environment :#{Merb.environment} in config file #{config_file}" unless configurations.key?(env_sym)
40
+ @config ||= (Merb::Plugins.config[:merb_active_record] = configurations[env_sym])
35
41
  end
36
42
 
37
43
  def configurations
@@ -62,7 +68,7 @@ module Merb
62
68
  else
63
69
  copy_sample_config
64
70
  Merb.logger.error! "No database.yml file found in #{Merb.root}/config."
65
- Merb.logger.error! "A sample file was created called database.sample.yml for you to copy and edit."
71
+ Merb.logger.error! "A sample file was created called database.yml.sample for you to copy and edit."
66
72
  exit(1)
67
73
  end
68
74
  end
@@ -15,4 +15,7 @@
15
15
 
16
16
  :production:
17
17
  <<: *defaults
18
- :database: sample_production
18
+ :database: sample_production
19
+
20
+ :rake:
21
+ <<: *defaults
@@ -47,7 +47,7 @@ module Merb
47
47
  end
48
48
 
49
49
  # Don't try to reload ARStore::Session in dev mode.
50
- def reloadable? #:nodoc:
50
+ def reloadable?
51
51
  false
52
52
  end
53
53
 
@@ -5,7 +5,7 @@ if defined?(Merb::Plugins)
5
5
 
6
6
  class Merb::Orms::ActiveRecord::Connect < Merb::BootLoader
7
7
 
8
- after BeforeAppRuns
8
+ after BeforeAppLoads
9
9
 
10
10
  def self.run
11
11
  Merb::Orms::ActiveRecord.connect
@@ -13,5 +13,11 @@ if defined?(Merb::Plugins)
13
13
  end
14
14
 
15
15
  end
16
+
17
+ generators = File.join(File.dirname(__FILE__), 'generators')
18
+ Merb.add_generators generators / :migration
19
+ Merb.add_generators generators / :model
20
+ Merb.add_generators generators / :resource_controller
21
+ Merb.add_generators generators / :session_migration
16
22
 
17
23
  end
metadata CHANGED
@@ -1,25 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb_activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duane Johnson
8
- autorequire: merb_activerecord
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-04 00:00:00 -05:00
12
+ date: 2008-08-13 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: merb-core
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.9.3
23
+ version: 0.9.4
23
24
  version:
24
25
  description: Merb plugin that provides ActiveRecord support for Merb
25
26
  email: canadaduane@gmail.com
@@ -38,6 +39,34 @@ files:
38
39
  - TODO
39
40
  - lib/active_record
40
41
  - lib/active_record/merbtasks.rb
42
+ - lib/generators
43
+ - lib/generators/migration.rb
44
+ - lib/generators/model.rb
45
+ - lib/generators/resource_controller.rb
46
+ - lib/generators/session_migration.rb
47
+ - lib/generators/templates
48
+ - lib/generators/templates/migration
49
+ - lib/generators/templates/migration/schema
50
+ - lib/generators/templates/migration/schema/migrations
51
+ - lib/generators/templates/migration/schema/migrations/%file_name%.rb
52
+ - lib/generators/templates/model
53
+ - lib/generators/templates/model/app
54
+ - lib/generators/templates/model/app/models
55
+ - lib/generators/templates/model/app/models/%file_name%.rb
56
+ - lib/generators/templates/resource_controller
57
+ - lib/generators/templates/resource_controller/app
58
+ - lib/generators/templates/resource_controller/app/controllers
59
+ - lib/generators/templates/resource_controller/app/controllers/%file_name%.rb
60
+ - lib/generators/templates/resource_controller/app/views
61
+ - lib/generators/templates/resource_controller/app/views/%file_name%
62
+ - lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb
63
+ - lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb
64
+ - lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb
65
+ - lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb
66
+ - lib/generators/templates/session_migration
67
+ - lib/generators/templates/session_migration/schema
68
+ - lib/generators/templates/session_migration/schema/migrations
69
+ - lib/generators/templates/session_migration/schema/migrations/%version%_sessions.rb
41
70
  - lib/merb
42
71
  - lib/merb/orms
43
72
  - lib/merb/orms/active_record
@@ -48,40 +77,6 @@ files:
48
77
  - lib/merb_activerecord.rb
49
78
  - specs/merb_active_record_spec.rb
50
79
  - specs/spec_helper.rb
51
- - activerecord_generators/database_sessions_migration
52
- - activerecord_generators/database_sessions_migration/database_sessions_migration_generator.rb
53
- - activerecord_generators/database_sessions_migration/templates
54
- - activerecord_generators/database_sessions_migration/templates/sessions_migration.erb
55
- - activerecord_generators/database_sessions_migration/USAGE
56
- - activerecord_generators/migration
57
- - activerecord_generators/migration/migration_generator.rb
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
62
- - activerecord_generators/migration/USAGE
63
- - activerecord_generators/model
64
- - activerecord_generators/model/model_generator.rb
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
69
- - activerecord_generators/model/USAGE
70
- - activerecord_generators/resource_controller
71
- - activerecord_generators/resource_controller/resource_controller_generator.rb
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
84
- - activerecord_generators/resource_controller/USAGE
85
80
  has_rdoc: true
86
81
  homepage: http://merbivore.com
87
82
  post_install_message:
@@ -103,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
98
  version:
104
99
  requirements: []
105
100
 
106
- rubyforge_project:
107
- rubygems_version: 1.0.1
101
+ rubyforge_project: merb
102
+ rubygems_version: 1.2.0
108
103
  signing_key:
109
104
  specification_version: 2
110
105
  summary: Merb plugin that provides ActiveRecord support for Merb
@@ -1,5 +0,0 @@
1
- Description:
2
-
3
-
4
- Usage:
5
-
@@ -1,53 +0,0 @@
1
- class DatabaseSessionsMigrationGenerator < Merb::GeneratorBase
2
-
3
- default_options :author => nil
4
-
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 ""
9
- super
10
- @name = 'database_sessions'
11
- end
12
-
13
- def manifest
14
- record do |m|
15
- # Ensure appropriate folder(s) exists
16
- m.directory 'schema/migrations'
17
-
18
- # Create stubs
19
- highest_migration = Dir[Dir.pwd+'/schema/migrations/*'].map{|f| File.basename(f) =~ /^(\d+)/; $1}.max
20
- filename = format("%03d_%s", (highest_migration.to_i+1), @name.snake_case)
21
- m.template "sessions_migration.erb", "schema/migrations/#{filename}.rb"
22
- puts banner
23
-
24
- end
25
- end
26
-
27
- protected
28
- def banner
29
- <<-EOS
30
- A migration to add sessions to your database has been created.
31
- Run 'rake db:migrate' to add the sessions migration to your database.
32
-
33
- EOS
34
- end
35
-
36
- def add_options!(opts)
37
- # opts.separator ''
38
- # opts.separator 'Options:'
39
- # For each option below, place the default
40
- # at the top of the file next to "default_options"
41
- # opts.on("-a", "--author=\"Your Name\"", String,
42
- # "Some comment about this option",
43
- # "Default: none") { |options[:author]| }
44
- # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
45
- end
46
-
47
- def extract_options
48
- # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
49
- # Templates can access these value via the attr_reader-generated methods, but not the
50
- # raw instance variable value.
51
- # @author = options[:author]
52
- end
53
- end
@@ -1,15 +0,0 @@
1
- class DatabaseSessions < ActiveRecord::Migration
2
- def self.up
3
- create_table :sessions do |t|
4
- t.column :session_id, :text
5
- t.column :data, :text
6
- end
7
- end
8
-
9
- def self.down
10
- drop_table :sessions
11
- end
12
- end
13
-
14
-
15
-
@@ -1,5 +0,0 @@
1
- Description:
2
-
3
-
4
- Usage:
5
-
@@ -1,42 +0,0 @@
1
- class MigrationGenerator < Merb::GeneratorBase
2
- attr_reader :model_attributes, :model_class_name, :model_file_name, :table_name
3
-
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)]
11
- end
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"
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
-
42
- end
@@ -1,17 +0,0 @@
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,4 +0,0 @@
1
- Description:
2
-
3
-
4
- Usage:
@@ -1,41 +0,0 @@
1
- class ModelGenerator < Merb::GeneratorBase
2
- attr_reader :model_attributes, :model_class_name, :model_file_name, :migration_args
3
-
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
-
14
- end
15
-
16
- def manifest
17
- record do |m|
18
- @m = m
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
-
41
- end
@@ -1,2 +0,0 @@
1
- class <%= model_class_name %> < ActiveRecord::Base
2
- end
File without changes
@@ -1,74 +0,0 @@
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
35
-
36
- @full_controller_const = ((@controller_modules.dup || []) << @controller_class_name).join("::")
37
- end
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
64
- end
65
-
66
- protected
67
- def banner
68
- <<-EOS.split("\n").map{|x| x.strip}.join("\n")
69
- Creates a basic Merb resource controller.
70
-
71
- USAGE: #{spec.name} my_resource
72
- EOS
73
- end
74
- end
@@ -1,68 +0,0 @@
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 -%>
@@ -1,16 +0,0 @@
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,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, edit action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/edit.html.erb</tt></p>
@@ -1,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, index action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/index.html.erb</tt></p>
@@ -1,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, new action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/new.html.erb</tt></p>
@@ -1,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, show action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/show.html.erb</tt></p>