merb_sequel 0.5 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/Rakefile +12 -6
  2. data/lib/merb/orms/sequel/connection.rb +12 -9
  3. data/lib/merb/orms/sequel/{database.sample.yml → database.yml.sample} +0 -0
  4. data/lib/merb/session/sequel_session.rb +5 -4
  5. data/lib/merb_sequel.rb +13 -8
  6. data/lib/merb_sequel/merbtasks.rb +40 -0
  7. data/sequel_generators/database_sessions_migration/USAGE +5 -0
  8. data/sequel_generators/database_sessions_migration/database_sessions_migration_generator.rb +53 -0
  9. data/{lib/merb/session/001_add_sessions_table.rb → sequel_generators/database_sessions_migration/templates/sessions_migration.erb} +0 -0
  10. data/sequel_generators/migration/migration_generator.rb +37 -9
  11. data/sequel_generators/migration/templates/{new_migration.erb → schema/migrations/%migration_file_name%.rb} +4 -4
  12. data/sequel_generators/model/model_generator.rb +36 -11
  13. data/sequel_generators/model/templates/app/models/%model_file_name%.rb +2 -0
  14. data/sequel_generators/resource_controller/resource_controller_generator.rb +66 -19
  15. data/sequel_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb +68 -0
  16. data/sequel_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb +16 -0
  17. data/sequel_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb +3 -0
  18. data/sequel_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb +3 -0
  19. data/sequel_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb +3 -0
  20. data/sequel_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb +3 -0
  21. metadata +98 -77
  22. data/lib/merbtasks.rb +0 -34
  23. data/sequel_generators/model/templates/sequel_model_template.erb +0 -2
  24. data/sequel_generators/resource_controller/templates/controller.rb +0 -56
  25. data/sequel_generators/resource_controller/templates/edit.html.erb +0 -1
  26. data/sequel_generators/resource_controller/templates/helper.rb +0 -5
  27. data/sequel_generators/resource_controller/templates/index.html.erb +0 -1
  28. data/sequel_generators/resource_controller/templates/new.html.erb +0 -1
  29. data/sequel_generators/resource_controller/templates/show.html.erb +0 -1
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require "rake/gempackagetask"
3
3
 
4
4
  PLUGIN = "merb_sequel"
5
5
  NAME = "merb_sequel"
6
- VERSION = "0.5"
6
+ VERSION = "0.9.2"
7
7
  AUTHOR = "Wayne E. Seguin, Lance Carlson"
8
8
  EMAIL = "wayneeseguin@gmail.com, lancecarlson@gmail.com"
9
9
  HOMEPAGE = "http://merb-plugins.rubyforge.org/merb_sequel/"
@@ -23,21 +23,27 @@ specification = Gem::Specification.new do |spec|
23
23
  spec.require_path = "lib"
24
24
  spec.extra_rdoc_files = ["README", "LICENSE", 'TODO']
25
25
  # Dependencies
26
- spec.add_dependency("merb", ">= 0.5")
26
+ #spec.add_dependency("merb", ">= 0.9")
27
+ spec.add_dependency("merb-core", ">= 0.9.2") # This will probably only be temporary until there is an official merb gem greater than 0.9
27
28
  spec.add_dependency("sequel", ">= 1.0.0")
28
- spec.add_dependency("sequel_model", ">= 0.2")
29
+ spec.add_dependency("sequel_model", ">= 0.3.3")
29
30
  spec.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,sequel_generators}/**/*")
30
31
  end
31
32
 
33
+ windows = (PLATFORM =~ /win32|cygwin/) rescue nil
34
+
35
+ SUDO = windows ? "" : "sudo"
36
+
32
37
  Rake::GemPackageTask.new(specification) do |package|
33
38
  package.gem_spec = specification
34
39
  end
35
40
 
