mack-data_mapper 0.8.0.101 → 0.8.1
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/lib/mack-data_mapper.rb +5 -1
- data/lib/mack-data_mapper/database.rb +8 -9
- data/lib/mack-data_mapper/database_migrations.rb +2 -2
- data/lib/mack-data_mapper/dm_patches/migrations.rb +37 -1
- data/lib/mack-data_mapper/dm_patches/uri.rb +9 -0
- data/lib/mack-data_mapper/paginator.rb +52 -0
- data/lib/mack-data_mapper/repo_runner_helper.rb +22 -0
- metadata +14 -15
- data/lib/mack-data_mapper/dm_patches/dm-timestamps.rb +0 -6
- data/lib/mack-data_mapper/dm_patches/model.rb +0 -48
- data/lib/mack-data_mapper/dm_patches/property_set.rb +0 -15
- data/lib/mack-data_mapper/dm_patches/validations.rb +0 -15
data/lib/mack-data_mapper.rb
CHANGED
@@ -3,6 +3,8 @@ require 'genosaurus'
|
|
3
3
|
|
4
4
|
configatron.mack.set_default(:disable_transactional_tests, false)
|
5
5
|
configatron.mack.data_mapper_session_store.set_default(:expiry_time, 4.hours)
|
6
|
+
configatron.mack.data_mapper.set_default(:repository_runner_context, :default)
|
7
|
+
configatron.mack.data_mapper.set_default(:use_repository_runner, false)
|
6
8
|
|
7
9
|
require 'mack-orm'
|
8
10
|
|
@@ -12,7 +14,7 @@ fl = File.join(File.dirname(__FILE__), "mack-data_mapper")
|
|
12
14
|
$: << File.expand_path(File.join(fl, "dm_patches"))
|
13
15
|
|
14
16
|
[:core, :aggregates, :migrations, :serializer, :timestamps, :validations, :observer, :types].each do |g|
|
15
|
-
gem "dm-#{g}", "0.9.
|
17
|
+
gem "dm-#{g}", "0.9.6"
|
16
18
|
require "dm-#{g}" unless g == :types
|
17
19
|
end
|
18
20
|
|
@@ -25,6 +27,8 @@ require File.join(fl, "generators")
|
|
25
27
|
require File.join(fl, "helpers", "orm_helpers")
|
26
28
|
require File.join(fl, "resource")
|
27
29
|
require File.join(fl, "test_extensions")
|
30
|
+
require File.join(fl, "repo_runner_helper")
|
31
|
+
require File.join(fl, "paginator")
|
28
32
|
|
29
33
|
|
30
34
|
[:helpers, :migration_generator, :model_generator, :scaffold_generator, :dm_patches, :sessions].each do |folder|
|
@@ -59,12 +59,12 @@ module Mack
|
|
59
59
|
structure += show.attributes["create table".to_sym]
|
60
60
|
structure += ";\n\n"
|
61
61
|
end
|
62
|
+
structure.gsub!('MyISAM', 'InnoDB')
|
62
63
|
File.open(output_file, "w") {|f| f.puts structure}
|
63
64
|
when /Postgres/
|
64
65
|
`pg_dump -i -U "#{uri.user}" -s -x -O -n #{ENV["SCHEMA"] ||= "public"} -f #{output_file} #{uri.basename}`
|
65
66
|
when /Sqlite3/
|
66
|
-
|
67
|
-
`sqlite3 #{File.join(db_dir, uri.basename)} .schema > #{output_file}`
|
67
|
+
puts `sqlite3 #{uri.path} .schema > #{output_file}`
|
68
68
|
else
|
69
69
|
raise "Task not supported for '#{repository(repis).adapter.class.name}'"
|
70
70
|
end
|
@@ -97,10 +97,9 @@ module Mack
|
|
97
97
|
repo.adapter.execute "CREATE DATABASE #{uri.basename} ENCODING = 'utf8'"
|
98
98
|
end
|
99
99
|
when /Sqlite3/
|
100
|
-
|
101
|
-
|
102
|
-
FileUtils.
|
103
|
-
FileUtils.touch(File.join(db_dir, uri.basename))
|
100
|
+
puts "Creating (SQLite3): #{uri.path}"
|
101
|
+
FileUtils.mkdir_p(File.dirname(uri.path), :verbose => true)
|
102
|
+
FileUtils.touch(uri.path, :verbose => true)
|
104
103
|
else
|
105
104
|
raise "Task not supported for '#{repository(repis).adapter.class.name}'"
|
106
105
|
end
|
@@ -117,14 +116,14 @@ module Mack
|
|
117
116
|
end
|
118
117
|
when /Postgres/
|
119
118
|
setup_temp(uri, "postgres")
|
119
|
+
DataObjects::Postgres::Connection.__pools.each {|k, v| v.dispose}
|
120
120
|
repository(:tmp) do |repo|
|
121
121
|
puts "Dropping (PostgreSQL): #{uri.basename}"
|
122
122
|
repo.adapter.execute "DROP DATABASE IF EXISTS #{uri.basename}"
|
123
123
|
end
|
124
124
|
when /Sqlite3/
|
125
|
-
puts "Dropping (SQLite3): #{uri.
|
126
|
-
|
127
|
-
FileUtils.rm_rf(File.join(db_dir.to_s, uri.basename))
|
125
|
+
puts "Dropping (SQLite3): #{uri.path}"
|
126
|
+
FileUtils.rm_rf(uri.path)
|
128
127
|
else
|
129
128
|
raise "Task not supported for '#{repository(repis).adapter.class.name}'"
|
130
129
|
end
|
@@ -6,7 +6,7 @@ module Mack
|
|
6
6
|
|
7
7
|
# Migrates the database to the latest version
|
8
8
|
def self.migrate
|
9
|
-
Mack::Database.establish_connection
|
9
|
+
# Mack::Database.establish_connection
|
10
10
|
::DataMapper::MigrationRunner.reset!
|
11
11
|
migration_files.each { |mig| load mig }
|
12
12
|
::DataMapper::MigrationRunner.migrate_up!
|
@@ -29,7 +29,7 @@ module Mack
|
|
29
29
|
end
|
30
30
|
::DataMapper::MigrationRunner.migrations.clear
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
end # Migrations
|
34
34
|
end # Database
|
35
35
|
end # Mack
|
@@ -40,4 +40,40 @@ module SQL # :nodoc:
|
|
40
40
|
end
|
41
41
|
|
42
42
|
end # TableModifier
|
43
|
-
end # SQL
|
43
|
+
end # SQL
|
44
|
+
|
45
|
+
module DataMapper # :nodoc:
|
46
|
+
|
47
|
+
class Migration # :nodoc:
|
48
|
+
include SQL
|
49
|
+
|
50
|
+
# perform the migration by running the code in the #up block
|
51
|
+
def perform_up
|
52
|
+
result = nil
|
53
|
+
if needs_up?
|
54
|
+
# database.transaction.commit do
|
55
|
+
say_with_time "== Performing Up Migration ##{position}: #{name}", 0 do
|
56
|
+
result = @up_action.call
|
57
|
+
end
|
58
|
+
update_migration_info(:up)
|
59
|
+
# end
|
60
|
+
end
|
61
|
+
result
|
62
|
+
end
|
63
|
+
|
64
|
+
# un-do the migration by running the code in the #down block
|
65
|
+
def perform_down
|
66
|
+
result = nil
|
67
|
+
if needs_down?
|
68
|
+
# database.transaction.commit do
|
69
|
+
say_with_time "== Performing Down Migration ##{position}: #{name}", 0 do
|
70
|
+
result = @down_action.call
|
71
|
+
end
|
72
|
+
update_migration_info(:down)
|
73
|
+
# end
|
74
|
+
end
|
75
|
+
result
|
76
|
+
end
|
77
|
+
|
78
|
+
end # Migration
|
79
|
+
end # DataMapper
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Mack
|
2
|
+
module Database
|
3
|
+
|
4
|
+
class Paginator
|
5
|
+
|
6
|
+
# Implements the paginate method from the Mack::Database::Paginator spec in mack-orm.
|
7
|
+
def paginate
|
8
|
+
order_clause = [self.query_options.delete(:order)].flatten.compact
|
9
|
+
|
10
|
+
self.total_results = self.klass.count(self.query_options)
|
11
|
+
self.total_pages = (self.total_results.to_f / self.results_per_page).ceil
|
12
|
+
|
13
|
+
self.current_page = self.total_pages if self.current_page > self.total_pages
|
14
|
+
|
15
|
+
if order_clause.empty?
|
16
|
+
self.klass.key.each do |k|
|
17
|
+
order_clause << k.name.to_sym.asc
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
self.query_options.reverse_merge!({
|
22
|
+
:order => order_clause
|
23
|
+
})
|
24
|
+
|
25
|
+
offset = (self.current_page - 1) * self.results_per_page
|
26
|
+
offset = 0 if offset < 0
|
27
|
+
|
28
|
+
self.query_options.merge!({
|
29
|
+
:limit => self.results_per_page,
|
30
|
+
:offset => offset
|
31
|
+
})
|
32
|
+
|
33
|
+
self.results = self.klass.all(self.query_options)
|
34
|
+
self
|
35
|
+
end # paginate
|
36
|
+
|
37
|
+
end # Paginator
|
38
|
+
end # Database
|
39
|
+
end # Mack
|
40
|
+
|
41
|
+
module DataMapper # :nodoc:
|
42
|
+
module Resource # :nodoc:
|
43
|
+
module ClassMethods # :nodoc:
|
44
|
+
|
45
|
+
def paginate(options = {}, query_options = {})
|
46
|
+
paginator = Mack::Database::Paginator.new(self, options, query_options)
|
47
|
+
paginator.paginate
|
48
|
+
end
|
49
|
+
|
50
|
+
end # ClassMethods
|
51
|
+
end # Resource
|
52
|
+
end # DataMapper
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mack
|
2
|
+
module DataMapper # :nodoc:
|
3
|
+
# This runner helper will wrap a request with a DataMapper::Repository.
|
4
|
+
# To turn on this runner set the following configuration value equal to true:
|
5
|
+
# configatron.mack.data_mapper.use_repository_runner = true
|
6
|
+
# To set the context in which the runner helper runs, set this configuration value:
|
7
|
+
# configatron.mack.data_mapper.repository_runner_context = :default
|
8
|
+
class RepositoryRunnerHelper < Mack::RunnerHelpers::Base
|
9
|
+
|
10
|
+
def start(request, response, cookies)
|
11
|
+
::DataMapper::Repository.context << ::DataMapper::Repository.new(configatron.mack.data_mapper.repository_runner_context)
|
12
|
+
end
|
13
|
+
|
14
|
+
def complete(request, response, cookies)
|
15
|
+
::DataMapper::Repository.context.pop
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Mack::RunnerHelpers::Registry.add(Mack::DataMapper::RepositoryRunnerHelper) if configatron.mack.data_mapper.use_repository_runner
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mack-data_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-26 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.6
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: dm-aggregates
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.
|
33
|
+
version: 0.9.6
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: dm-migrations
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - "="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.9.
|
43
|
+
version: 0.9.6
|
44
44
|
version:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: dm-serializer
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.9.
|
53
|
+
version: 0.9.6
|
54
54
|
version:
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: dm-timestamps
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - "="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 0.9.
|
63
|
+
version: 0.9.6
|
64
64
|
version:
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
66
|
name: dm-validations
|
@@ -70,7 +70,7 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - "="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: 0.9.
|
73
|
+
version: 0.9.6
|
74
74
|
version:
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: dm-observer
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
requirements:
|
81
81
|
- - "="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: 0.9.
|
83
|
+
version: 0.9.6
|
84
84
|
version:
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: dm-types
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - "="
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0.9.
|
93
|
+
version: 0.9.6
|
94
94
|
version:
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: mack-orm
|
@@ -100,7 +100,7 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.8.
|
103
|
+
version: 0.8.1
|
104
104
|
version:
|
105
105
|
description: "mack-data_mapper was developed by: markbates"
|
106
106
|
email: mark@mackframework.com
|
@@ -113,11 +113,8 @@ extra_rdoc_files:
|
|
113
113
|
files:
|
114
114
|
- lib/mack-data_mapper/database.rb
|
115
115
|
- lib/mack-data_mapper/database_migrations.rb
|
116
|
-
- lib/mack-data_mapper/dm_patches/dm-timestamps.rb
|
117
116
|
- lib/mack-data_mapper/dm_patches/migrations.rb
|
118
|
-
- lib/mack-data_mapper/dm_patches/
|
119
|
-
- lib/mack-data_mapper/dm_patches/property_set.rb
|
120
|
-
- lib/mack-data_mapper/dm_patches/validations.rb
|
117
|
+
- lib/mack-data_mapper/dm_patches/uri.rb
|
121
118
|
- lib/mack-data_mapper/generators.rb
|
122
119
|
- lib/mack-data_mapper/helpers/orm_helpers.rb
|
123
120
|
- lib/mack-data_mapper/migration_generator/migration_generator.rb
|
@@ -127,6 +124,8 @@ files:
|
|
127
124
|
- lib/mack-data_mapper/model_generator/templates/model.rb.template
|
128
125
|
- lib/mack-data_mapper/model_generator/templates/rspec.rb.template
|
129
126
|
- lib/mack-data_mapper/model_generator/templates/test_case.rb.template
|
127
|
+
- lib/mack-data_mapper/paginator.rb
|
128
|
+
- lib/mack-data_mapper/repo_runner_helper.rb
|
130
129
|
- lib/mack-data_mapper/resource.rb
|
131
130
|
- lib/mack-data_mapper/scaffold_generator/templates/app/controllers/controller.rb.template
|
132
131
|
- lib/mack-data_mapper/sessions/data_mapper_session_store.rb
|
@@ -1,6 +0,0 @@
|
|
1
|
-
# module DataMapper # :nodoc:
|
2
|
-
# module Timestamp # :nodoc:
|
3
|
-
# TIMESTAMP_PROPERTIES[:created_at] = lambda { |r| r.created_at = DateTime.now if r.new_record? && r.created_at.nil? } # :nodoc:
|
4
|
-
# TIMESTAMP_PROPERTIES[:created_on] = lambda { |r| r.created_on = DateTime.now if r.new_record? && r.created_on.nil? } # :nodoc:
|
5
|
-
# end
|
6
|
-
# end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# module DataMapper # :nodoc:
|
2
|
-
# module Model # :nodoc:
|
3
|
-
#
|
4
|
-
# def property(name, type, options = {})
|
5
|
-
# property = Property.new(self, name, type, options)
|
6
|
-
#
|
7
|
-
# create_property_getter(property)
|
8
|
-
# create_property_setter(property)
|
9
|
-
#
|
10
|
-
# @properties[repository_name][property.name] = property
|
11
|
-
#
|
12
|
-
# # Add property to the other mappings as well if this is for the default
|
13
|
-
# # repository.
|
14
|
-
# if repository_name == default_repository_name
|
15
|
-
# @properties.each_pair do |repository_name, properties|
|
16
|
-
# next if repository_name == default_repository_name
|
17
|
-
# properties << property
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# # Add the property to the lazy_loads set for this resources repository
|
22
|
-
# # only.
|
23
|
-
# # TODO Is this right or should we add the lazy contexts to all
|
24
|
-
# # repositories?
|
25
|
-
# if property.lazy?
|
26
|
-
# context = options.fetch(:lazy, :default)
|
27
|
-
# context = :default if context == true
|
28
|
-
#
|
29
|
-
# Array(context).each do |item|
|
30
|
-
# @properties[repository_name].lazy_context(item) << name
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# # add the property to the child classes only if the property was
|
35
|
-
# # added after the child classes' properties have been copied from
|
36
|
-
# # the parent
|
37
|
-
# if respond_to?(:descendants)
|
38
|
-
# descendants.each do |model|
|
39
|
-
# next if model.properties(repository_name).has_property?(name)
|
40
|
-
# model.property(name, type, options)
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# property
|
45
|
-
# end
|
46
|
-
#
|
47
|
-
# end # module Model
|
48
|
-
# end # module DataMapper
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# module DataMapper # :nodoc:
|
2
|
-
# class PropertySet # :nodoc:
|
3
|
-
#
|
4
|
-
# def []=(name, property)
|
5
|
-
# if existing_property = detect { |p| p.name == name }
|
6
|
-
# property.hash
|
7
|
-
# @entries[@entries.index(existing_property)] = property
|
8
|
-
# else
|
9
|
-
# add(property)
|
10
|
-
# end
|
11
|
-
# property
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# end # class PropertySet
|
15
|
-
# end # module DataMapper
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# module DataMapper # :nodoc:
|
2
|
-
# module Validate # :nodoc:
|
3
|
-
# class GenericValidator # :nodoc:
|
4
|
-
#
|
5
|
-
# def ==(other)
|
6
|
-
# self.field_name == other.field_name &&
|
7
|
-
# self.if_clause == other.if_clause &&
|
8
|
-
# self.class == other.class &&
|
9
|
-
# self.unless_clause == other.unless_clause &&
|
10
|
-
# self.instance_variable_get(:@options) == other.instance_variable_get(:@options)
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# end # class GenericValidator
|
14
|
-
# end # module Validate
|
15
|
-
# end # module DataMapper
|