pk-merb_sequel 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG ADDED
@@ -0,0 +1,10 @@
1
+ == 1.0.7
2
+
3
+ * Add support for ActiveModel via active_model plugin for Sequel > 3.5.0 or
4
+ Merb::Orms::Sequel::Model::ActiveModelCompatibility module. Added
5
+ :load_activemodel_compatibility configuration option to handle ActiveModel
6
+ compatibility loading. See README for
7
+ more information.
8
+ * Removed Merb::Orms::Sequel::ModelExtensions in favour to Merb::Orms::Sequel::Model::ActiveModelCompatibility
9
+ * Added spec.opts
10
+ * Fixing session storage
data/README.rdoc CHANGED
@@ -53,18 +53,25 @@ use_orm :sequel
53
53
 
54
54
  == Compatibility
55
55
 
56
- ===Ruby 1.8.7:
56
+ === Ruby 1.8.7:
57
57
  Sequel 2.11.0:: All pass
58
58
  Sequel 2.12.0:: All pass
59
59
  Sequel 3.0.0:: All pass
60
60
  Sequel 3.5.0:: All pass
61
61
 
62
- ===Ruby 1.9.1:
62
+ === Ruby 1.9.1:
63
63
  Sequel 2.11.0:: All pass except session spec failing due to Marshall issues.
64
64
  Sequel 2.12.0:: All pass except session spec failing due to Marshall issues.
65
65
  Sequel 3.0.0:: All pass except session spec failing due to Marshall issues.
66
66
  Sequel 3.5.0:: All pass except session spec failing due to Marshall issues.
67
67
 
68
+ === ActiveModel compatibility
69
+ In Merb > 1.0.13 we use ActiveModel interface for the ORM plugins. merb_sequel
70
+ now supports this for all versions of Sequel by including compatibilit layers
71
+ by default or loading active model plugin when using Sequel > 3.5.0
72
+
73
+ You can use configuration to not load compatibility layer:
74
+ Merb::Plugins.config[:merb_sequel][:load_activemodel_compatibility] = false
68
75
 
69
76
  == RSpec transactional examples
70
77
 
@@ -77,7 +84,11 @@ your spec_helper.rb or any spec you want to be transactional:
77
84
  Now <b>each example is wrapped in a Sequel transaction and when example finishes
78
85
  Sequel::Error::Rollback is raised which cause transaction to rollback</b>.
79
86
 
80
- == Connection options
87
+ == Connection options & Settings
88
+
89
+ Settings:
90
+
91
+ * :load_activemodel_compatibility. By default is set to true. If set to false, ActiveModelCompatibility is not loaded.
81
92
 
82
93
  Merb Sequel plug-in uses config/database.yml for connection configuration.
83
94
 
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ GEM_EMAIL = "wayneeseguin@gmail.com, lancecarlson@gmail.com, email@loriholden.c
17
17
 
18
18
  GEM_NAME = "pk-merb_sequel"
19
19
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
- GEM_VERSION = "1.0.6" + PKG_BUILD
20
+ GEM_VERSION = "1.0.7" + PKG_BUILD
21
21
 
22
22
  RELEASE_NAME = "REL #{GEM_VERSION}"
23
23
 
@@ -35,7 +35,7 @@ spec = Gem::Specification.new do |s|
35
35
  s.homepage = PROJECT_URL
36
36
  s.add_dependency("merb-core", ">= 0.9.9")
37
37
  s.add_dependency("sequel", ">= 1.4.0")
38
- s.files = %w(LICENSE README.rdoc Rakefile TODO Generators) + Dir.glob("{lib}/**/*")
38
+ s.files = %w(CHANGELOG LICENSE README.rdoc Rakefile TODO Generators) + Dir.glob("{lib}/**/*")
39
39
  end
40
40
 
41
41
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -27,7 +27,7 @@ module Merb
27
27
  @config ||= begin
28
28
  # Convert string keys to symbols
29
29
  full_config = Erubis.load_yaml_file(config_file)
30
- config = (Merb::Plugins.config[:merb_sequel] = {})
30
+ config = Merb::Plugins.config[:merb_sequel]
31
31
  (full_config[Merb.environment.to_sym] || full_config[Merb.environment] || full_config[:development]).each do |key, value|
