tpitale-rails_datamapper 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +81 -0
- data/LICENSE +20 -0
- data/README.rdoc +40 -0
- data/Rakefile +30 -0
- data/VERSION +1 -0
- data/datamapper.rake +80 -0
- data/generators/dm_install/dm_install_generator.rb +12 -0
- data/generators/dm_install/templates/datamapper.rake +42 -0
- data/generators/dm_migration/dm_migration_generator.rb +11 -0
- data/generators/dm_migration/templates/migration.rb +17 -0
- data/generators/dm_model/dm_model_generator.rb +28 -0
- data/generators/dm_model/templates/model.rb +13 -0
- data/generators/dm_model/templates/unit_test.rb +8 -0
- data/generators/rspec_dm_model/rspec_dm_model_generator.rb +28 -0
- data/generators/rspec_dm_model/templates/model_spec.rb +9 -0
- data/lib/rails_datamapper.rb +61 -0
- data/lib/rails_datamapper/session_store.rb +63 -0
- data/rails_datamapper.gemspec +70 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +135 -0
data/Gemfile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
group :runtime do
|
4
|
+
|
5
|
+
# We bundle both AS and extlib while extlib compatibility needs to be kept around.
|
6
|
+
# require 'dm-core' will ensure that only one is activated at any time though.
|
7
|
+
# This is done by trying to require AS components and fallback to requiring
|
8
|
+
# extlib in case a LoadError was rescued when requiring AS code.
|
9
|
+
#
|
10
|
+
# Due to bundle exec activating all groups in the Gemfile, it's recommended to run
|
11
|
+
#
|
12
|
+
# bundle install --without quality
|
13
|
+
#
|
14
|
+
# to have a development environment that is able to run the specs. The problem is that
|
15
|
+
# metric_fu activates active_support=2.2.3 if we comment out the gem 'activesupport'
|
16
|
+
# declaration - have a look below for why we would want to do that (and a bit later, for
|
17
|
+
# why that's actually not *strictly* necessary, but recommended)
|
18
|
+
#
|
19
|
+
# To run the specs using AS, leave this Gemfile as it is and just run
|
20
|
+
#
|
21
|
+
# bundle install --without qality
|
22
|
+
# ADAPTERS=sqlite3 bundle exec rake spec # or whatever adapter
|
23
|
+
#
|
24
|
+
# To run the specs using extlib, comment out the: gem 'activesupport' line and run
|
25
|
+
#
|
26
|
+
# bundle install --without quality
|
27
|
+
# ADAPTERS=sqlite3 bundle exec rake spec # or whatever adapter
|
28
|
+
#
|
29
|
+
# If you want to run the quality tasks as provided by metric_fu and related gems,
|
30
|
+
# you have to run
|
31
|
+
#
|
32
|
+
# bundle install
|
33
|
+
# bundle exec rake metrics:all
|
34
|
+
#
|
35
|
+
# Switch back to a bundle without quality gems before trying to run the specs again
|
36
|
+
#
|
37
|
+
# bundle install --without quality
|
38
|
+
# ADAPTERS=sqlite3 bundle exec rake spec # or whatever adapter
|
39
|
+
#
|
40
|
+
# It was mentioned above that all this is not *strictly* necessary, and this is true.
|
41
|
+
# Currently dm-core does the following as the first require when checking for AS
|
42
|
+
#
|
43
|
+
# require 'active_support/core_ext/object/singleton_class'
|
44
|
+
#
|
45
|
+
# Because this method is not present in activesupport <= 3.0.0.beta, dm-core's feature
|
46
|
+
# detection will actually do the "right thing" and fall back to extlib. However, since
|
47
|
+
# this is not the case for all dm-more gems as well, the safest thing to do is to respect
|
48
|
+
# the more tedious workflow for now, as it will at least be guaranteed to work the same
|
49
|
+
# for both dm-core and dm-more.
|
50
|
+
#
|
51
|
+
# Note that this won't be an issue anymore once we dropped support for extlib completely,
|
52
|
+
# or bundler folks decide to support something like "bundle exec --without=foo rake spec"
|
53
|
+
# (which probably is not going to happen anytime soon).
|
54
|
+
#
|
55
|
+
|
56
|
+
if ENV['EXTLIB']
|
57
|
+
gem 'extlib', '~> 0.9.15', :git => 'git://github.com/datamapper/extlib.git'
|
58
|
+
end
|
59
|
+
|
60
|
+
gem 'rails', '>= 2.3.5'
|
61
|
+
gem 'dm-core', '~> 1.0.01'
|
62
|
+
end
|
63
|
+
|
64
|
+
group :development do
|
65
|
+
gem 'rake', '~> 0.8.7'
|
66
|
+
gem 'rspec', '~> 1.3'
|
67
|
+
gem 'yard', '~> 0.5'
|
68
|
+
gem 'rcov', '~> 0.9.7'
|
69
|
+
gem 'jeweler', '~> 1.4'
|
70
|
+
gem 'data_objects', '~> 0.10.1'
|
71
|
+
gem 'do_sqlite3', '~> 0.10.1'
|
72
|
+
gem 'do_mysql', '~> 0.10.1'
|
73
|
+
gem 'do_postgres', '~> 0.10.1'
|
74
|
+
end
|
75
|
+
|
76
|
+
group :quality do
|
77
|
+
gem 'yardstick', '~> 0.1'
|
78
|
+
gem 'metric_fu', '~> 1.3'
|
79
|
+
gem 'reek', '~> 1.2.7'
|
80
|
+
gem 'roodi', '~> 2.1'
|
81
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tom Malone
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
This is a Rails plugin that provides datamapper as an orm
|
2
|
+
|
3
|
+
== Setup
|
4
|
+
|
5
|
+
add the following line to your projects environment.rb
|
6
|
+
|
7
|
+
config.gem "rails_datamapper"
|
8
|
+
|
9
|
+
== Generators
|
10
|
+
|
11
|
+
This will install the datamapper rake tasks:
|
12
|
+
|
13
|
+
script/generate dm_install
|
14
|
+
|
15
|
+
Three generators are added by default
|
16
|
+
|
17
|
+
script/generate dm_model
|
18
|
+
script/generate rspec_dm_model
|
19
|
+
script/generate dm_migration
|
20
|
+
|
21
|
+
The first two add a migration but you can call
|
22
|
+
|
23
|
+
script/generate dm_model --skip-migration
|
24
|
+
script/generate rspec_dm_model --skip-migration
|
25
|
+
|
26
|
+
To avoid any dependency on active record add this to your projects environment.rb
|
27
|
+
|
28
|
+
config.frameworks -= [ :active_record ]
|
29
|
+
|
30
|
+
== Session Store
|
31
|
+
|
32
|
+
Change config/initializers/session_store.rb to something like the following:
|
33
|
+
|
34
|
+
ActionController::Base.session_store = :data_mapper_store
|
35
|
+
ActionController::Base.session = {
|
36
|
+
:expires_after => 7.days,
|
37
|
+
:key => '_session_id',
|
38
|
+
}
|
39
|
+
|
40
|
+
Then create the sessions table with: rake db:sessions:create
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
gem 'jeweler', '~> 1.4'
|
6
|
+
require 'jeweler'
|
7
|
+
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = 'tpitale-rails_datamapper'
|
10
|
+
gem.summary = 'Rails Plugin for DataMapper'
|
11
|
+
gem.description = gem.summary
|
12
|
+
gem.email = 'tomjmalone [a] gmail [d] com'
|
13
|
+
gem.homepage = 'http://github.com/datamapper/dm-more/tree/master/%s' % gem.name
|
14
|
+
gem.authors = [ 'Tom Malone' ]
|
15
|
+
|
16
|
+
gem.rubyforge_project = 'datamapper'
|
17
|
+
|
18
|
+
gem.add_dependency 'dm-core', '~> 1.0.0'
|
19
|
+
gem.add_dependency 'rails', '>= 2.3.5'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rspec', '~> 1.3'
|
22
|
+
gem.add_development_dependency 'yard', '~> 0.5'
|
23
|
+
end
|
24
|
+
|
25
|
+
Jeweler::GemcutterTasks.new
|
26
|
+
|
27
|
+
FileList['tasks/**/*.rake'].each { |task| import task }
|
28
|
+
rescue LoadError
|
29
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
30
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.10.3
|
data/datamapper.rake
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
|
2
|
+
# Monkey patch to allow overriding defined rake tasks (instead of
|
3
|
+
# adding to them, which is the default behaviour when specifying tasks
|
4
|
+
# >1 times).
|
5
|
+
|
6
|
+
Rake::TaskManager.class_eval do
|
7
|
+
def remove_task(task_name)
|
8
|
+
@tasks.delete(task_name.to_s)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove_task(task_name)
|
13
|
+
returning Rake.application do |app|
|
14
|
+
app.remove_task(app[task_name].name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Until AR/DM co-existence becomes practically possible, presume
|
19
|
+
# mutual exclusivity between the two. Thus we wipe all pre-existing
|
20
|
+
# db tasks which we assume to be ActiveRecord-based and thus won't
|
21
|
+
# work).
|
22
|
+
|
23
|
+
Rake.application.tasks.select do |t|
|
24
|
+
t.class == Rake::Task && t.name.starts_with?("db")
|
25
|
+
end.each { |t| remove_task(t.name) }
|
26
|
+
|
27
|
+
namespace :db do
|
28
|
+
|
29
|
+
desc 'Perform automigration'
|
30
|
+
task :automigrate => :environment do
|
31
|
+
FileList["app/models/**/*.rb"].each do |model|
|
32
|
+
load model
|
33
|
+
end
|
34
|
+
::DataMapper.auto_migrate!
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Perform non destructive automigration'
|
38
|
+
task :autoupgrade => :environment do
|
39
|
+
FileList["app/models/**/*.rb"].each do |model|
|
40
|
+
load model
|
41
|
+
end
|
42
|
+
::DataMapper.auto_upgrade!
|
43
|
+
end
|
44
|
+
|
45
|
+
namespace :migrate do
|
46
|
+
task :load => :environment do
|
47
|
+
gem 'dm-migrations', '0.10.3'
|
48
|
+
FileList['db/migrations/*.rb'].each do |migration|
|
49
|
+
load migration
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'Migrate up using migrations'
|
54
|
+
task :up, :version, :needs => :load do |t, args|
|
55
|
+
version = args[:version]
|
56
|
+
migrate_up!(version)
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Migrate down using migrations'
|
60
|
+
task :down, :version, :needs => :load do |t, args|
|
61
|
+
version = args[:version]
|
62
|
+
migrate_down!(version)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
desc 'Migrate the database to the latest version'
|
67
|
+
task :migrate => 'db:migrate:up'
|
68
|
+
|
69
|
+
namespace :sessions do
|
70
|
+
desc "Creates the sessions table for DataMapperStore"
|
71
|
+
task :create => :environment do
|
72
|
+
::DataMapperStore::Session.auto_migrate!
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "Clear the sessions table for DataMapperStore"
|
76
|
+
task :clear => :environment do
|
77
|
+
::DataMapperStore::Session.all.destroy!
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
namespace :db do
|
2
|
+
|
3
|
+
desc 'Perform automigration'
|
4
|
+
task :automigrate => :environment do
|
5
|
+
FileList['app/models/**/*.rb'].each do |model|
|
6
|
+
load model
|
7
|
+
end
|
8
|
+
::DataMapper.auto_migrate!
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Perform non destructive automigration'
|
12
|
+
task :autoupgrade => :environment do
|
13
|
+
FileList['app/models/**/*.rb'].each do |model|
|
14
|
+
load model
|
15
|
+
end
|
16
|
+
::DataMapper.auto_upgrade!
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace :migrate do
|
20
|
+
task :load => :environment do
|
21
|
+
gem 'dm-migrations', '0.10.3'
|
22
|
+
FileList['db/migrations/*.rb'].each do |migration|
|
23
|
+
load migration
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Migrate up using migrations'
|
28
|
+
task :up, :version, :needs => :load do |t, args|
|
29
|
+
version = args[:version]
|
30
|
+
migrate_up!(version)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Migrate down using migrations'
|
34
|
+
task :down, :version, :needs => :load do |t, args|
|
35
|
+
version = args[:version]
|
36
|
+
migrate_down!(version)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Migrate the database to the latest version'
|
41
|
+
task :migrate => 'db:migrate:up'
|
42
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails_generator/generators/components/migration/migration_generator'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
class DmMigrationGenerator < Rails::Generator::NamedBase
|
5
|
+
|
6
|
+
def manifest
|
7
|
+
record do |m|
|
8
|
+
m.migration_template 'migration.rb', 'db/migrate'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
migration 1, :<%= class_name.underscore %> do
|
2
|
+
up do
|
3
|
+
create_table :<%= table_name %> do
|
4
|
+
<% Array(attributes).each do |attribute| -%>
|
5
|
+
column :<%= attribute.name if attribute %>, <%= attribute.type.to_s.capitalize %>, :nullable? => false
|
6
|
+
<% end -%>
|
7
|
+
<% unless options[:skip_timestamps] -%>
|
8
|
+
column :created_at, DateTime, :nullable? => false
|
9
|
+
column :updated_at, DateTime, :nullable? => false
|
10
|
+
<% end -%>
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
down do
|
15
|
+
drop_table :<%= table_name %>
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails_generator/generators/components/model/model_generator'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
class DmModelGenerator < ModelGenerator
|
5
|
+
|
6
|
+
def manifest
|
7
|
+
record do |m|
|
8
|
+
|
9
|
+
# Check for class naming collisions.
|
10
|
+
m.class_collisions class_path, class_name, "#{class_name}Test"
|
11
|
+
|
12
|
+
# Model, test, and fixture directories.
|
13
|
+
m.directory File.join('app/models', class_path)
|
14
|
+
m.directory File.join('test/unit', class_path)
|
15
|
+
|
16
|
+
# Model class, unit test, and fixtures.
|
17
|
+
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
18
|
+
m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
|
19
|
+
|
20
|
+
unless options[:skip_migration]
|
21
|
+
m.migration_template 'dm_migration:migration.rb', 'db/migrate', :assigns => {
|
22
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
23
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= class_name %>
|
2
|
+
include DataMapper::Resource
|
3
|
+
|
4
|
+
property :id, Serial
|
5
|
+
<% Array(attributes).each do |attribute| -%>
|
6
|
+
property :<%= attribute.name %>, <%= attribute.type.to_s.capitalize %>, :required => true
|
7
|
+
<% end -%>
|
8
|
+
<% unless options[:skip_timestamps] -%>
|
9
|
+
property :created_at, DateTime, :required => true
|
10
|
+
property :updated_at, DateTime, :required => true
|
11
|
+
<% end -%>
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails_generator/generators/components/model/model_generator'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
class RspecDmModelGenerator <ModelGenerator
|
5
|
+
|
6
|
+
def manifest
|
7
|
+
record do |m|
|
8
|
+
|
9
|
+
# Check for class naming collisions.
|
10
|
+
m.class_collisions class_path, class_name
|
11
|
+
|
12
|
+
# Model, spec, and fixture directories.
|
13
|
+
m.directory File.join('app/models', class_path)
|
14
|
+
m.directory File.join('spec/models', class_path)
|
15
|
+
|
16
|
+
# Model class, spec and fixtures.
|
17
|
+
m.template 'dm_model:model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
18
|
+
m.template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
19
|
+
|
20
|
+
unless options[:skip_migration]
|
21
|
+
m.migration_template 'dm_migration:migration.rb', 'db/migrate', :assigns => {
|
22
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
23
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), <%= ([ "'..'" ] * class_nesting_depth).join(', ') %>, '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe <%= class_name %> do
|
4
|
+
before(:each) do
|
5
|
+
@<%= file_name %> = <%= class_name %>.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should be awesome'
|
9
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'extlib/pathname'
|
3
|
+
|
4
|
+
require 'rails_datamapper/session_store'
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
module DataMapper
|
8
|
+
class << self
|
9
|
+
extend ActiveSupport::Memoizable
|
10
|
+
|
11
|
+
def create_connection
|
12
|
+
# TODO: handle Rails and Merb style database.yml files
|
13
|
+
conf = config.dup
|
14
|
+
repositories = conf.delete(:repositories)
|
15
|
+
::DataMapper.setup(:default, conf) unless conf.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def config_file
|
21
|
+
File.new(File.expand_path('config/database.yml', Rails.root))
|
22
|
+
end
|
23
|
+
|
24
|
+
def full_config
|
25
|
+
YAML::load(ERB.new(config_file.read).result)
|
26
|
+
end
|
27
|
+
|
28
|
+
memoize :full_config
|
29
|
+
|
30
|
+
def config
|
31
|
+
if hash = full_config[Rails.env] || full_config[Rails.env.to_sym]
|
32
|
+
normalize_config(hash)
|
33
|
+
else
|
34
|
+
raise ArgumentError, "missing environment '#{Rails.env}' in config file #{config_file}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
memoize :config
|
39
|
+
|
40
|
+
def normalize_config(hash)
|
41
|
+
config = {}
|
42
|
+
|
43
|
+
hash.symbolize_keys.each do |key, value|
|
44
|
+
config[key] = if value.kind_of?(Hash)
|
45
|
+
normalize_config(value)
|
46
|
+
elsif key == :port
|
47
|
+
value.to_i
|
48
|
+
elsif key == :adapter && value == 'postgresql'
|
49
|
+
'postgres'
|
50
|
+
else
|
51
|
+
value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
config
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
Rails::DataMapper.create_connection
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
|
3
|
+
# Implements DataMapper-specific session store.
|
4
|
+
|
5
|
+
module ActionController
|
6
|
+
module Session
|
7
|
+
class DataMapperStore < AbstractStore
|
8
|
+
|
9
|
+
# Options passed in here are specified at:
|
10
|
+
# config/initializers/session_store.rb
|
11
|
+
|
12
|
+
def initialize(app, options = {})
|
13
|
+
options.symbolize_keys!
|
14
|
+
options[:expire_after] = options[:expires] || nil
|
15
|
+
|
16
|
+
super
|
17
|
+
|
18
|
+
unless (self.class.class_variable_defined? :@@session_class and @@session_class)
|
19
|
+
@@session_class = options.delete(:session_class) || ::DataMapperStore::Session
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def get_session(env, sid)
|
25
|
+
sid ||= generate_sid
|
26
|
+
session = @@session_class.first(:session_id => sid)
|
27
|
+
[sid, session.nil? ? {} : session.data]
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_session(env, sid, session_data)
|
31
|
+
session = @@session_class.first(:session_id => sid) ||
|
32
|
+
@@session_class.new(:session_id => sid)
|
33
|
+
session.data = session_data || {}
|
34
|
+
session.updated_at = Time.now if session.dirty?
|
35
|
+
|
36
|
+
session.save
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module DataMapperStore
|
43
|
+
class Session
|
44
|
+
include ::DataMapper::Resource
|
45
|
+
|
46
|
+
def self.name
|
47
|
+
"session"
|
48
|
+
end
|
49
|
+
|
50
|
+
property :id, Serial
|
51
|
+
property :session_id, String, :unique_index => true
|
52
|
+
property :data, Text, :required => true, :default => ::Base64.encode64(Marshal.dump({}))
|
53
|
+
property :updated_at, DateTime, :required => false, :index => true
|
54
|
+
|
55
|
+
def data=(data)
|
56
|
+
attribute_set(:data, ::Base64.encode64(Marshal.dump(data)))
|
57
|
+
end
|
58
|
+
|
59
|
+
def data
|
60
|
+
Marshal.load(::Base64.decode64(attribute_get(:data)))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rails_datamapper}
|
8
|
+
s.version = "0.10.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tom Malone"]
|
12
|
+
s.date = %q{2010-06-17}
|
13
|
+
s.description = %q{Rails Plugin for DataMapper}
|
14
|
+
s.email = %q{tomjmalone [a] gmail [d] com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"datamapper.rake",
|
26
|
+
"generators/dm_install/dm_install_generator.rb",
|
27
|
+
"generators/dm_install/templates/datamapper.rake",
|
28
|
+
"generators/dm_migration/dm_migration_generator.rb",
|
29
|
+
"generators/dm_migration/templates/migration.rb",
|
30
|
+
"generators/dm_model/dm_model_generator.rb",
|
31
|
+
"generators/dm_model/templates/model.rb",
|
32
|
+
"generators/dm_model/templates/unit_test.rb",
|
33
|
+
"generators/rspec_dm_model/rspec_dm_model_generator.rb",
|
34
|
+
"generators/rspec_dm_model/templates/model_spec.rb",
|
35
|
+
"lib/rails_datamapper.rb",
|
36
|
+
"lib/rails_datamapper/session_store.rb",
|
37
|
+
"rails_datamapper.gemspec",
|
38
|
+
"tasks/yard.rake",
|
39
|
+
"tasks/yardstick.rake"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/datamapper/dm-more/tree/master/rails_datamapper}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubyforge_project = %q{datamapper}
|
45
|
+
s.rubygems_version = %q{1.3.6}
|
46
|
+
s.summary = %q{Rails Plugin for DataMapper}
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.3"])
|
54
|
+
s.add_runtime_dependency(%q<rails>, ["~> 2.3.5"])
|
55
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3"])
|
56
|
+
s.add_development_dependency(%q<yard>, ["~> 0.5"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<dm-core>, ["~> 0.10.3"])
|
59
|
+
s.add_dependency(%q<rails>, ["~> 2.3.5"])
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
61
|
+
s.add_dependency(%q<yard>, ["~> 0.5"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<dm-core>, ["~> 0.10.3"])
|
65
|
+
s.add_dependency(%q<rails>, ["~> 2.3.5"])
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
67
|
+
s.add_dependency(%q<yard>, ["~> 0.5"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/tasks/yard.rake
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
begin
|
2
|
+
require 'pathname'
|
3
|
+
require 'yardstick/rake/measurement'
|
4
|
+
require 'yardstick/rake/verify'
|
5
|
+
|
6
|
+
# yardstick_measure task
|
7
|
+
Yardstick::Rake::Measurement.new
|
8
|
+
|
9
|
+
# verify_measurements task
|
10
|
+
Yardstick::Rake::Verify.new do |verify|
|
11
|
+
verify.threshold = 100
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
%w[ yardstick_measure verify_measurements ].each do |name|
|
15
|
+
task name.to_s do
|
16
|
+
abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tpitale-rails_datamapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 10
|
8
|
+
- 3
|
9
|
+
version: 0.10.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Tom Malone
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-18 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: dm-core
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 1.0.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rails
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 3
|
44
|
+
- 5
|
45
|
+
version: 2.3.5
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 3
|
58
|
+
version: "1.3"
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: yard
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
- 5
|
71
|
+
version: "0.5"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
74
|
+
description: Rails Plugin for DataMapper
|
75
|
+
email: tomjmalone [a] gmail [d] com
|
76
|
+
executables: []
|
77
|
+
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
extra_rdoc_files:
|
81
|
+
- LICENSE
|
82
|
+
- README.rdoc
|
83
|
+
files:
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE
|
86
|
+
- README.rdoc
|
87
|
+
- Rakefile
|
88
|
+
- VERSION
|
89
|
+
- datamapper.rake
|
90
|
+
- generators/dm_install/dm_install_generator.rb
|
91
|
+
- generators/dm_install/templates/datamapper.rake
|
92
|
+
- generators/dm_migration/dm_migration_generator.rb
|
93
|
+
- generators/dm_migration/templates/migration.rb
|
94
|
+
- generators/dm_model/dm_model_generator.rb
|
95
|
+
- generators/dm_model/templates/model.rb
|
96
|
+
- generators/dm_model/templates/unit_test.rb
|
97
|
+
- generators/rspec_dm_model/rspec_dm_model_generator.rb
|
98
|
+
- generators/rspec_dm_model/templates/model_spec.rb
|
99
|
+
- lib/rails_datamapper.rb
|
100
|
+
- lib/rails_datamapper/session_store.rb
|
101
|
+
- rails_datamapper.gemspec
|
102
|
+
- tasks/yard.rake
|
103
|
+
- tasks/yardstick.rake
|
104
|
+
has_rdoc: true
|
105
|
+
homepage: http://github.com/datamapper/dm-more/tree/master/tpitale-rails_datamapper
|
106
|
+
licenses: []
|
107
|
+
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options:
|
110
|
+
- --charset=UTF-8
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project: datamapper
|
130
|
+
rubygems_version: 1.3.6
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: Rails Plugin for DataMapper
|
134
|
+
test_files: []
|
135
|
+
|