active_force 0.5.0 → 0.6.0

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.
@@ -0,0 +1,357 @@
1
+ module StandardTypes
2
+ STANDARD_TYPES = %w[
3
+ Account
4
+ Asset
5
+ AssetFeed
6
+ AssetTag
7
+ AssignmentRule
8
+ AsyncApexJob
9
+ AttachedContentDocument
10
+ Attachment
11
+ AuthSession
12
+ Bookmark
13
+ BrandTemplate
14
+ BusinessHours
15
+ BusinessProcess
16
+ CallCenter
17
+ Campaign
18
+ CampaignFeed
19
+ CampaignMember
20
+ CampaignMemberStatus
21
+ CampaignOwnerSharingRule
22
+ Campaign
23
+ CampaignShare
24
+ CampaignTag
25
+ Case
26
+ CaseArticle
27
+ CaseComment
28
+ CaseContactRole
29
+ CaseFeed
30
+ CaseHistory
31
+ CaseMilestone
32
+ CaseOwnerSharingRule
33
+ CaseShare
34
+ CaseSolution
35
+ Solution
36
+ CaseStatus
37
+ CaseTag
38
+ CaseTeamMember
39
+ CaseTeamRole
40
+ CaseTeamTemplate
41
+ CaseTeamTemplateMember
42
+ CaseTeamTemplateRecord
43
+ CategoryData
44
+ CategoryNode
45
+ CategoryNodeLocalization
46
+ ChatterActivity
47
+ ChatterAnswersActivity
48
+ ChatterAnswersReputationLevel
49
+ ChatterAnswersReputationLevel
50
+ ChatterConversation
51
+ ChatterConversationMember
52
+ ChatterMessage
53
+ CollaborationGroup
54
+ CollaborationGroupFeed
55
+ CollaborationGroupMember
56
+ CollaborationGroupMemberRequest
57
+ CollaborationInvitation
58
+ CombinedAttachment
59
+ Community
60
+ Contact
61
+ ContactFeed
62
+ ContactHistory
63
+ ContactOwnerSharingRule
64
+ ContactShare
65
+ ContactTag
66
+ ContentDocument
67
+ ContentDocumentFeed
68
+ ContentDocumentHistory
69
+ ContentDocumentLink
70
+ ContentVersion
71
+ ContentVersionHistory
72
+ ContentWorkspace
73
+ ContentWorkspaceDoc
74
+ Contract
75
+ ContractContactRole
76
+ ContractFeed
77
+ ContractHistory
78
+ ContractLineItem
79
+ ContractLineItemHistory
80
+ ContractStatus
81
+ ContractTag
82
+ CronTrigger
83
+ CronJobDetail
84
+ CurrencyType
85
+ CustomBrand
86
+ CustomBrandAsset
87
+ CustomPermission
88
+ DandBCompany
89
+ Dashboard
90
+ DashboardComponent
91
+ DashboardComponentFeed
92
+ DashboardFeed
93
+ DashboardTag
94
+ DatacloudCompany
95
+ DatacloudContact
96
+ DatacloudDandBCompany
97
+ DatacloudOwnedEntity
98
+ DatacloudPurchaseUsage
99
+ DatacloudSocialHandle
100
+ DatedConversionRate
101
+ DeclinedEventRelation
102
+ Division
103
+ DivisionLocalization
104
+ Document
105
+ DocumentAttachmentMap
106
+ DocumentTag
107
+ EmailMessage
108
+ EmailServicesAddress
109
+ EmailServicesFunction
110
+ EmailStatus
111
+ EmailTemplate
112
+ Entitlement
113
+ EntitlementContact
114
+ EntitlementFeed
115
+ EntitlementHistory
116
+ EntitlementTemplate
117
+ EntityHistory
118
+ EntitySubscription
119
+ EnvironmentHubMember
120
+ Event
121
+ EventFeed
122
+ EventRelation
123
+ EventTag
124
+ EventWhoRelation
125
+ EventRelation
126
+ ExternalDataSource
127
+ ExternalDataUserAuth
128
+ FeedComment
129
+ FeedItem
130
+ FeedLike
131
+ FeedPollChoice
132
+ FeedPollVote
133
+ FeedPost
134
+ FeedTrackedChange
135
+ FieldPermissions
136
+ FiscalYearSettings
137
+ Folder
138
+ ForecastingAdjustment
139
+ ForecastingFact
140
+ ForecastingItem
141
+ ForecastingQuota
142
+ ForecastShare
143
+ Group
144
+ GroupMember
145
+ HashtagDefinition
146
+ Holiday
147
+ Idea
148
+ IdeaComment
149
+ IdeaTheme
150
+ KnowledgeableUser
151
+ KnowledgeArticle
152
+ KnowledgeArticleVersion
153
+ KnowledgeArticleVersionHistory
154
+ KnowledgeArticleViewStat
155
+ KnowledgeArticleVoteStat
156
+ Lead
157
+ LeadFeed
158
+ LeadHistory
159
+ LeadOwnerSharingRule
160
+ LeadShare
161
+ LeadStatus
162
+ LeadTag
163
+ LimitAllocationPerApp
164
+ LineitemOverride
165
+ LoginHistory
166
+ MailmergeTemplate
167
+ MilestoneType
168
+ Name
169
+ Network
170
+ NetworkActivityAudit
171
+ NetworkMember
172
+ NetworkMemberGroup
173
+ NetworkModeration
174
+ NewsFeed
175
+ Note
176
+ NoteAndAttachment
177
+ NoteTag
178
+ ObjectPermissions
179
+ ObjectTerritory2AssignmentRule
180
+ ObjectTerritory2AssignmentRuleItem
181
+ ObjectTerritory2Association
182
+ OpenActivity
183
+ Opportunity
184
+ OpportunityCompetitor
185
+ OpportunityContactRole
186
+ OpportunityFeed
187
+ OpportunityFieldHistory
188
+ OpportunityHistory
189
+ OpportunityLineItem
190
+ OpportunityLineItemSchedule
191
+ OpportunityOverride
192
+ OpportunityOwnerSharingRule
193
+ OpportunityPartner
194
+ OpportunityShare
195
+ OpportunitySplit
196
+ OpportunitySplitType
197
+ OpportunityStage
198
+ OpportunityTag
199
+ OpportunityTeamMember
200
+ Organization
201
+ OrgWideEmailAddress
202
+ OwnedContentDocument
203
+ PackageLicense
204
+ Partner
205
+ PartnerNetworkConnection
206
+ PartnerNetworkRecordConnection
207
+ PartnerRole
208
+ Period
209
+ PermissionSet
210
+ PermissionSetAssignment
211
+ Pricebook2
212
+ Pricebook2History
213
+ PricebookEntry
214
+ ProcessDefinition
215
+ ProcessInstance
216
+ ProcessInstanceHistory
217
+ ProcessInstanceNode
218
+ ProcessInstanceStep
219
+ ProcessInstanceWorkitem
220
+ ProcessNode
221
+ Product2
222
+ Product2Feed
223
+ ProductEntitlementTemplate
224
+ Profile
225
+ ProfileSkill
226
+ ProfileSkillEndorsement
227
+ ProfileSkillEndorsementHistory
228
+ ProfileSkillFeed
229
+ ProfileSkillHistory
230
+ ProfileSkillShare
231
+ ProfileSkillUser
232
+ ProfileSkillUserHistory
233
+ PushTopic
234
+ QuantityForecast
235
+ QuantityForecastHistory
236
+ Question
237
+ QuestionDataCategorySelection
238
+ QuestionReportAbuse
239
+ QuestionSubscription
240
+ QueueSobject
241
+ Quote
242
+ QuoteDocument
243
+ QuoteLineItem
244
+ RecentlyViewed
245
+ RecordType
246
+ RecordTypeLocalization
247
+ Reply
248
+ ReplyReportAbuse
249
+ Report
250
+ ReportFeed
251
+ ReportTag
252
+ RevenueForecast
253
+ RevenueForecastHistory
254
+ RuleTerritory2Association
255
+ Scontrol
256
+ ScontrolLocalization
257
+ SelfServiceUser
258
+ ServiceContract
259
+ ServiceContractFeed
260
+ ServiceContractHistory
261
+ ServiceContractOwnerSharingRule
262
+ ServiceContractShare
263
+ SetupEntityAccess
264
+ SignupRequest
265
+ Site
266
+ SiteHistory
267
+ SlaProcess
268
+ Solution
269
+ SolutionFeed
270
+ SolutionHistory
271
+ SolutionStatus
272
+ SolutionTag
273
+ StaticResource
274
+ StreamingChannel
275
+ TagDefinition
276
+ Task
277
+ TaskFeed
278
+ TaskPriority
279
+ TaskRelation
280
+ TaskStatus
281
+ TaskTag
282
+ TaskWhoRelation
283
+ TaskRelation
284
+ Territory
285
+ Territory2
286
+ Territory2Model
287
+ Territory2ModelHistory
288
+ Territory2Type
289
+ Topic
290
+ TopicAssignment
291
+ TopicFeed
292
+ UndecidedEventRelation
293
+ User
294
+ UserAccountTeamMember
295
+ UserConfigTransferButton
296
+ UserConfigTransferSkill
297
+ UserFeed
298
+ UserLicense
299
+ UserLogin
300
+ UserMembershipSharingRule
301
+ UserPackageLicense
302
+ UserPreference
303
+ UserProfile
304
+ UserProfileFeed
305
+ UserRecordAccess
306
+ UserRole
307
+ UserShare
308
+ UserTeamMember
309
+ UserTerritory
310
+ UserTerritory2Association
311
+ Vote
312
+ WebLink
313
+ WebLinkLocalization
314
+ WorkAccess
315
+ WorkAccessShare
316
+ WorkBadge
317
+ WorkBadgeDefinition
318
+ WorkBadgeDefinitionHistory
319
+ WorkBadgeDefinitionShare
320
+ WorkCoaching
321
+ WorkCoachingFeed
322
+ WorkCoachingHistory
323
+ WorkCoachingShare
324
+ WorkFeedback
325
+ WorkFeedbackQuestion
326
+ WorkFeedbackQuestionHistory
327
+ WorkFeedbackQuestionSet
328
+ WorkFeedbackQuestionSetShare
329
+ WorkFeedbackQuestionShare
330
+ WorkFeedbackRequest
331
+ WorkFeedbackRequestHistory
332
+ WorkFeedbackRequestShare
333
+ WorkFeedbackShare
334
+ WorkGoal
335
+ WorkGoalCollaborator
336
+ WorkGoalCollaboratorHistory
337
+ WorkGoalFeed
338
+ WorkGoalHistory
339
+ WorkGoalLink
340
+ WorkGoalShare
341
+ WorkPerformanceCycle
342
+ WorkPerformanceCycleFeed
343
+ WorkPerformanceCycleHistory
344
+ WorkPerformanceCycleShare
345
+ WorkReward
346
+ WorkRewardFund
347
+ WorkRewardFundHistory
348
+ WorkRewardFundShare
349
+ WorkRewardFundType
350
+ WorkRewardFundTypeHistory
351
+ WorkRewardFundTypeShare
352
+ WorkRewardHistory
353
+ WorkRewardShare
354
+ WorkThanks
355
+ WorkThanksShare
356
+ ]
357
+ end
@@ -0,0 +1,33 @@
1
+ require 'active_force/standard_types'
2
+
3
+ module ActiveForce
4
+ class Table
5
+
6
+ def initialize klass
7
+ @klass = klass.to_s
8
+ end
9
+
10
+ def name
11
+ @name ||= pick_table_name
12
+ end
13
+
14
+ def custom_table_name?
15
+ !StandardTypes::STANDARD_TYPES.include?(name_without_namespace)
16
+ end
17
+
18
+ private
19
+
20
+ def pick_table_name
21
+ if custom_table_name?
22
+ "#{ name_without_namespace }__c"
23
+ else
24
+ name_without_namespace
25
+ end
26
+ end
27
+
28
+ def name_without_namespace
29
+ @klass.split('::').last
30
+ end
31
+
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveForce
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -0,0 +1,61 @@
1
+ module ActiveForce
2
+ class ModelGenerator < Rails::Generators::NamedBase
3
+ desc 'This generator loads the table fields from SFDC and generates the fields for the SObject with a more ruby names'
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def create_model_file
8
+ @table_name = file_name.capitalize
9
+ @class_name = @table_name.gsub '__c', ''
10
+ template "model.rb.erb", "app/models/#{@class_name.downcase}.rb" if table_exists?
11
+ end
12
+
13
+ protected
14
+
15
+ Attribute = Struct.new :field, :column
16
+
17
+ def attributes
18
+ @attributes ||= sfdc_columns.map do |column|
19
+ Attribute.new column_to_field(column), column
20
+ end
21
+ end
22
+
23
+ def sfdc_columns
24
+ @columns ||= ActiveForce::SObject.sfdc_client.describe(@table_name).fields.map do |field|
25
+ field.name
26
+ end
27
+ end
28
+
29
+ def table_exists?
30
+ !! sfdc_columns
31
+ rescue Faraday::Error::ResourceNotFound
32
+ puts "The specified table name is not found. Be sure to append __c if it's custom"
33
+ end
34
+
35
+ def column_to_field column
36
+ column.underscore.gsub("__c", "").to_sym
37
+ end
38
+
39
+ def attribute_line attribute
40
+ "field :#{ attribute.field },#{ space_justify attribute.field } from: '#{ attribute.column }'"
41
+ end
42
+
43
+ def space_justify field_name
44
+ longest_field = attributes.map { |attr| attr.field.length } .max
45
+ justify_count = longest_field - field_name.length
46
+ " " * justify_count
47
+ end
48
+
49
+
50
+ class String
51
+ def underscore
52
+ self.gsub(/::/, '/').
53
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
54
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
55
+ tr("-", "_").
56
+ downcase
57
+ end
58
+ end
59
+
60
+ end
61
+ end