32
32
  config[key.to_sym] = value
33
33
  end
@@ -0,0 +1,38 @@
1
+ module Merb
2
+ module Orms
3
+ module Sequel
4
+ module Model
5
+
6
+ # This code has been taken from Sequel 3.5.0
7
+ # Sequel::Plugins::ActiveModel
8
+ # http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/ActiveModel.html
9
+ module ActiveModelCompatibility
10
+ # Record that an object was destroyed, for later use by
11
+ # destroyed?
12
+ def after_destroy
13
+ super
14
+ @destroyed = true
15
+ end
16
+
17
+ # Whether the object was destroyed by destroy. Not true
18
+ # for objects that were deleted.
19
+ def destroyed?
20
+ @destroyed == true
21
+ end
22
+
23
+ # An alias for new?
24
+ def new_record?
25
+ new?
26
+ end
27
+
28
+ # With the ActiveModel plugin, Sequel model objects are already
29
+ # compliant, so this returns self.
30
+ def to_model
31
+ self
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,11 +1,10 @@
1
1
  require 'sequel'
2
2
  require 'sequel/extensions/migration' if Merb::Orms::Sequel.new_sequel?
3
3
  require 'merb-core/dispatch/session'
4
- require 'base64'
5
4
 
6
5
  module Merb
7
6
 
8
- Merb::Plugins.config[:merb_sequel][:session_table_name] ||= "sessions"
7
+ Merb::Plugins.config[:merb_sequel][:session_table_name] ||= 'sessions'
9
8
 
10
9
  # Default session migration run if a sessions table does not yet exist.
11
10
  #
@@ -49,23 +48,26 @@ module Merb
49
48
  # ContainerSession:: The session corresponding to the ID.
50
49
  def retrieve_session(session_id)
51
50
  if item = find(:session_id => session_id)
52
- item.data
51
+ Marshal.load(item.data.unpack('m').first)
53
52
  end
54
53
  end
55
54
 
56
55
  # ==== Parameters
57
56
  # session_id<String>:: ID of the session to set.
58
57
  # data<ContainerSession>:: The session to set.
59
- def store_session(session_id, data)
58
+ def store_session(session_id, session_data)
59
+ session_data = session_data.empty? ? nil : [Marshal.dump(session_data)].pack('m')
60
60
  begin
61
- if item = find(:session_id => session_id)
62
- item.update(:data => data)
61
+ if item = self.find(:session_id => session_id)
62
+ item.update(:data => session_data)
63
63
  else
64
- item = self.new(:session_id => session_id, :data => data, :created_at => Time.now)
64
+ item = self.new(:session_id => session_id,
65
+ :data => session_data,
66
+ :created_at => Time.now)
65
67
  item.save
66
68
  end
67
69
  rescue => e
68
- Merb.logger.error("#{e.message} when trying to save #{data}")
70
+ Merb.logger.error("#{e.message} when trying to save #{session_data}")
69
71
  end
70
72
  end
71
73
 
@@ -76,63 +78,20 @@ module Merb
76
78
  item.delete
77
79
  end
78
80
  end
79
-
80
- # ==== Returns
81
- # Integer:: The maximum length of the 'data' column.
82
- def data_column_size_limit
83
- 512 # TODO - figure out how much space we actually have
84
- end
85
81
 
86
82
  unless Merb::Orms::Sequel.new_sequel?
87
83
  alias :create_table! :create_table
88
84
  alias :drop_table! :drop_table
89
85
  end
90
86
  end
91
-
92
- # Lazy-unserialize session state.
93
- def data
94
- data = (@values[:data] ? Marshal.load(@values[:data]) : {}) if @data.nil?
95
- @data
96
- end
97
-
98
- # Virtual attribute writer - override.
99
- def data=(hsh)
100
- super(hsh) if hsh.is_a?(Hash)
101
- end
102
-
103
- # Has the session been loaded yet?
104
- def loaded?
105
- !!@data
106
- end
107
-
108
- if Merb::Orms::Sequel.new_sequel?
109
- def before_save
110
- super
111
- prepare_data_to_save
112
- end
113
- else
114
- before_save :prepare_data_to_save
115
- end
116
-
117
- private
118
-
119
- def prepare_data_to_save
120
- @values[:data] = Marshal.dump(self.data)
121
- if @values[:data].size > self.class.data_column_size_limit
122
- raise Merb::SessionMixin::SessionOverflow
123
- end
124
- end
125
-
126
87
  end
