active_force 0.0.6.alfa → 0.0.7.alfa

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbd6c1f543bc1665eb9bae1a0b884d27b1731fee
4
- data.tar.gz: 9b0e307c8db0dde5789a560005e87fa8d05f9fac
3
+ metadata.gz: c7c95ee692d2b9302abc561d8b75abb46471cb3e
4
+ data.tar.gz: 57cf7fbe1dabbddcba08399cf23aa7e21ec0d80d
5
5
  SHA512:
6
- metadata.gz: f52aa5a3b15ff6021d0257995fb88c4ec8a9cc9b0a1e7d57cbd64780b76b1fac5c5dcc661b395d272cc6ea4414b2a8ca9ea806b0decc9af2c46153a43e21b2e7
7
- data.tar.gz: 6cd0303531137db2fc3674c8a3e79ec192bde1f111be3a443c57337f1c4a35abdbcb8dd6b0dc60ef395d50afe2bc8604c5c540eaaec73e56b150003d53c15869
6
+ metadata.gz: 04ee4308094ca54cf96a9a9f940a2512598c9bde125ac79ad78ed3168aeb9e3106ad9b4236b02ed8d527102a677897b8fba73e49b349eaa2dd40d961d4a519bf
7
+ data.tar.gz: fa2590afa762d3c94e8b53197f5168dcd95b4560a364e64425e6280563b174e2d60655404d28c851d95dd529040894bf628e883a6735e76e1970eaf5f7c6c7a0
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
- ## 0.0.6.alfa ##
1
+ # 0.0.7.alfa #
2
2
 
3
- * ActiveForce::SObject#table_name is auto populated using the class
3
+ * Use simpler error messages.
4
+ * Implement .all and .create methods (copying ActiveRecord Interface)
5
+ * Add SObject.all method.
6
+ * Add basic support for multi-picklists.
7
+
8
+ # 0.0.6.alfa #
9
+
10
+ * ActiveForce::SObject#table_name is auto populated using the class
4
11
  name. It adds "__c" to all non standard types.
data/active_force.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'active_force/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "active_force"
8
8
  spec.version = ActiveForce::VERSION
9
- spec.authors = ["Eloy Espinaco"]
10
- spec.email = ["eloyesp@gmail.com"]
9
+ spec.authors = ["Eloy Espinaco", "Pablo Oldani"]
10
+ spec.email = "eloyesp@gmail.com"
11
11
  spec.description = %q{Use SalesForce as an ActiveModel}
12
12
  spec.summary = %q{Help you implement models persisting on Sales Force within Rails using RESTForce}
13
13
  spec.homepage = ""
@@ -32,6 +32,18 @@ module ActiveForce
32
32
  model
33
33
  end
34
34
 
35
+ def self.all
36
+ all = Client.query(<<-SOQL.strip_heredoc).to_a
37
+ SELECT
38
+ #{ fields.join(', ') }
39
+ FROM
40
+ #{ table_name }
41
+ SOQL
42
+ all.map do |mash|
43
+ build mash
44
+ end
45
+ end
46
+
35
47
  def self.find id
36
48
  build Client.query(<<-SOQL.strip_heredoc).first
37
49
  SELECT #{fields.join(', ')}
@@ -40,11 +52,21 @@ module ActiveForce
40
52
  SOQL
41
53
  end
42
54
 
55
+ def self.create(attributes = nil, &block)
56
+ if attributes.is_a?(Array)
57
+ attributes.collect { |attr| create(attr, &block) }
58
+ else
59
+ object = new(attributes, &block)
60
+ object.create
61
+ object
62
+ end
63
+ end
64
+
43
65
  def create
44
66
  return false unless valid?
45
67
  hash = {}
46
68
  mappings.map do |field, name_in_sfdc|
47
- value = attribute(field.to_s)
69
+ value = read_value field
48
70
  hash[name_in_sfdc] = value if value.present?
49
71
  end
50
72
  self.id = Client.create! table_name, hash
@@ -53,7 +75,7 @@ module ActiveForce
53
75
  Rails.logger.warn do
54
76
  "[SFDC] [#{self.class.model_name}] [#{self.class.table_name}] Error while creating, params: #{hash}, error: #{error.inspect}"
55
77
  end
56
- errors[:base] << "Error when creating the #{self.class.model_name}"
78
+ errors[:base] << error.message
57
79
  false
58
80
  end
59
81
 
@@ -80,13 +102,29 @@ module ActiveForce
80
102
  id?
81
103
  end
82
104
 
83
- def self.field field_name, from: field_name.camelize
105
+ def self.field field_name, from: field_name.camelize, as: :string
84
106
  mappings[field_name] = from
85
- attribute field_name
107
+ attribute field_name, sf_type: as
86
108
  end
87
109
 
88
110
  def self.mappings
89
111
  @mappings ||= {}
90
112
  end
113
+
114
+ private
115
+ def read_value field
116
+ if self.class.attributes[field][:sf_type] == :multi_picklist
117
+ attribute(field.to_s).reject(&:empty?).join(';')
118
+ else
119
+ attribute(field.to_s)
120
+ end
121
+ end
122
+
123
+ def self.picklist field
124
+ picks = Client.picklist_values(table_name, mappings[field])
125
+ picks.map do |value|
126
+ [value[:label], value[:value]]
127
+ end
128
+ end
91
129
  end
92
130
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveForce
2
- VERSION = "0.0.6.alfa"
2
+ VERSION = "0.0.7.alfa"
3
3
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_force
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6.alfa
4
+ version: 0.0.7.alfa
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Espinaco
8
+ - Pablo Oldani
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-08-27 00:00:00.000000000 Z
12
+ date: 2013-10-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: active_attr
@@ -95,8 +96,7 @@ dependencies:
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  description: Use SalesForce as an ActiveModel
98
- email:
99
- - eloyesp@gmail.com
99
+ email: eloyesp@gmail.com
100
100
  executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []