merb_datamapper 0.4.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,8 +1,10 @@
1
- merb_data_mapper
1
+ merb_datamapper
2
2
  =================
3
3
 
4
4
  A plugin for the Merb framework that provides DataMapper access
5
5
 
6
6
  To use sessions:
7
- set the session store to data_mapper in merb.yml
8
- add the dependency in dependencies.rb: dependency "merb_data_mapper"
7
+ 1. set the session store to datamapper in merb.yml:
8
+ :session_store: datamapper
9
+ 2. add the dependency in dependencies.rb:
10
+ use_orm :datamapper
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
 
4
4
  PLUGIN = "merb_datamapper"
5
5
  NAME = "merb_datamapper"
6
- VERSION = "0.4.4"
6
+ VERSION = "0.5"
7
7
  AUTHOR = "Jason Toy"
8
8
  EMAIL = "jtoy@rubynow.com"
9
9
  HOMEPAGE = "http://merbivore.com"
@@ -20,7 +20,7 @@ spec = Gem::Specification.new do |s|
20
20
  s.author = AUTHOR
21
21
  s.email = EMAIL
22
22
  s.homepage = HOMEPAGE
23
- s.add_dependency('merb', '>= 0.4.0')
23
+ s.add_dependency('merb', '>= 0.5')
24
24
  s.add_dependency('datamapper', '>= 0.2.3')
25
25
  s.require_path = 'lib'
26
26
  s.autorequire = PLUGIN
@@ -35,3 +35,7 @@ task :install do
35
35
  sh %{rake package}
