merb_sequel 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/Rakefile +70 -39
  2. data/lib/generators/migration.rb +4 -0
  3. data/lib/generators/model.rb +8 -0
  4. data/lib/generators/resource_controller.rb +12 -0
  5. data/lib/generators/session_migration.rb +4 -0
  6. data/lib/generators/templates/migration/schema/migrations/%file_name%.rb +24 -0
  7. data/lib/generators/templates/model/app/models/%file_name%.rb +4 -0
  8. data/lib/generators/templates/resource_controller/app/controllers/%file_name%.rb +59 -0
  9. data/lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb +3 -0
  10. data/lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb +3 -0
  11. data/lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb +3 -0
  12. data/lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb +3 -0
  13. data/{sequel_generators/database_sessions_migration/templates/sessions_migration.erb → lib/generators/templates/session_migration/schema/migrations/%version%_sessions.rb} +2 -2
  14. data/lib/merb/orms/sequel/connection.rb +1 -1
  15. data/lib/merb/session/sequel_session.rb +7 -3
  16. data/lib/merb_sequel.rb +7 -1
  17. metadata +37 -41
  18. data/sequel_generators/database_sessions_migration/USAGE +0 -5
  19. data/sequel_generators/database_sessions_migration/database_sessions_migration_generator.rb +0 -53
  20. data/sequel_generators/migration/USAGE +0 -5
  21. data/sequel_generators/migration/migration_generator.rb +0 -42
  22. data/sequel_generators/migration/templates/schema/migrations/%migration_file_name%.rb +0 -23
  23. data/sequel_generators/model/USAGE +0 -0
  24. data/sequel_generators/model/model_generator.rb +0 -41
  25. data/sequel_generators/model/templates/app/models/%model_file_name%.rb +0 -2
  26. data/sequel_generators/resource_controller/USAGE +0 -0
  27. data/sequel_generators/resource_controller/resource_controller_generator.rb +0 -74
  28. data/sequel_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb +0 -68
  29. data/sequel_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb +0 -16
  30. data/sequel_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb +0 -3
  31. data/sequel_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb +0 -3
  32. data/sequel_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb +0 -3
  33. data/sequel_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb +0 -3
data/Rakefile CHANGED
@@ -1,48 +1,79 @@
1
- require "rubygems"
2
- require "rake/gempackagetask"
3
-
4
- PLUGIN = "merb_sequel"
5
- NAME = "merb_sequel"
6
- VERSION = "0.9.3"
7
- AUTHOR = "Wayne E. Seguin, Lance Carlson"
8
- EMAIL = "wayneeseguin@gmail.com, lancecarlson@gmail.com"
9
- HOMEPAGE = "http://merb-plugins.rubyforge.org/merb_sequel/"
10
- SUMMARY = "Merb plugin that provides support for Sequel and Sequel::Model"
11
-
12
- specification = Gem::Specification.new do |spec|
13
- spec.name = NAME
14
- spec.email = EMAIL
15
- spec.author = AUTHOR
16
- spec.version = VERSION
17
- spec.summary = SUMMARY
18
- spec.platform = Gem::Platform::RUBY
19
- spec.has_rdoc = true
20
- spec.homepage = HOMEPAGE
21
- spec.description = SUMMARY
22
- spec.autorequire = PLUGIN
23
- spec.require_path = "lib"
24
- spec.extra_rdoc_files = ["README", "LICENSE", 'TODO']
25
- # Dependencies
26
- #spec.add_dependency("merb", ">= 0.9")
27
- spec.add_dependency("merb-core", ">= 0.9.3") # This will probably only be temporary until there is an official merb gem greater than 0.9
28
- spec.add_dependency("sequel", ">= 1.4.0")
29
- spec.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,sequel_generators}/**/*")
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require "rake/rdoctask"
4
+ require "extlib"
5
+ require 'merb-core/tasks/merb_rake_helper'
6
+ require "spec/rake/spectask"
7
+
8
+ ##############################################################################
9
+ # Package && release
10
+ ##############################################################################
11
+ RUBY_FORGE_PROJECT = "merb"
12
+ PROJECT_URL = "http://merbivore.com"
13
+ PROJECT_SUMMARY = "Merb plugin that provides support for Sequel and Sequel::Model"
14
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY
15
+
16
+ GEM_AUTHOR = "Wayne E. Seguin, Lance Carlson"
17
+ GEM_EMAIL = "wayneeseguin@gmail.com, lancecarlson@gmail.com"
18
+
19
+ GEM_NAME = "merb_sequel"
20
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
21
+ GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
22
+
23
+ RELEASE_NAME = "REL #{GEM_VERSION}"
24
+
25
+ require "extlib/tasks/release"
26
+
27
+ spec = Gem::Specification.new do |s|
28
+ s.rubyforge_project = RUBY_FORGE_PROJECT
29
+ s.name = GEM_NAME
30
+ s.version = GEM_VERSION
31
+ s.platform = Gem::Platform::RUBY
32
+ s.has_rdoc = true
33
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
34
+ s.summary = PROJECT_SUMMARY
35
+ s.description = PROJECT_DESCRIPTION
36
+ s.author = GEM_AUTHOR
37
+ s.email = GEM_EMAIL
38
+ s.homepage = PROJECT_URL
39
+ s.add_dependency("merb-core", ">= 0.9.4")
40
+ s.add_dependency("sequel", ">= 1.4.0")
41
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,sequel_generators}/**/*")
30
42
  end