127
88
 
128
89
  class SequelSession < SessionStoreContainer
129
-
130
90
  # The session store type
131
91
  self.session_store_type = :sequel
132
92
 
133
93
  # The store object is the model class itself
134
94
  self.store = SequelSessionStore
135
-
136
95
  end
137
96
 
138
97
  end
data/lib/merb_sequel.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  if defined?(Merb::Plugins)
2
- Merb::Plugins.config[:merb_sequel] = {}
3
- require File.join(File.dirname(__FILE__) / "sequel_ext" / "model")
2
+
3
+ # Default settings
4
+ Merb::Plugins.config[:merb_sequel] = { :load_activemodel_compatibility => true }
5
+
6
+ require File.join(File.dirname(__FILE__) / "merb" / "orms" / "sequel" / "model")
4
7
  require File.join(File.dirname(__FILE__) / "merb" / "orms" / "sequel" / "connection")
5
8
  Merb::Plugins.add_rakefiles "merb_sequel" / "merbtasks"
6
9
 
7
- Sequel::Model.send(:include, Merb::Orms::Sequel::ModelExtensions)
8
-
9
10
  # Connects to the database and handles session
10
11
  #
11
12
  # Connects to the database and loads sequel sessions if we use them.
@@ -20,7 +21,29 @@ if defined?(Merb::Plugins)
20
21
  require File.join(File.dirname(__FILE__) / "merb" / "session" / "sequel_session")
21
22
  end
22
23
 
24
+ # Set identifiy to use Sequel primary key field
23
25
  Merb::Router.root_behavior = Merb::Router.root_behavior.identify(Sequel::Model => :pk)
26
+
27
+ # Load compatibility extensions
28
+ if Merb::Plugins.config[:merb_sequel][:load_activemodel_compatibility]
29
+ load_activemodel_compatibility
30
+ end
31
+ end
32
+
33
+ # Load active model plugin if available
34
+ #
35
+ # Merb > 1.0.13 expects models to be ActiveModel compatible
36
+ # Sequel 3.5.0 added plugin to make Sequel models AtciveModel
37
+ # compatible.
38
+ #
39
+ # We're loading plugin to all models here if plugin is available
40
+ # if the plugin is not available we must include compatibility module.
41
+ def self.load_activemodel_compatibility
42
+ begin
43
+ Sequel::Model.plugin :active_model
44
+ rescue LoadError, NoMethodError
45
+ Sequel::Model.send(:include, Merb::Orms::Sequel::Model::ActiveModelCompatibility)
46
+ end
24
47
  end
25
48
 
26
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pk-merb_sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne E. Seguin, Lance Carlson, Lori Holden, Pavel Kunc
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-04 00:00:00 +01:00
12
+ date: 2009-10-17 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -43,6 +43,7 @@ extra_rdoc_files:
43
43
  - LICENSE
44
44
  - TODO
45
45
  files:
46
+ - CHANGELOG
46
47
  - LICENSE
47
48
  - README.rdoc
48
49
  - Rakefile
@@ -62,11 +63,11 @@ files:
62
63
  - lib/generators/templates/session_migration/schema/migrations/%version%_sessions.rb
63
64
  - lib/merb/orms/sequel/connection.rb
64
65
  - lib/merb/orms/sequel/database.yml.sample
66
+ - lib/merb/orms/sequel/model.rb
65
67
  - lib/merb/session/sequel_session.rb
66
68
  - lib/merb_sequel/merbtasks.rb
67
69
  - lib/merb_sequel/rspec/sequel.rb
68
70
  - lib/merb_sequel.rb
69
- - lib/sequel_ext/model.rb
70
71
  has_rdoc: true
71
72
  homepage: http://github.com/pk/merb_sequel
72
73
  licenses: []
@@ -1,11 +0,0 @@
1
- module Merb
2
- module Orms
3
- module Sequel
4
- module ModelExtensions
5
- def new_record?
6
- self.new?
7
- end
8
- end
9
- end
10
- end
11
- end