36
36
  sh %{sudo gem install pkg/#{NAME}-#{VERSION}}
37
37
  end
38
+
39
+ task :release => :package do
40
+ sh %{rubyforge add_release merb #{PLUGIN} #{VERSION} pkg/#{NAME}-#{VERSION}.gem}
41
+ end
@@ -5,8 +5,8 @@ module Merb
5
5
  module Orms
6
6
  module DataMapper
7
7
  class << self
8
- def config_file() MERB_ROOT / "config" / "database.yml" end
9
- def sample_dest() MERB_ROOT / "config" / "database.sample.yml" end
8
+ def config_file() Merb.root / "config" / "database.yml" end
9
+ def sample_dest() Merb.root / "config" / "database.sample.yml" end
10
10
  def sample_source() File.dirname(__FILE__) / "database.sample.yml" end
11
11
 
12
12
  def copy_sample_config
@@ -18,8 +18,8 @@ module Merb
18
18
  begin
19
19
  # Convert string keys to symbols
20
20
  full_config = Erubis.load_yaml_file(config_file)
21
- config = (Merb::Plugins.config[:merb_data_mapper] = {})
22
- (full_config[MERB_ENV.to_sym] || full_config[MERB_ENV]).each { |k, v| config[k.to_sym] = v }
21
+ config = (Merb::Plugins.config[:merb_datamapper] = {})
22
+ (full_config[Merb.environment.to_sym] || full_config[Merb.environment]).each { |k, v| config[k.to_sym] = v }
23
23
  config
24
24
  end
25
25
  end
@@ -31,7 +31,7 @@ module Merb
31
31
  ::DataMapper::Database.setup(config)
32
32
  else
33
33
  copy_sample_config
34
- puts "No database.yml file found in #{MERB_ROOT}/config."
34
+ puts "No database.yml file found in #{Merb.root}/config."
35
35
  puts "A sample file was created called database.sample.yml for you to copy and edit."
36
36
  exit(1)
37
37
  end
@@ -40,7 +40,7 @@ module Merb
40
40
  # Registering this ORM lets the user choose DataMapper as a session store
41
41
  # in merb.yml's session_store: option.
42
42
  def register_session_type
43
- Merb::Server.register_session_type("data_mapper",
43
+ Merb::BootLoader.register_session_type("datamapper",
44
44
  "merb/session/data_mapper_session",
45
45
  "Using DataMapper database sessions")
46
46
  end
@@ -4,21 +4,21 @@ namespace :dm do
4
4
  namespace :db do
5
5
  desc "Perform automigration"
6
6
  task :automigrate => :merb_env do
7
- DataMapper::Base.auto_migrate!
7
+ DataMapper::Persistence.auto_migrate!
8
8
  end
9
9
  end
10
10
 
11
11
  namespace :sessions do
12
12
  desc "Creates session migration"
13
13
  task :create => :merb_env do
14
- dest = File.join(MERB_ROOT, "schema", "migrations","001_add_sessions_table.rb")
14
+ dest = File.join(Merb.root, "schema", "migrations","001_add_sessions_table.rb")
15
15
  source = File.join(File.dirname(__FILE__), "merb", "session","001_add_sessions_table.rb")
16
16
  #FileUtils.cp source, dest unless File.exists?(dest)
17
17
  end
18
18
 
19
19
  desc "Clears sessions"
20
20
  task :clear => :merb_env do
21
- table_name = (Merb::Plugins.config[:data_mapper][:session_table_name] || "sessions")
21
+ table_name = (Merb::Plugins.config[:datamapper][:session_table_name] || "sessions")
22
22
  #Merb::Orms::DataMapper.connect.execute("DELETE FROM #{table_name}")
23
23
  end
24
24
  end
@@ -3,7 +3,7 @@ require 'base64'
3
3
  module Merb
4
4
  module SessionMixin
5
5
  def setup_session
6
- MERB_LOGGER.info("Setting up session")
6
+ Merb.logger.info("Setting up session")
7
7
  before = cookies[_session_id_key]
8
8
  request.session, cookies[_session_id_key] = Merb::DataMapperSession.persist(cookies[_session_id_key])
9
9
  @_fingerprint = Marshal.dump(request.session.data).hash
@@ -11,19 +11,19 @@ module Merb
11
11
  end
12
12
 
13
13
  def finalize_session
14
- MERB_LOGGER.info("Finalize session")
14
+ Merb.logger.info("Finalize session")
15
15
  request.session.save if @_fingerprint != Marshal.dump(request.session.data).hash
16
16
  set_cookie(_session_id_key, request.session.session_id, _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
17
17
  end
18
18
  end
19
19
 
20
- table_name = (Merb::Plugins.config[:merb_data_mapper][:session_table_name] || "sessions")
20
+ table_name = (Merb::Plugins.config[:merb_datamapper][:session_table_name] || "sessions")
21
21
 
22
22
  class DataMapperSession < DataMapper::Base
23
23
 
24
24
  set_table_name "sessions"
25
- property :session_id, :text
26
- property :data, :text
25
+ property :session_id, :text, :lazy => false, :key => true
26
+ property :data, :text, :lazy => false
27
27
 
28
28
  attr_accessor :needs_new_cookie
29
29
 
@@ -37,7 +37,7 @@ module Merb
37
37
  # If none is found, generates a new session.
38
38
  def persist(session_id)
39
39
  if session_id
40
- session = self[:session_id => session_id]
40
+ session = self[session_id]
41
41
  end
42
42
  unless session
43
43
  session = generate
@@ -63,10 +63,18 @@ module Merb
63
63
  end
64
64
 
65
65
  # Lazy-delete of session data
66
- def delete
67
- data = {}
66
+ def delete(key = nil)
67
+ key ? self.data.delete(key) : self.data.clear
68
+ end
69
+
70
+ def empty?
71
+ data.empty?
68
72
  end
69
73
 
74
+ def each(&b)
75
+ data.each(&b)
76
+ end
77
+
70
78
  def [](key)
71
79
  data[key]
72
80
  end
@@ -78,7 +86,10 @@ module Merb
78
86
  def data
79
87
  @unmarshalled_data || @unmarshalled_data = self.class.unmarshal(@data)
80
88
  end
81
-
89
+
90
+ def data=(data)
91
+ @data, @unmarshalled_data = data, data
92
+ end
82
93
 
83
94
  private
84
95
 
@@ -1,7 +1,7 @@
1
1
  # make sure we're running inside Merb
2
2
  if defined?(Merb::Plugins)
3
- if Merb::Server.app_loaded?
4
- puts "Warning: The merb_data_mapper gem must be loaded before the application"
3
+ if Merb::BootLoader.app_loaded?
4
+ puts "Warning: The merb_datamapper gem must be loaded before the application"
5
5
  else
6
6
  require "merb/orms/data_mapper/connection"
7
7
  Merb::Orms::DataMapper.connect
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: merb_datamapper
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.4
7
- date: 2007-11-12 00:00:00 -06:00
6
+ version: "0.5"
7
+ date: 2008-01-09 00:00:00 -08:00
8
8
  summary: Merb plugin that provides DataMapper support for Merb
9
9
  require_paths:
10
10
  - lib
@@ -88,7 +88,7 @@ dependencies:
88
88
  requirements:
89
89
  - - ">="
90
90
  - !ruby/object:Gem::Version
91
- version: 0.4.0
91
+ version: "0.5"
92
92
  version:
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: datamapper