ar-extensions 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +8 -0
- data/Rakefile +9 -6
- data/db/migrate/generic_schema.rb +2 -0
- data/lib/ar-extensions/csv.rb +11 -9
- data/lib/ar-extensions/extensions.rb +1 -0
- data/lib/ar-extensions/finders.rb +3 -2
- data/lib/ar-extensions/import.rb +4 -2
- data/lib/ar-extensions/temporary_table.rb +1 -1
- data/lib/ar-extensions/version.rb +1 -1
- metadata +6 -5
data/ChangeLog
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
2009-02-09 zdennis <zach.dennis@gmail.com>
|
2
|
+
|
3
|
+
* fixed issue in http://zdennis.lighthouseapp.com/projects/14379/tickets/14-join-table-conditions-broken
|
4
|
+
* Updated usage of Inflector to point to ActiveSupport::Inflector
|
5
|
+
* Fixed bug where finder conditions which use arext-suffixed keys and normal field keys would fail when using a conditions hash. (Gabe da Silveira)
|
6
|
+
* added timestamps options to not automatically add timestamps even if record timestamps is disabled in ActiveRecord::Base (Thibaud Guillaume-Gentil)
|
7
|
+
* Updated to use alias_method_chain so that multiple aliased finders remain intact (Marcus Crafter)
|
8
|
+
|
1
9
|
2007-07-20 zdennis <zdennis@dhcp-22.atomicobject.localnet>
|
2
10
|
|
3
11
|
* Added patch from Michael Flester to fix bug with created_at/updated_at fields to use proper timezone.
|
data/Rakefile
CHANGED
@@ -14,12 +14,8 @@ end
|
|
14
14
|
|
15
15
|
ADAPTERS = %w( mysql postgresql sqlite sqlite3 oracle )
|
16
16
|
|
17
|
-
desc "Packages a rubygem"
|
18
|
-
task "pkg" do
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
17
|
namespace :db do
|
18
|
+
|
23
19
|
namespace :test do
|
24
20
|
ADAPTERS.each do |adapter|
|
25
21
|
desc "builds test database for #{adapter}"
|
@@ -29,13 +25,16 @@ namespace :db do
|
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
28
|
+
|
32
29
|
end
|
33
30
|
|
34
31
|
namespace :test do
|
32
|
+
|
35
33
|
ADAPTERS.each do |adapter|
|
36
34
|
desc "test base extensions for #{adapter}"
|
37
35
|
task adapter do |t|
|
38
36
|
ENV['ARE_DB'] = adapter
|
37
|
+
|
39
38
|
task = Rake::Task[ "db:test:prepare_#{adapter}" ]
|
40
39
|
begin
|
41
40
|
task = false if SchemaInfo::VERSION == SchemaInfo.find( :first ).version
|
@@ -48,6 +47,7 @@ namespace :test do
|
|
48
47
|
end
|
49
48
|
|
50
49
|
namespace :activerecord do
|
50
|
+
|
51
51
|
ADAPTERS.each do |adapter|
|
52
52
|
desc "runs ActiveRecord unit tests for #{adapter} with ActiveRecord::Extensions"
|
53
53
|
task adapter.to_sym do |t|
|
@@ -66,6 +66,9 @@ namespace :test do
|
|
66
66
|
Dir.chdir( old_dir )
|
67
67
|
ENV['RUBYOPT'] = old_env
|
68
68
|
end
|
69
|
+
|
69
70
|
end
|
71
|
+
|
70
72
|
end
|
71
|
-
|
73
|
+
|
74
|
+
end
|
data/lib/ar-extensions/csv.rb
CHANGED
@@ -66,14 +66,16 @@ end
|
|
66
66
|
# although nesting multiple has_one/belongs_to associations.
|
67
67
|
#
|
68
68
|
module ActiveRecord::Extensions::FindToCSV
|
69
|
-
ALIAS_FOR_FIND = :_original_find_before_arext
|
70
69
|
|
71
|
-
def self.included(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
def self.included(base)
|
71
|
+
if !base.respond_to?(:find_with_csv)
|
72
|
+
base.class_eval do
|
73
|
+
extend ClassMethods
|
74
|
+
include InstanceMethods
|
75
|
+
end
|
76
|
+
class << base
|
77
|
+
alias_method_chain :find, :csv
|
78
|
+
end
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
@@ -125,8 +127,8 @@ module ActiveRecord::Extensions::FindToCSV
|
|
125
127
|
|
126
128
|
public
|
127
129
|
|
128
|
-
def
|
129
|
-
results =
|
130
|
+
def find_with_csv( *args ) # :nodoc:
|
131
|
+
results = find_without_csv( *args )
|
130
132
|
results.extend( ArrayInstanceMethods ) if results.is_a?( Array )
|
131
133
|
results
|
132
134
|
end
|
@@ -10,7 +10,6 @@ module ActiveRecord::ConnectionAdapters::Quoting
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
13
|
class ActiveRecord::Base
|
15
14
|
|
16
15
|
class << self
|
@@ -55,12 +54,14 @@ class ActiveRecord::Base
|
|
55
54
|
if val.respond_to?( :to_sql )
|
56
55
|
conditions << sanitize_sql_by_way_of_duck_typing( val )
|
57
56
|
next
|
57
|
+
elsif val.is_a?(Hash) # don't mess with ActiveRecord hash nested hash functionality
|
58
|
+
conditions << sanitize_sql_hash_for_conditions(key => val)
|
58
59
|
else
|
59
60
|
sql = nil
|
60
61
|
result = ActiveRecord::Extensions.process( key, val, self )
|
61
62
|
if result
|
62
63
|
conditions << result.sql
|
63
|
-
values.push( result.value )
|
64
|
+
values.push( result.value ) unless result.value.nil?
|
64
65
|
else
|
65
66
|
# Extract table name from qualified attribute names.
|
66
67
|
attr = key.to_s
|
data/lib/ar-extensions/import.rb
CHANGED
@@ -93,6 +93,8 @@ class ActiveRecord::Base
|
|
93
93
|
# * +synchronize+ - an array of ActiveRecord instances for the model
|
94
94
|
# that you are currently importing data into. This synchronizes
|
95
95
|
# existing model instances in memory with updates from the import.
|
96
|
+
# * +timestamps+ - true|false, tells import to not add timestamps \
|
97
|
+
# (if false) even if record timestamps is disabled in ActiveRecord::Base
|
96
98
|
#
|
97
99
|
# == Examples
|
98
100
|
# class BlogPost < ActiveRecord::Base ; end
|
@@ -149,7 +151,7 @@ class ActiveRecord::Base
|
|
149
151
|
def import( *args )
|
150
152
|
@logger = Logger.new(STDOUT)
|
151
153
|
@logger.level = Logger::DEBUG
|
152
|
-
options = { :validate=>true }
|
154
|
+
options = { :validate=>true, :timestamps=>true }
|
153
155
|
options.merge!( args.pop ) if args.last.is_a? Hash
|
154
156
|
|
155
157
|
# assume array of model objects
|
@@ -194,7 +196,7 @@ class ActiveRecord::Base
|
|
194
196
|
array_of_attributes = array_of_attributes.dup
|
195
197
|
|
196
198
|
# record timestamps unless disabled in ActiveRecord::Base
|
197
|
-
if record_timestamps
|
199
|
+
if record_timestamps && options.delete( :timestamps )
|
198
200
|
add_special_rails_stamps column_names, array_of_attributes, options
|
199
201
|
end
|
200
202
|
|
@@ -75,7 +75,7 @@ class ActiveRecord::Base
|
|
75
75
|
options[:like] = self unless options[:like]
|
76
76
|
options[:temporary] = true if not options[:permanent] and not options.has_key?( :temporary )
|
77
77
|
table_name = options[:table_name]
|
78
|
-
model_name = options[:model_name] || Inflector.classify( table_name )
|
78
|
+
model_name = options[:model_name] || ActiveSupport::Inflector.classify( table_name )
|
79
79
|
raise Exception.new( "Model #{model_name} already exists! \n" ) if Object.const_defined? model_name
|
80
80
|
|
81
81
|
like_table_name = options[:like].table_name || self.table_name
|
metadata
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-extensions
|
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
|
- Zach Dennis
|
8
8
|
- Mark Van Holstyn
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2009-02-09 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
18
|
+
type: :runtime
|
18
19
|
version_requirement:
|
19
20
|
version_requirements: !ruby/object:Gem::Requirement
|
20
21
|
requirements:
|
21
22
|
- - ">="
|
22
23
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
+
version: 2.0.2
|
24
25
|
version:
|
25
26
|
description: Extends ActiveRecord functionality by adding better finder/query support, as well as supporting mass data import, foreign key, CSV and temporary tables
|
26
27
|
email: zach.dennis@gmail.com
|
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
88
|
requirements: []
|
88
89
|
|
89
90
|
rubyforge_project: arext
|
90
|
-
rubygems_version: 1.1
|
91
|
+
rubygems_version: 1.3.1
|
91
92
|
signing_key:
|
92
93
|
specification_version: 2
|
93
94
|
summary: Extends ActiveRecord functionality.
|