activesalesforce 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ =begin
2
+ ActiveSalesforce
3
+ Copyright 2006 Doug Chasman
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ =end
17
+
18
+ module ActiveSalesforce
19
+
20
+ module ActiveRecord
21
+
22
+ module Mixin
23
+ def self.append_features(base) #:nodoc:
24
+ super
25
+
26
+ base.class_eval do
27
+ class << self
28
+ def set_table_name(value = nil, &block)
29
+ super(value, &block)
30
+ connection.set_class_for_entity(self, table_name.singularize)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ end
data/lib/asf_adapter.rb CHANGED
@@ -26,6 +26,8 @@ require File.dirname(__FILE__) + '/column_definition'
26
26
  require File.dirname(__FILE__) + '/relationship_definition'
27
27
  require File.dirname(__FILE__) + '/boxcar_command'
28
28
  require File.dirname(__FILE__) + '/entity_definition'
29
+ require File.dirname(__FILE__) + '/asf_active_record'
30
+
29
31
 
30
32
  class ResultArray < Array
31
33
  attr_reader :actual_size
@@ -35,6 +37,7 @@ class ResultArray < Array
35
37
  end
36
38
  end
37
39
 
40
+
38
41
  module ActiveRecord
39
42
  class Base
40
43
  @@cache = {}
@@ -93,7 +96,7 @@ module ActiveRecord
93
96
  end
94
97
  end
95
98
  end
96
-
99
+
97
100
 
98
101
  module ConnectionAdapters
99
102
  class SalesforceError < RuntimeError
@@ -125,12 +128,21 @@ module ActiveRecord
125
128
  @entity_def_map = {}
126
129
 
127
130
  @command_boxcar = []
131
+ @class_to_entity_map = {}
132
+ end
133
+
134
+
135
+ def set_class_for_entity(klass, entity_name)
136
+ @logger.debug("Setting @class_to_entity_map['#{entity_name.upcase}'] = #{klass}")
137
+ @class_to_entity_map[entity_name.upcase] = klass
128
138
  end
129
139
 
140
+
130
141
  def binding
131
142
  @connection
132
143
  end
133
144
 
145
+
134
146
  def adapter_name #:nodoc:
135
147
  'ActiveSalesforce'
136
148
  end
@@ -459,7 +471,7 @@ module ActiveRecord
459
471
 
460
472
  if cached_entity_def
461
473
  # Check for the loss of asf AR setup
462
- entity_klass = entity_name.constantize
474
+ entity_klass = class_from_entity_name(entity_name)
463
475
 
464
476
  configure_active_record cached_entity_def unless entity_klass.respond_to?(:asf_augmented?)
465
477
 
@@ -512,7 +524,7 @@ module ActiveRecord
512
524
 
513
525
  def configure_active_record(entity_def)
514
526
  entity_name = entity_def.name
515
- klass = entity_name.constantize
527
+ klass = class_from_entity_name(entity_name)
516
528
 
517
529
  class << klass
518
530
  def asf_augmented?
@@ -544,7 +556,7 @@ module ActiveRecord
544
556
  reference_to = reference_to.chop.chop.chop.capitalize if reference_to.match(/__c$/)
545
557
 
546
558
  begin
547
- referenced_klass = reference_to.constantize
559
+ referenced_klass = class_from_entity_name(reference_to)
548
560
  rescue NameError => e
549
561
  # Automatically create a least a stub for the referenced entity
550
562
  @logger.debug(" Creating ActiveRecord stub for the referenced entity '#{reference_to}'")
@@ -585,6 +597,16 @@ module ActiveRecord
585
597
  end
586
598
 
587
599
 
600
+ def class_from_entity_name(entity_name)
601
+ entity_klass = @class_to_entity_map[entity_name.upcase]
602
+ @logger.debug("Found matching class '#{entity_klass}' for entity '#{entity_name}'") if entity_klass
603
+
604
+ entity_klass = entity_name.constantize unless entity_klass
605
+
606
+ entity_klass
607
+ end
608
+
609
+
588
610
  def create_sobject(entity_name, id, fields)
589
611
  entity_def = get_entity_def(entity_name)
590
612
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: activesalesforce
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.6
6
+ version: 0.3.7
7
7
  date: 2006-02-27 00:00:00 -05:00
8
8
  summary: ActiveSalesforce (ASF) is a Rails connection adapter that provides direct access to Salesforce.com hosted data and metadata via the ActiveRecord model layer. Objects, fields, and relationships are all auto surfaced as active record attributes and rels.
9
9
  require_paths:
@@ -37,6 +37,7 @@ files:
37
37
  - lib/asf_adapter.rb
38
38
  - lib/sid_authentication_filter.rb
39
39
  - lib/relationship_definition.rb
40
+ - lib/asf_active_record.rb
40
41
  - test/unit
41
42
  - test/unit/recorded_test_case.rb
42
43
  - test/unit/basic_test.rb