afc_salesforce 0.1.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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/README.md +1 -0
  8. data/Rakefile +6 -0
  9. data/afc_salesforce.gemspec +40 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/afc_salesforce.rb +56 -0
  13. data/lib/afc_salesforce/account.rb +61 -0
  14. data/lib/afc_salesforce/additional_income.rb +12 -0
  15. data/lib/afc_salesforce/ahc_realtor.rb +0 -0
  16. data/lib/afc_salesforce/asset.rb +13 -0
  17. data/lib/afc_salesforce/base.rb +11 -0
  18. data/lib/afc_salesforce/borrower.rb +36 -0
  19. data/lib/afc_salesforce/configuration.rb +16 -0
  20. data/lib/afc_salesforce/forms/agent_referral.rb +50 -0
  21. data/lib/afc_salesforce/forms/long_purchase.rb +56 -0
  22. data/lib/afc_salesforce/forms/long_refinance.rb +56 -0
  23. data/lib/afc_salesforce/forms/short_lead.rb +48 -0
  24. data/lib/afc_salesforce/lead.rb +31 -0
  25. data/lib/afc_salesforce/models/account.rb +267 -0
  26. data/lib/afc_salesforce/models/ahc_realtor.rb +67 -0
  27. data/lib/afc_salesforce/models/asset.rb +35 -0
  28. data/lib/afc_salesforce/models/base.rb +17 -0
  29. data/lib/afc_salesforce/models/concerns/type_setter.rb +23 -0
  30. data/lib/afc_salesforce/models/contact.rb +152 -0
  31. data/lib/afc_salesforce/models/income.rb +25 -0
  32. data/lib/afc_salesforce/models/lead.rb +118 -0
  33. data/lib/afc_salesforce/tools.rb +4 -0
  34. data/lib/afc_salesforce/tools/utilities.rb +45 -0
  35. data/lib/afc_salesforce/tools/validation.rb +18 -0
  36. data/lib/afc_salesforce/tools/validation/rule/email.rb +58 -0
  37. data/lib/afc_salesforce/tools/validation/rule/instance_of.rb +36 -0
  38. data/lib/afc_salesforce/tools/validation/rule/length.rb +52 -0
  39. data/lib/afc_salesforce/tools/validation/rule/matches.rb +44 -0
  40. data/lib/afc_salesforce/tools/validation/rule/not_empty.rb +32 -0
  41. data/lib/afc_salesforce/tools/validation/rule/not_nil.rb +32 -0
  42. data/lib/afc_salesforce/tools/validation/rule/numeric.rb +32 -0
  43. data/lib/afc_salesforce/tools/validation/rule/phone.rb +51 -0
  44. data/lib/afc_salesforce/tools/validation/rule/regular_expression.rb +33 -0
  45. data/lib/afc_salesforce/tools/validation/validator.rb +128 -0
  46. data/lib/afc_salesforce/version.rb +3 -0
  47. metadata +194 -0