36
- task :install do
37
- sh %{rake package}
38
- sh %{sudo gem install pkg/#{NAME}-#{VERSION}}
41
+ desc "Install merb_sequel"
42
+ task :install => :package do
43
+ sh %{#{SUDO} gem install pkg/#{NAME}-#{VERSION} --no-rdoc --no-ri --no-update-sources}
39
44
  end
40
45
 
46
+ desc 'Release the current version on rubyforge'
41
47
  task :release => :package do
42
48
  sh %{rubyforge add_release merb #{PLUGIN} #{VERSION} pkg/#{NAME}-#{VERSION}.gem}
43
49
  end
@@ -7,8 +7,8 @@ module Merb
7
7
  class << self
8
8
 
9
9
  def config_file() Merb.root / "config" / "database.yml" end
10
- def sample_dest() Merb.root / "config" / "database.sample.yml" end
11
- def sample_source() File.dirname(__FILE__) / "database.sample.yml" end
10
+ def sample_dest() Merb.root / "config" / "database.yml.sample" end
11
+ def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
12
12
 
13
13
  def copy_sample_config
14
14
  FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
@@ -36,14 +36,15 @@ module Merb
36
36
  require "sequel_model"
37
37
 
38
38
  if File.exists?(config_file)
39
- puts "#{Time.now.httpdate}: Connecting to the '#{config[:database]}' database on '#{config[:host]}' using '#{config[:adapter]}' ..."
39
+ Merb.logger.info!("Connecting to the '#{config[:database]}' database on '#{config[:host]}' using '#{config[:adapter]}' ...")
40
40
  connection = ::Sequel.connect(config_options(config))
41
- Merb.logger.error("Connection Error: #{e}") unless connection
41
+ Merb.logger.error!("Connection Error: #{e}") unless connection
42
42
  connection
43
43
  else
44
44
  copy_sample_config
45
- puts "#{Time.now.httpdate}: No database.yml file found in #{Merb.root}/config."
46
- puts "A sample file was created called config/database.sample.yml for you to copy and edit."
45
+ Merb.logger.set_log(STDERR)
46
+ Merb.logger.error! "No database.yml file found in #{Merb.root}/config."
47
+ Merb.logger.error! "A sample file was created called config/database.sample.yml for you to copy and edit."
47
48
  exit(1)
48
49
  end
49
50
 
@@ -67,9 +68,11 @@ module Merb
67
68
  # Registering this ORM lets the user choose sequel as a session store
68
69
  # in merb.yml's session_store: option.
69
70
  def register_session_type
70
- Merb::BootLoader.register_session_type("sequel",
71
- "merb/session/sequel_session",
72
- "Using Sequel database sessions")
71
+ Merb.register_session_type(
72
+ "sequel",
73
+ "merb/session/sequel_session",
74
+ "Using Sequel database sessions"
75
+ )
73
76
  end
74
77
 
75
78
  end
@@ -3,9 +3,7 @@ require "base64"
3
3
  module Merb
4
4
 
5
5
  module SessionMixin
6
-
7
6
  def setup_session
8
- Merb.logger.info("Setting up session")
9
7
  before = cookies[_session_id_key]
10
8
  request.session, cookies[_session_id_key] = Merb::SequelSession.persist(cookies[_session_id_key])
11
9
  @_fingerprint = Marshal.dump(request.session.data).hash
@@ -13,9 +11,12 @@ module Merb
13
11
  end
14
12
 
15
13
  def finalize_session
16
- Merb.logger.info("Finalize session")
17
14
  request.session.save if @_fingerprint != Marshal.dump(request.session.data).hash
18
- set_cookie(_session_id_key, request.session.values[:session_id], _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
15
+ set_cookie(_session_id_key, request.session.values[:session_id], Time.now + _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
16
+ end
17
+
18
+ def session_store_type
19
+ "sequel"
19
20
  end
20
21
 
21
22
  end
@@ -1,12 +1,17 @@
1
- # make sure we're running inside Merb
2
1
  if defined?(Merb::Plugins)
3
- if Merb::BootLoader.app_loaded?
4
- puts "Warning: The merb_sequel gem must be loaded before the application"
5
- else
6
- require "merb/orms/sequel/connection"
7
- Merb::Orms::Sequel.connect
8
- Merb::Orms::Sequel.register_session_type
2
+ Merb::Plugins.config[:merb_sequel] = {}
3
+ require File.join(File.dirname(__FILE__) / "merb" / "orms" / "sequel" / "connection")
4
+ Merb::Plugins.add_rakefiles "merb_sequel" / "merbtasks"
5
+
6
+ class Merb::Orms::Sequel::Connect < Merb::BootLoader
7
+
8
+ after BeforeAppRuns
9
+
10
+ def self.run
11
+ Merb::Orms::Sequel.connect
12
+ Merb::Orms::Sequel.register_session_type
13
+ end
14
+
9
15
  end
10
16
 
11
- Merb::Plugins.add_rakefiles "merbtasks"
12
17
  end
@@ -0,0 +1,40 @@
1
+ require "fileutils"
2
+
3
+ namespace :sequel do
4
+
5
+ task :merb_start do
6
+ Merb.start :adapter => 'runner',
7
+ :environment => ENV['MERB_ENV'] || 'development'
8
+ end
9
+
10
+ namespace :db do
11
+
12
+ desc "Perform migration using migrations in schema/migrations"
13
+ task :migrate => :merb_start do
14
+ Sequel::Migrator.apply(Merb::Orms::Sequel.connect, "schema/migrations", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
15
+ end
16
+
17
+ end
18
+
19
+ namespace :sessions do
20
+
21
+ desc "Creates session migration"
22
+ task :create => :merb_start do
23
+ migration_exists = Dir[File.join(Merb.root,"schema", "migrations", "*.rb")].detect{ |f| f =~ /database_sessions\.rb/ }
24
+ if migration_exists
25
+ puts "\nThe Session Migration File already exists\n\n"
26
+ else
27
+ sh %{merb-gen database_sessions_migration}
28
+ end
29
+ end
30
+
31
+ desc "Clears sessions"
32
+ task :clear => :merb_start do
33
+ table_name = ((Merb::Plugins.config[:sequel] || {})[:session_table_name] || "sessions")
34
+
35
+ Merb::Orms::Sequel.connect.execute("DELETE FROM #{table_name}")
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,53 @@
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,14 +1,42 @@
1
- require "merb/generators/merb_generator_helpers"
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( *args )
6
- super( *args )
7
- @migration_template_name = "new_migration.erb"
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 self.superclass
11
- RubiGen::Base
12
- end
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)
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 a Sequel Migration stub..
37
+
38
+ USAGE: #{spec.name}"
39
+ EOS
40
+ end
41
+
14
42
  end
@@ -2,15 +2,15 @@
2
2
  # http://sequel.rubyforge.org/
3
3
  # http://code.google.com/p/ruby-sequel/wiki/Migrations
4
4
 
5
- class <%= class_name.snake_case.camel_case %> < Sequel::Migration
5
+ class <%= model_class_name %>Migration < Sequel::Migration
6
6
 
7
7
  def up
8
8
  <%= "create_table :#{table_name} do" if table_name %>
9
- <% if table_attributes.empty? -%>
9
+ <% if model_attributes.empty? -%>
10
10
  primary_key :id
11
11
  <% else -%>
12
- <% table_attributes.each do |attribute| -%>
13
- <%= attribute.type %> :<%= attribute.name %>
12
+ <% model_attributes.each do |attribute| -%>
13
+ <%= attribute.last %> :<%= attribute.first %>
14
14
  <% end -%>
15
15
  <% end -%>
16
16
  <%= "end" if table_name %>
@@ -1,16 +1,41 @@
1
- require "merb/generators/merb_generator_helpers"
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( *args )
6
- super( *args )
7
- @model_template_name = "sequel_model_template.erb"
8
- @migration_generator_name = "migration"
9
- @model_test_generator_name = "merb_model_test"
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 self.superclass
13
- RubiGen::Base
14
- end
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 a Sequel Model stub..
36
+
37
+ USAGE: #{spec.name}"
38
+ EOS
39
+ end
40
+
16
41
  end
@@ -0,0 +1,2 @@
1
+ class <%= model_class_name %> < Sequel::Model
2
+ end
@@ -1,27 +1,74 @@
1
- require "merb/generators/merb_generator_helpers"
2
-
3
- class ResourceControllerGenerator < Merb::GeneratorHelpers::ControllerGeneratorBase
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
- def initialize(*args)
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 self.superclass
14
- RubiGen::Base
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
-
19
67
  def banner
20
- <<-EOS
21
- Creates a Merb controller, views and specs using Sequel Models
68
+ <<-EOS.split("\n").map{|x| x.strip}.join("\n")
69
+ Creates a basic Merb resource controller.
22
70
 
23
- USAGE: #{$0} #{spec.name} resource_name"
24
- EOS
71
+ USAGE: #{spec.name} my_resource
72
+ EOS
25
73
  end
26
-
27
- end
74
+ end
@@ -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 %>.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 -%>
@@ -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
@@ -0,0 +1,3 @@
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>
@@ -0,0 +1,3 @@
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>
@@ -0,0 +1,3 @@
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>
@@ -0,0 +1,3 @@
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>
metadata CHANGED
@@ -1,109 +1,130 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: merb_sequel
5
3
  version: !ruby/object:Gem::Version
6
- version: "0.5"
7
- date: 2008-01-09 00:00:00 -08:00
8
- summary: Merb plugin that provides support for Sequel and Sequel::Model
9
- require_paths:
10
- - lib
11
- email: wayneeseguin@gmail.com, lancecarlson@gmail.com
12
- homepage: http://merb-plugins.rubyforge.org/merb_sequel/
13
- rubyforge_project:
14
- description: Merb plugin that provides support for Sequel and Sequel::Model
15
- autorequire: merb_sequel
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
  - Wayne E. Seguin, Lance Carlson
8
+ autorequire: merb_sequel
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
+ - !ruby/object:Gem::Dependency
25
+ name: sequel
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.0.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: sequel_model
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.3
41
+ version:
42
+ description: Merb plugin that provides support for Sequel and Sequel::Model
43
+ email: wayneeseguin@gmail.com, lancecarlson@gmail.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - README
50
+ - LICENSE
51
+ - TODO
31
52
  files:
32
53
  - LICENSE
33
54
  - README
34
55
  - Rakefile
35
56
  - TODO
36
57
  - lib/merb
37
- - lib/merb_sequel.rb
38
- - lib/merbtasks.rb
39
58
  - lib/merb/orms
40
- - lib/merb/session
41
59
  - lib/merb/orms/sequel
42
60
  - lib/merb/orms/sequel/connection.rb
43
- - lib/merb/orms/sequel/database.sample.yml
44
- - lib/merb/session/001_add_sessions_table.rb
61
+ - lib/merb/orms/sequel/database.yml.sample
62
+ - lib/merb/session
45
63
  - lib/merb/session/sequel_session.rb
64
+ - lib/merb_sequel
65
+ - lib/merb_sequel/merbtasks.rb
66
+ - lib/merb_sequel.rb
46
67
  - specs/merb_sequel_spec.rb
47
68
  - specs/spec_helper.rb
69
+ - sequel_generators/database_sessions_migration
70
+ - sequel_generators/database_sessions_migration/database_sessions_migration_generator.rb
71
+ - sequel_generators/database_sessions_migration/templates
72
+ - sequel_generators/database_sessions_migration/templates/sessions_migration.erb
73
+ - sequel_generators/database_sessions_migration/USAGE
48
74
  - sequel_generators/migration
49
- - sequel_generators/model
50
- - sequel_generators/resource_controller
51
75
  - sequel_generators/migration/migration_generator.rb
52
76
  - sequel_generators/migration/templates
77
+ - sequel_generators/migration/templates/schema
78
+ - sequel_generators/migration/templates/schema/migrations
79
+ - sequel_generators/migration/templates/schema/migrations/%migration_file_name%.rb
53
80
  - sequel_generators/migration/USAGE
54
- - sequel_generators/migration/templates/new_migration.erb
81
+ - sequel_generators/model
55
82
  - sequel_generators/model/model_generator.rb
56
83
  - sequel_generators/model/templates
84
+ - sequel_generators/model/templates/app
85
+ - sequel_generators/model/templates/app/models
86
+ - sequel_generators/model/templates/app/models/%model_file_name%.rb
57
87
  - sequel_generators/model/USAGE
58
- - sequel_generators/model/templates/sequel_model_template.erb
88
+ - sequel_generators/resource_controller
59
89
  - sequel_generators/resource_controller/resource_controller_generator.rb
60
90
  - sequel_generators/resource_controller/templates
91
+ - sequel_generators/resource_controller/templates/app
92
+ - sequel_generators/resource_controller/templates/app/controllers
93
+ - sequel_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb
94
+ - sequel_generators/resource_controller/templates/app/helpers
95
+ - sequel_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb
96
+ - sequel_generators/resource_controller/templates/app/views
97
+ - sequel_generators/resource_controller/templates/app/views/%controller_file_name%
98
+ - sequel_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb
99
+ - sequel_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb
100
+ - sequel_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb
101
+ - sequel_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb
61
102
  - sequel_generators/resource_controller/USAGE
62
- - sequel_generators/resource_controller/templates/controller.rb
63
- - sequel_generators/resource_controller/templates/edit.html.erb
64
- - sequel_generators/resource_controller/templates/helper.rb
65
- - sequel_generators/resource_controller/templates/index.html.erb
66
- - sequel_generators/resource_controller/templates/new.html.erb
67
- - sequel_generators/resource_controller/templates/show.html.erb
68
- test_files: []
69
-
103
+ has_rdoc: true
104
+ homepage: http://merb-plugins.rubyforge.org/merb_sequel/
105
+ post_install_message:
70
106
  rdoc_options: []
71
107
 
72
- extra_rdoc_files:
73
- - README
74
- - LICENSE
75
- - TODO
76
- executables: []
77
-
78
- extensions: []
79
-
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: "0"
115
+ version:
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: "0"
121
+ version:
80
122
  requirements: []
81
123
 
82
- dependencies:
83
- - !ruby/object:Gem::Dependency
84
- name: merb
85
- version_requirement:
86
- version_requirements: !ruby/object:Gem::Version::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: "0.5"
91
- version:
92
- - !ruby/object:Gem::Dependency
93
- name: sequel
94
- version_requirement:
95
- version_requirements: !ruby/object:Gem::Version::Requirement
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: 1.0.0
100
- version:
101
- - !ruby/object:Gem::Dependency
102
- name: sequel_model
103
- version_requirement:
104
- version_requirements: !ruby/object:Gem::Version::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: "0.2"
109
- version:
124
+ rubyforge_project:
125
+ rubygems_version: 1.0.1
126
+ signing_key:
127
+ specification_version: 2
128
+ summary: Merb plugin that provides support for Sequel and Sequel::Model
129
+ test_files: []
130
+
@@ -1,34 +0,0 @@
1
- require "fileutils"
2
-
3
- namespace :sequel do
4
-
5
- namespace :db do
6
-
7
- desc "Perform migration using migrations in schema/migrations"
8
- task :migrate => :merb_env do
9
- Sequel::Migrator.apply(Merb::Orms::Sequel.connect, "schema/migrations", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
10
- end
11
-
12
- end
13
-
14
- namespace :sessions do
15
-
16
- desc "Creates session migration"
17
- task :create => :merb_env do
18
- # TODO: this should not use '001' always...
19
- dest = File.join(Merb.root, "schema", "migrations","001_add_sessions_table.rb")
20
- source = File.join(File.dirname(__FILE__), "merb", "session","001_add_sessions_table.rb")
21
-
22
- FileUtils.cp source, dest unless File.exists?(dest)
23
- end
24
-
25
- desc "Clears sessions"
26
- task :clear => :merb_env do
27
- table_name = (Merb::Plugins.config[:sequel][:session_table_name] || "sessions")
28
-
29
- Merb::Orms::Sequel.connect.execute("DELETE FROM #{table_name}")
30
- end
31
-
32
- end
33
-
34
- end
@@ -1,2 +0,0 @@
1
- class <%= class_name %> < Sequel::Model(:<%= class_name.snake_case.pluralize %>)
2
- end
@@ -1,56 +0,0 @@
1
- <% klass = class_name.singularize -%>
2
- <% ivar = class_name.snake_case.singularize -%>
3
- class <%= class_name %> < Application
4
-
5
- provides :xml, :js, :yaml
6
-
7
- def index
8
- @<%= ivar.pluralize %> = <%= klass %>.all
9
- render @<%= ivar.pluralize %>
10
- end
11
-
12
- def show
13
- @<%= ivar %> = <%= klass %>[params[:id]]
14
- render @<%= ivar %>
15
- end
16
-
17
- def new
18
- only_provides :html
19
- @<%= ivar %> = <%= klass %>.new(params[:<%= ivar %>])
20
- render
21
- end
22
-
23
- def create
24
- @<%= ivar %> = <%= klass %>.new(params[:<%= ivar %>])
25
- if @<%= ivar %>.save
26
- redirect url(:<%= ivar %>, @<%= ivar %>)
27
- else
28
- render :action => :new
29
- end
30
- end
31
-
32
- def edit
33
- only_provides :html
34
- @<%= ivar %> = <%= klass %>[params[:id]]
35
- render
36
- end
37
-
38
- def update
39
- @<%= ivar %> = <%= klass %>[params[:id]]
40
- if @<%= ivar %>.update(params[:<%= ivar %>])
41
- redirect url(:<%= ivar %>, @<%= ivar %>)
42
- else
43
- raise BadRequest
44
- end
45
- end
46
-
47
- def destroy
48
- @<%= ivar %> = <%= klass %>[params[:id]]
49
- if @<%= ivar %>.destroy
50
- redirect url(:<%= ivar %>s)
51
- else
52
- raise BadRequest
53
- end
54
- end
55
-
56
- end
@@ -1 +0,0 @@
1
- Edit for <%= class_name %>
@@ -1,5 +0,0 @@
1
- module Merb
2
- module <%= class_name %>Helper
3
-
4
- end
5
- end
@@ -1 +0,0 @@
1
- Index for <%= class_name %>
@@ -1 +0,0 @@
1
- New for <%= class_name %>
@@ -1 +0,0 @@
1
- Show for <%= class_name %>