31
43
 
32
- windows = (PLATFORM =~ /win32|cygwin/) rescue nil
44
+ Rake::GemPackageTask.new(spec) do |pkg|
45
+ pkg.gem_spec = spec
46
+ end
33
47
 
34
- SUDO = windows ? "" : "sudo"
48
+ ##############################################################################
49
+ # Installation
50
+ ##############################################################################
51
+ desc "Install the gem"
52
+ task :install => [:package] do
53
+ sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
54
+ end
35
55
 
36
- Rake::GemPackageTask.new(specification) do |package|
37
- package.gem_spec = specification
56
+ namespace :jruby do
57
+ desc "Run :package and install the resulting .gem with jruby"
58
+ task :install => :package do
59
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
60
+ end
38
61
  end
39
62
 
40
- desc "Install merb_sequel"
41
- task :install => :package do
42
- sh %{#{SUDO} gem install pkg/#{NAME}-#{VERSION} --no-rdoc --no-ri --no-update-sources}
63
+ ##############################################################################
64
+ # Specs
65
+ ##############################################################################
66
+ desc "Run all specs"
67
+ Spec::Rake::SpecTask.new("specs") do |t|
68
+ t.spec_opts = ["--format", "specdoc", "--colour"]
69
+ t.spec_files = Dir["spec/**/*_spec.rb"].sort
43
70
  end
44
71
 
45
- desc 'Release the current version on rubyforge'
46
- task :release => :package do
47
- sh %{rubyforge add_release merb #{PLUGIN} #{VERSION} pkg/#{NAME}-#{VERSION}.gem}
72
+ desc "Run all specs and generate an rcov report"
73
+ Spec::Rake::SpecTask.new('rcov') do |t|
74
+ t.spec_files = FileList['spec/**/*_spec.rb']
75
+ t.spec_opts = ["--format", "specdoc", "--colour"]
76
+ t.rcov = true
77
+ t.rcov_dir = 'coverage'
78
+ t.rcov_opts = ['--exclude', 'gems', '--exclude', 'spec']
48
79
  end
@@ -0,0 +1,4 @@
1
+ Merb::Generators::MigrationGenerator.template :migration_sequel, :orm => :sequel 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_sequel, :orm => :sequel 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 => :sequel 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_sequel, :orm => :sequel 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}_sequel".to_sym,
8
+ :orm => :sequel, :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_sequel, :orm => :sequel 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,24 @@
1
+ # For details on Sequel migrations see
2
+ # http://sequel.rubyforge.org/
3
+ # http://code.google.com/p/ruby-sequel/wiki/Migrations
4
+
5
+ class <%= class_name %> < Sequel::Migration
6
+
7
+ def up
8
+ <% if model -%>
9
+ create_table :<%= table_name -%> do
10
+ primary_key :id
11
+ <% attributes.each do |name, type| -%>
12
+ <%= type %> :<%= name %>
13
+ <% end -%>
14
+ end
15
+ <% end -%>
16
+ end
17
+
18
+ def down
19
+ <% if model -%>
20
+ drop_table :<%= table_name %>
21
+ <% end -%>
22
+ end
23
+
24
+ end
@@ -0,0 +1,4 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %> < Sequel::Model
3
+ end
4
+ <% end -%>
@@ -0,0 +1,59 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %> < Application
3
+ # provides :xml, :yaml, :js
4
+
5
+ def index
6
+ @<%= plural_model %> = <%= model_class_name %>.all
7
+ display @<%= plural_model %>
8
+ end
9
+
10
+ def show
11
+ @<%= singular_model %> = <%= model_class_name %>[params[:id]]
12
+ raise NotFound unless @<%= singular_model %>
13
+ display @<%= singular_model %>
14
+ end
15
+
16
+ def new
17
+ only_provides :html
18
+ @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
19
+ render
20
+ end
21
+
22
+ def create
23
+ @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
24
+ if @<%= singular_model %>.save
25
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
26
+ else
27
+ render :new
28
+ end
29
+ end
30
+
31
+ def edit
32
+ only_provides :html
33
+ @<%= singular_model %> = <%= model_class_name %>[params[:id]]
34
+ raise NotFound unless @<%= singular_model %>
35
+ render
36
+ end
37
+
38
+ def update
39
+ @<%= singular_model %> = <%= model_class_name %>[params[:id]]
40
+ raise NotFound unless @<%= singular_model %>
41
+ if @<%= singular_model %>.update(params[:<%= singular_model %>])
42
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
43
+ else
44
+ raise BadRequest
45
+ end
46
+ end
47
+
48
+ def destroy
49
+ @<%= singular_model %> = <%= model_class_name %>[params[:id]]
50
+ raise NotFound unless @<%= singular_model %>
51
+ if @<%= singular_model %>.destroy
52
+ redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>s)
53
+ else
54
+ raise BadRequest
55
+ end
56
+ end
57
+
58
+ end
59
+ <% 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>
@@ -8,9 +8,9 @@ class AddSessionsTable < Sequel::Migration
8
8
  text :data
