ar-extensions 0.8.0 → 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/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
- end
73
+
74
+ end
@@ -22,6 +22,8 @@ ActiveRecord::Schema.define do
22
22
  t.column :replies_count, :integer
23
23
  t.column :parent_id, :integer
24
24
  t.column :type, :string
25
+ t.column :created_at, :datetime
26
+ t.column :updated_at, :datetime
25
27
  end
26
28
 
27
29
  create_table :projects, :force=>true do |t|
@@ -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( cl ) # :nodoc:
72
- virtual_class = class << cl ; self ; end
73
- if not virtual_class.ancestors.include?( self::ClassMethods )
74
- cl.instance_eval "alias #{ALIAS_FOR_FIND} :find"
75
- cl.extend( ClassMethods )
76
- cl.send( :include, InstanceMethods )
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 find( *args ) # :nodoc:
129
- results = self.send( ALIAS_FOR_FIND, *args )
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
@@ -283,6 +283,7 @@ module ActiveRecord::Extensions
283
283
  result_values << $2
284
284
  '?'
285
285
  end
286
+ result_values = nil if result_values.empty?
286
287
  return Result.new(str , result_values)
287
288
  end
288
289
  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
@@ -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
@@ -2,7 +2,7 @@
2
2
  module ActiveRecord # :nodoc:
3
3
  module Extensions # :nodoc:
4
4
  module VERSION
5
- MAJOR, MINOR, REVISION = %W( 0 7 0 )
5
+ MAJOR, MINOR, REVISION = %W( 0 8 1 )
6
6
  STRING = [ MAJOR, MINOR, REVISION ].join( '.' )
7
7
  end
8
8
  end
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.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis
8
8
  - Mark Van Holstyn
9
- autorequire: ar-extensions.rb
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-08-06 00:00:00 -04:00
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: 1.14.1
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.0
91
+ rubygems_version: 1.3.1
91
92
  signing_key:
92
93
  specification_version: 2
93
94
  summary: Extends ActiveRecord functionality.