pk-merb_sequel 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,17 +7,17 @@ require "spec/rake/spectask"
7
7
  ##############################################################################
8
8
  # Package && release
9
9
  ##############################################################################
10
- RUBY_FORGE_PROJECT = "merb"
11
- PROJECT_URL = "http://merbivore.com"
10
+ RUBY_FORGE_PROJECT = "merb_sequel"
11
+ PROJECT_URL = "http://github.com/pk/merb_sequel"
12
12
  PROJECT_SUMMARY = "Merb plugin that provides support for Sequel and Sequel::Model"
13
13
  PROJECT_DESCRIPTION = PROJECT_SUMMARY
14
14
 
15
- GEM_AUTHOR = "Wayne E. Seguin, Lance Carlson, Lori Holden"
16
- GEM_EMAIL = "wayneeseguin@gmail.com, lancecarlson@gmail.com, email@loriholden.com"
15
+ GEM_AUTHOR = "Wayne E. Seguin, Lance Carlson, Lori Holden, Pavel Kunc"
16
+ GEM_EMAIL = "wayneeseguin@gmail.com, lancecarlson@gmail.com, email@loriholden.com, pavel.kunc@gmail.com"
17
17
 
18
18
  GEM_NAME = "merb_sequel"
19
19
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
- GEM_VERSION = (Merb::MORE_VERSION rescue "1.0.4") + PKG_BUILD
20
+ GEM_VERSION = "1.0.5" + PKG_BUILD
21
21
 
22
22
  RELEASE_NAME = "REL #{GEM_VERSION}"
23
23
 
@@ -1,6 +1,6 @@
1
- # For details on Sequel migrations see
2
- # http://sequel.rubyforge.org/
3
- # http://sequel.rubyforge.org/rdoc/classes/Sequel/Database.html#M000607
1
+ # For details on Sequel migrations see:
2
+ # * http://sequel.rubyforge.org/
3
+ # * http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Migration.html
4
4
 
5
5
  class <%= class_name %> < Sequel::Migration
6
6
 
@@ -25,9 +25,10 @@ class <%= class_name %> < Application
25
25
  # POST /<%= resource_path %>
26
26
  def create
27
27
  @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
28
- if @<%= singular_model %>.save
28
+ begin
29
+ @<%= singular_model %>.save
29
30
  redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
30
- else
31
+ rescue Sequel::ValidationFailed
31
32
  render :new
32
33
  end
33
34
  end
@@ -44,10 +45,11 @@ class <%= class_name %> < Application
44
45
  def update
45
46
  @<%= singular_model %> = <%= model_class_name %>[params[:id]]
46
47
  raise NotFound unless @<%= singular_model %>
47
- if @<%= singular_model %>.update(params[:<%= singular_model %>])
48
+ begin
49
+ @<%= singular_model %>.update(params[:<%= singular_model %>])
48
50
  redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
49
- else
50
- raise BadRequest
51
+ rescue Sequel::ValidationFailed
52
+ render :edit
51
53
  end
52
54
  end
53
55
 
@@ -55,12 +57,13 @@ class <%= class_name %> < Application
55
57
  def destroy
56
58
  @<%= singular_model %> = <%= model_class_name %>[params[:id]]
57
59
  raise NotFound unless @<%= singular_model %>
58
- if @<%= singular_model %>.destroy
60
+ begin
61
+ @<%= singular_model %>.destroy
59
62
  redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>s)
60
- else
63
+ rescue Sequel::Error
61
64
  raise BadRequest
62
65
  end
63
66
  end
64
67
 
65
68
  end
66
- <% end -%>
69
+ <% end -%>
@@ -57,10 +57,15 @@ module Merb
57
57
  # session_id<String>:: ID of the session to set.
58
58
  # data<ContainerSession>:: The session to set.
59
59
  def store_session(session_id, data)
60
- if item = find(:session_id => session_id)
61
- item.update(:data => data)
62
- else
63
- create(:session_id => session_id, :data => data, :created_at => Time.now)
60
+ begin
61
+ if item = find(:session_id => session_id)
62
+ item.update(:data => data)
63
+ else
64
+ item = self.new(:session_id => session_id, :data => data, :created_at => Time.now)
65
+ item.save
66
+ end
67
+ rescue => e
68
+ Merb.logger.error("#{e.message} when trying to save #{data}")
64
69
  end
65
70
  end
66
71
 
@@ -86,12 +91,13 @@ module Merb
86
91
 
87
92
  # Lazy-unserialize session state.
88
93
  def data
89
- @data ||= (@values[:data] ? Marshal.load(@values[:data]) : {})
94
+ data = (@values[:data] ? Marshal.load(@values[:data]) : {}) if @data.nil?
95
+ @data
90
96
  end
91
97
 
92
98
  # Virtual attribute writer - override.
93
99
  def data=(hsh)
94
- @data = hsh if hsh.is_a?(Hash)
100
+ super(hsh) if hsh.is_a?(Hash)
95
101
  end
96
102
 
97
103
  # Has the session been loaded yet?
data/lib/merb_sequel.rb CHANGED
@@ -4,6 +4,8 @@ if defined?(Merb::Plugins)
4
4
  require File.join(File.dirname(__FILE__) / "merb" / "orms" / "sequel" / "connection")
5
5
  Merb::Plugins.add_rakefiles "merb_sequel" / "merbtasks"
6
6
 
7
+ Sequel::Model.send(:include, Merb::Orms::Sequel::ModelExtensions)
8
+
7
9
  # Connects to the database and handles session
8
10
  #
9
11
  # Connects to the database and loads sequel sessions if we use them.
@@ -1,7 +1,11 @@
1
- module Sequel
2
- class Model
3
- def new_record?
4
- self.new?
1
+ module Merb
2
+ module Orms
3
+ module Sequel
4
+ module ModelExtensions
5
+ def new_record?
6
+ self.new?
7
+ end
8
+ end
5
9
  end
6
10
  end
7
- end
11
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pk-merb_sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
- - Wayne E. Seguin, Lance Carlson, Lori Holden
7
+ - Wayne E. Seguin, Lance Carlson, Lori Holden, Pavel Kunc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-12 00:00:00 -07:00
12
+ date: 2009-08-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 1.4.0
34
34
  version:
35
35
  description: Merb plugin that provides support for Sequel and Sequel::Model
36
- email: wayneeseguin@gmail.com, lancecarlson@gmail.com, email@loriholden.com
36
+ email: wayneeseguin@gmail.com, lancecarlson@gmail.com, email@loriholden.com, pavel.kunc@gmail.com
37
37
  executables: []
38
38
 
39
39
  extensions: []
@@ -90,8 +90,9 @@ files:
90
90
  - lib/merb_sequel.rb
91
91
  - lib/sequel_ext
92
92
  - lib/sequel_ext/model.rb
93
- has_rdoc: false
94
- homepage: http://merbivore.com
93
+ has_rdoc: true
94
+ homepage: http://github.com/pk/merb_sequel
95
+ licenses:
95
96
  post_install_message:
96
97
  rdoc_options: []
97
98
 
@@ -111,10 +112,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version:
112
113
  requirements: []
113
114
 
114
- rubyforge_project: merb
115
- rubygems_version: 1.2.0
115
+ rubyforge_project: merb_sequel
116
+ rubygems_version: 1.3.5
116
117
  signing_key:
117
- specification_version: 3
118
+ specification_version: 2
118
119
  summary: Merb plugin that provides support for Sequel and Sequel::Model
119
120
  test_files: []
120
121