9
9
  end
10
10
  end
11
-
11
+
12
12
  def down
13
13
  drop_table :sessions
14
14
  end
15
15
 
16
- end
16
+ end
@@ -43,7 +43,7 @@ module Merb
43
43
  copy_sample_config
44
44
  Merb.logger.set_log(STDERR)
45
45
  Merb.logger.error! "No database.yml file found in #{Merb.root}/config."
46
- Merb.logger.error! "A sample file was created called config/database.sample.yml for you to copy and edit."
46
+ Merb.logger.error! "A sample file was created called config/database.yml.sample for you to copy and edit."
47
47
  exit(1)
48
48
  end
49
49
 
@@ -45,7 +45,7 @@ module Merb
45
45
  # If none is found, generates a new session.
46
46
  def persist(session_id)
47
47
  if session_id
48
- session = find_by_session_id(session_id)
48
+ session = find(:session_id => session_id)
49
49
  end
50
50
  unless session
51
51
  session = generate
@@ -54,7 +54,7 @@ module Merb
54
54
  end
55
55
 
56
56
  # Don't try to reload ARStore::Session in dev mode.
57
- def reloadable? #:nodoc:
57
+ def reloadable?
58
58
  false
59
59
  end
60
60
 
@@ -106,6 +106,10 @@ module Merb
106
106
  def each(&b)
107
107
  data.each(&b)
108
108
  end
109
+
110
+ def each_with_index(&b)
111
+ data.each_with_index(&b)
112
+ end
109
113
 
110
114
  # Lazy-unmarshal session state.
111
115
  def data
@@ -149,4 +153,4 @@ module Merb
149
153
  puts "Created sessions table."
150
154
  end
151
155
 
152
- end
156
+ end
data/lib/merb_sequel.rb CHANGED
@@ -5,7 +5,7 @@ if defined?(Merb::Plugins)
5
5
 
6
6
  class Merb::Orms::Sequel::Connect < Merb::BootLoader
7
7
 
8
- after BeforeAppRuns
8
+ after BeforeAppLoads
9
9
 
10
10
  def self.run
11
11
  Merb::Orms::Sequel.connect
@@ -14,4 +14,10 @@ if defined?(Merb::Plugins)
14
14
 
15
15
  end
16
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
22
+
17
23
  end
metadata CHANGED
@@ -1,28 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb_sequel
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
  - Wayne E. Seguin, Lance Carlson
8
- autorequire: merb_sequel
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
  - !ruby/object:Gem::Dependency
25
26
  name: sequel
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -45,6 +47,34 @@ files:
45
47
  - README
46
48
  - Rakefile
47
49
  - TODO
50
+ - lib/generators
51
+ - lib/generators/migration.rb
52
+ - lib/generators/model.rb
53
+ - lib/generators/resource_controller.rb
54
+ - lib/generators/session_migration.rb
55
+ - lib/generators/templates
56
+ - lib/generators/templates/migration
57
+ - lib/generators/templates/migration/schema
58
+ - lib/generators/templates/migration/schema/migrations
59
+ - lib/generators/templates/migration/schema/migrations/%file_name%.rb
60
+ - lib/generators/templates/model
61
+ - lib/generators/templates/model/app
62
+ - lib/generators/templates/model/app/models
63
+ - lib/generators/templates/model/app/models/%file_name%.rb
64
+ - lib/generators/templates/resource_controller
65
+ - lib/generators/templates/resource_controller/app
66
+ - lib/generators/templates/resource_controller/app/controllers
67
+ - lib/generators/templates/resource_controller/app/controllers/%file_name%.rb
68
+ - lib/generators/templates/resource_controller/app/views
69
+ - lib/generators/templates/resource_controller/app/views/%file_name%
70
+ - lib/generators/templates/resource_controller/app/views/%file_name%/edit.html.erb
71
+ - lib/generators/templates/resource_controller/app/views/%file_name%/index.html.erb
72
+ - lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb
73
+ - lib/generators/templates/resource_controller/app/views/%file_name%/show.html.erb
74
+ - lib/generators/templates/session_migration
75
+ - lib/generators/templates/session_migration/schema
76
+ - lib/generators/templates/session_migration/schema/migrations
77
+ - lib/generators/templates/session_migration/schema/migrations/%version%_sessions.rb
48
78
  - lib/merb
