activesalesforce 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/asf_adapter.rb +20 -11
- metadata +2 -2
data/lib/asf_adapter.rb
CHANGED
@@ -38,9 +38,13 @@ module ActiveRecord
|
|
38
38
|
class Base
|
39
39
|
@@cache = {}
|
40
40
|
|
41
|
+
def self.debug(msg)
|
42
|
+
logger.debug(msg) if logger
|
43
|
+
end
|
44
|
+
|
41
45
|
# Establishes a connection to the database that's used by all Active Record objects.
|
42
46
|
def self.activesalesforce_connection(config) # :nodoc:
|
43
|
-
|
47
|
+
debug("\nUsing ActiveSalesforce connection\n")
|
44
48
|
|
45
49
|
# Default to production system using 7.0 API
|
46
50
|
url = config[:url]
|
@@ -64,12 +68,12 @@ module ActiveRecord
|
|
64
68
|
binding = @@cache["sid=#{sid}"] unless binding
|
65
69
|
|
66
70
|
unless binding
|
67
|
-
|
71
|
+
debug("Establishing new connection for [sid='#{sid}']")
|
68
72
|
|
69
73
|
binding = RForce::Binding.new(url, sid)
|
70
74
|
@@cache["sid=#{sid}"] = binding
|
71
75
|
|
72
|
-
|
76
|
+
debug("Created new connection for [sid='#{sid}']")
|
73
77
|
end
|
74
78
|
|
75
79
|
ConnectionAdapters::SalesforceAdapter.new(binding, logger, [url, sid], config)
|
@@ -80,7 +84,7 @@ module ActiveRecord
|
|
80
84
|
binding = @@cache["#{url}.#{username}.#{password}"] unless binding
|
81
85
|
|
82
86
|
unless binding
|
83
|
-
|
87
|
+
debug("Establishing new connection for ['#{url}', '#{username}']")
|
84
88
|
|
85
89
|
seconds = Benchmark.realtime {
|
86
90
|
binding = RForce::Binding.new(url, sid)
|
@@ -89,7 +93,7 @@ module ActiveRecord
|
|
89
93
|
@@cache["#{url}.#{username}.#{password}"] = binding
|
90
94
|
}
|
91
95
|
|
92
|
-
|
96
|
+
debug("Created new connection for ['#{url}', '#{username}'] in #{seconds} seconds")
|
93
97
|
end
|
94
98
|
|
95
99
|
ConnectionAdapters::SalesforceAdapter.new(binding, logger, [url, username, password, sid], config)
|
@@ -122,7 +126,7 @@ module ActiveRecord
|
|
122
126
|
|
123
127
|
|
124
128
|
def set_class_for_entity(klass, entity_name)
|
125
|
-
|
129
|
+
debug("Setting @class_to_entity_map['#{entity_name.upcase}'] = #{klass} for connection #{self}")
|
126
130
|
@class_to_entity_map[entity_name.upcase] = klass
|
127
131
|
end
|
128
132
|
|
@@ -525,7 +529,7 @@ module ActiveRecord
|
|
525
529
|
custom = false
|
526
530
|
rescue ActiveSalesforce::ASFError => e
|
527
531
|
# Fallback and see if we can find a custom object with this name
|
528
|
-
|
532
|
+
debug(" Unable to find medata for '#{entity_name}', falling back to custom object name #{entity_name + "__c"}")
|
529
533
|
|
530
534
|
metadata = get_result(@connection.describeSObject(:sObjectType => entity_name + "__c"), :describeSObject)
|
531
535
|
custom = true
|
@@ -592,7 +596,7 @@ module ActiveRecord
|
|
592
596
|
# DCHASMAN TODO Figure out how to handle polymorphic refs (e.g. Note.parent can refer to
|
593
597
|
# Account, Contact, Opportunity, Contract, Asset, Product2, <CustomObject1> ... <CustomObject(n)>
|
594
598
|
if reference_to.is_a? Array
|
595
|
-
|
599
|
+
debug(" Skipping unsupported polymophic one-to-#{one_to_many ? 'many' : 'one' } relationship '#{referenceName}' from #{klass} to [#{relationship.reference_to.join(', ')}] using #{foreign_key}")
|
596
600
|
next
|
597
601
|
end
|
598
602
|
|
@@ -607,7 +611,7 @@ module ActiveRecord
|
|
607
611
|
|
608
612
|
rescue NameError => e
|
609
613
|
# Automatically create a least a stub for the referenced entity
|
610
|
-
|
614
|
+
debug(" Creating ActiveRecord stub for the referenced entity '#{reference_to}'")
|
611
615
|
|
612
616
|
referenced_klass = klass.class_eval("::#{reference_to} = Class.new(ActiveRecord::Base)")
|
613
617
|
|
@@ -622,7 +626,7 @@ module ActiveRecord
|
|
622
626
|
klass.belongs_to referenceName.to_sym, :class_name => referenced_klass.name, :foreign_key => foreign_key, :dependent => false
|
623
627
|
end
|
624
628
|
|
625
|
-
|
629
|
+
debug(" Created one-to-#{one_to_many ? 'many' : 'one' } relationship '#{referenceName}' from #{klass} to #{referenced_klass} using #{foreign_key}")
|
626
630
|
end
|
627
631
|
end
|
628
632
|
end
|
@@ -638,7 +642,7 @@ module ActiveRecord
|
|
638
642
|
|
639
643
|
def class_from_entity_name(entity_name)
|
640
644
|
entity_klass = @class_to_entity_map[entity_name.upcase]
|
641
|
-
|
645
|
+
debug("Found matching class '#{entity_klass}' for entity '#{entity_name}'") if entity_klass
|
642
646
|
|
643
647
|
entity_klass = entity_name.constantize unless entity_klass
|
644
648
|
|
@@ -681,6 +685,11 @@ module ActiveRecord
|
|
681
685
|
[table_name, columns, entity_def]
|
682
686
|
end
|
683
687
|
|
688
|
+
|
689
|
+
def debug(msg)
|
690
|
+
@logger.debug(msg) if @logger
|
691
|
+
end
|
692
|
+
|
684
693
|
end
|
685
694
|
|
686
695
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activesalesforce
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2006-05-
|
6
|
+
version: 0.5.5
|
7
|
+
date: 2006-05-04 00:00:00 -04: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:
|
10
10
|
- lib
|