@@ -0,0 +1,128 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # A hash of rules for this object
6
+ def rules
7
+ @rules ||= {}
8
+ end
9
+
10
+ # A hash of errors for this object
11
+ def errors
12
+ @errors ||= {}
13
+ end
14
+
15
+ # Define a rule for this object
16
+ #
17
+ # The rule parameter can be one of the following:
18
+ #
19
+ # * a symbol that matches to a class in the AFCSalesforce::Tools::Validation::Rules namespace
20
+ # * e.g. rule(:field, :not_empty)
21
+ # * a hash containing the rule as the key and it's parameters as the values
22
+ # * e.g. rule(:field, :length => { minimum: 3, maximum: 5 })
23
+ # * an array combining the two previous types
24
+ # * e.g. rule(:field, [:not_empty, length: { minimum: 3, maximum: 5}])
25
+ def rule(field, definition)
26
+ field = field.to_sym
27
+ rules[field] = [] if rules[field].nil?
28
+
29
+ if definition.respond_to?(:each_pair)
30
+ add_parameterized_rules(field, definition)
31
+ elsif definition.respond_to?(:each)
32
+ definition.each do |item|
33
+ if item.respond_to?(:each_pair)
34
+ add_parameterized_rules(field, item)
35
+ else
36
+ add_single_rule(field, item)
37
+ end
38
+ end
39
+ else
40
+ add_single_rule(field, definition)
41
+ end
42
+
43
+ self
44
+ end
45
+
46
+ # Determines if this object is valid. When a rule fails for a field,
47
+ # this will stop processing further rules. In this way, you'll only get
48
+ # one error per field
49
+ def valid?
50
+ valid = true
51
+
52
+ rules.each_pair do |field, rules|
53
+ if ! @obj.respond_to?(field)
54
+ raise InvalidKey, "cannot validate non-existent field '#{field}'"
55
+ end
56
+
57
+ rules.each do |r|
58
+ value = @obj.send(field)
59
+ if !r.valid_value?(value)
60
+ valid = false
61
+ errors[field] = {rule: r.error_key}.merge(r.error(value))
62
+ break
63
+ end
64
+ end
65
+ end
66
+
67
+ @valid = valid
68
+ end
69
+
70
+ protected
71
+
72
+ # Adds a single rule to this object
73
+ def add_single_rule(field, key_or_klass, params = nil)
74
+ klass = if key_or_klass.respond_to?(:new)
75
+ key_or_klass
76
+ else
77
+ get_rule_class_by_name(key_or_klass)
78
+ end
79
+
80
+ args = [params].compact
81
+ rule = klass.new(*args)
82
+ rule.obj = @obj if rule.respond_to?(:obj=)
83
+ rules[field] << rule
84
+ end
85
+
86
+ # Adds a set of parameterized rules to this object
87
+ def add_parameterized_rules(field, rules)
88
+ rules.each_pair do |key, params|
89
+ add_single_rule(field, key, params)
90
+ end
91
+ end
92
+
93
+ # Resolves the specified rule name to a rule class
94
+ def get_rule_class_by_name(klass)
95
+ klass = camelize(klass)
96
+ AFCSalesforce::Tools::Validation::Rule.const_get(klass)
97
+ rescue NameError => e
98
+ raise InvalidRule.new(e)
99
+ end
100
+
101
+ # Converts a symbol to a class name, taken from rails
102
+ def camelize(term)
103
+ string = term.to_s
104
+ string = string.sub(/^[a-z\d]*/) { $&.capitalize }
105
+ string.gsub(/(?:_|(\/))([a-z\d]*)/i) { $2.capitalize }.gsub('/', '::')
106
+ end
107
+ end
108
+
109
+
110
+ class Validator
111
+ include AFCSalesforce::Tools::Validation::Rule
112
+
113
+ def initialize(obj)
114
+ @rules = self.class.rules if self.class.is_a?(AFCSalesforce::Tools::Validation::Rule)
115
+ @obj = obj
116
+ end
117
+ end
118
+
119
+ # InvalidKey is raised if a rule is added to a field that doesn't exist
120
+ class InvalidKey < RuntimeError
121
+ end
122
+
123
+ # InvalidRule is raised if a rule is added that doesn't exist
124
+ class InvalidRule < RuntimeError
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,3 @@
1
+ module AFCSalesforce
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: afc_salesforce
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Donavan White
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_girl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: restforce
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.5'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.5.3
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '2.5'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.5.3
103
+ - !ruby/object:Gem::Dependency
104
+ name: json
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.7'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.7'
117
+ description: Ruby lib for handling the connection to REST endpoints on any Sandbox
118
+ and Production Salesforce
119
+ email:
120
+ - donavan.white@americanfinancing.net
121
+ executables: []
122
+ extensions: []
123
+ extra_rdoc_files: []
124
+ files:
125
+ - ".gitignore"
126
+ - ".rspec"
127
+ - ".travis.yml"
128
+ - CODE_OF_CONDUCT.md
129
+ - Gemfile
130
+ - README.md
131
+ - Rakefile
132
+ - afc_salesforce.gemspec
133
+ - bin/console
134
+ - bin/setup
135
+ - lib/afc_salesforce.rb
136
+ - lib/afc_salesforce/account.rb
137
+ - lib/afc_salesforce/additional_income.rb
138
+ - lib/afc_salesforce/ahc_realtor.rb
139
+ - lib/afc_salesforce/asset.rb
140
+ - lib/afc_salesforce/base.rb
141
+ - lib/afc_salesforce/borrower.rb
142
+ - lib/afc_salesforce/configuration.rb
143
+ - lib/afc_salesforce/forms/agent_referral.rb
144
+ - lib/afc_salesforce/forms/long_purchase.rb
145
+ - lib/afc_salesforce/forms/long_refinance.rb
146
+ - lib/afc_salesforce/forms/short_lead.rb
147
+ - lib/afc_salesforce/lead.rb
148
+ - lib/afc_salesforce/models/account.rb
149
+ - lib/afc_salesforce/models/ahc_realtor.rb
150
+ - lib/afc_salesforce/models/asset.rb
151
+ - lib/afc_salesforce/models/base.rb
152
+ - lib/afc_salesforce/models/concerns/type_setter.rb
153
+ - lib/afc_salesforce/models/contact.rb
154
+ - lib/afc_salesforce/models/income.rb
155
+ - lib/afc_salesforce/models/lead.rb
156
+ - lib/afc_salesforce/tools.rb
157
+ - lib/afc_salesforce/tools/utilities.rb
158
+ - lib/afc_salesforce/tools/validation.rb
159
+ - lib/afc_salesforce/tools/validation/rule/email.rb
160
+ - lib/afc_salesforce/tools/validation/rule/instance_of.rb
161
+ - lib/afc_salesforce/tools/validation/rule/length.rb
162
+ - lib/afc_salesforce/tools/validation/rule/matches.rb
163
+ - lib/afc_salesforce/tools/validation/rule/not_empty.rb
164
+ - lib/afc_salesforce/tools/validation/rule/not_nil.rb
165
+ - lib/afc_salesforce/tools/validation/rule/numeric.rb
166
+ - lib/afc_salesforce/tools/validation/rule/phone.rb
167
+ - lib/afc_salesforce/tools/validation/rule/regular_expression.rb
168
+ - lib/afc_salesforce/tools/validation/validator.rb
169
+ - lib/afc_salesforce/version.rb
170
+ homepage: https://www.americanfinancing.net
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.5.2
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Salesforce Library for the AFC Salesforce Instance
194
+ test_files: []