49
79
  - lib/merb/orms
50
80
  - lib/merb/orms/sequel
@@ -57,42 +87,8 @@ files:
57
87
  - lib/merb_sequel.rb
58
88
  - specs/merb_sequel_spec.rb
59
89
  - specs/spec_helper.rb
60
- - sequel_generators/database_sessions_migration
61
- - sequel_generators/database_sessions_migration/database_sessions_migration_generator.rb
62
- - sequel_generators/database_sessions_migration/templates
63
- - sequel_generators/database_sessions_migration/templates/sessions_migration.erb
64
- - sequel_generators/database_sessions_migration/USAGE
65
- - sequel_generators/migration
66
- - sequel_generators/migration/migration_generator.rb
67
- - sequel_generators/migration/templates
68
- - sequel_generators/migration/templates/schema
69
- - sequel_generators/migration/templates/schema/migrations
70
- - sequel_generators/migration/templates/schema/migrations/%migration_file_name%.rb
71
- - sequel_generators/migration/USAGE
72
- - sequel_generators/model
73
- - sequel_generators/model/model_generator.rb
74
- - sequel_generators/model/templates
75
- - sequel_generators/model/templates/app
76
- - sequel_generators/model/templates/app/models
77
- - sequel_generators/model/templates/app/models/%model_file_name%.rb
78
- - sequel_generators/model/USAGE
79
- - sequel_generators/resource_controller
80
- - sequel_generators/resource_controller/resource_controller_generator.rb
81
- - sequel_generators/resource_controller/templates
82
- - sequel_generators/resource_controller/templates/app
83
- - sequel_generators/resource_controller/templates/app/controllers
84
- - sequel_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb
85
- - sequel_generators/resource_controller/templates/app/helpers
86
- - sequel_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb
87
- - sequel_generators/resource_controller/templates/app/views
88
- - sequel_generators/resource_controller/templates/app/views/%controller_file_name%
89
- - sequel_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb
90
- - sequel_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb
91
- - sequel_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb
92
- - sequel_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb
93
- - sequel_generators/resource_controller/USAGE
94
90
  has_rdoc: true
95
- homepage: http://merb-plugins.rubyforge.org/merb_sequel/
91
+ homepage: http://merbivore.com
96
92
  post_install_message:
97
93
  rdoc_options: []
98
94
 
@@ -112,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
108
  version:
113
109
  requirements: []
114
110
 
115
- rubyforge_project:
116
- rubygems_version: 1.0.1
111
+ rubyforge_project: merb
112
+ rubygems_version: 1.2.0
117
113
  signing_key:
118
114
  specification_version: 2
119
115
  summary: Merb plugin that provides support for Sequel and Sequel::Model
@@ -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 sequel: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,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)
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 a Sequel Migration stub..
37
-
38
- USAGE: #{spec.name}"
39
- EOS
40
- end
41
-
42
- end
@@ -1,23 +0,0 @@
1
- # For details on Sequel migrations see
2
- # http://sequel.rubyforge.org/
3
- # http://code.google.com/p/ruby-sequel/wiki/Migrations
4
-
5
- class <%= model_class_name %>Migration < Sequel::Migration
6
-
7
- def up
8
- <%= "create_table :#{table_name} do" if table_name %>
9
- <% if model_attributes.empty? -%>
10
- primary_key :id
11
- <% else -%>
12
- <% model_attributes.each do |attribute| -%>
13
- <%= attribute.last %> :<%= attribute.first %>
14
- <% end -%>
15
- <% end -%>
16
- <%= "end" if table_name %>
17
- end
18
-
19
- def down
20
- <% "drop_table :#{table_name}" if table_name -%>
21
- end
22
-
23
- end
File without changes
@@ -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 a Sequel Model stub..
36
-
37
- USAGE: #{spec.name}"
38
- EOS
39
- end
40
-
41
- end
@@ -1,2 +0,0 @@
1
- class <%= model_class_name %> < Sequel::Model
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 %>.all
12
- <%= " " * counter %> display @<%= plural_model %>
13
- <%= " " * counter %> end
14
-
15
- <%= " " * counter %> def show
16
- <%= " " * counter %> @<%= singular_model %> = <%= model_class_name %>[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 %>[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 %>[params[:id]]
45
- <%= " " * counter %> raise NotFound unless @<%= singular_model %>
46
- <%= " " * counter %> if @<%= singular_model %>.update(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 %>[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>