sf_cli 1.2.1 → 1.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6cc1ab1222fe6f4c19b78853eed5a06c7e7f9047146b5f59a08a888fb369a54
4
- data.tar.gz: f73f3784ed62def6460450fc6780f13fae73ae5d64ee7652b60379d50fcbc3e5
3
+ metadata.gz: f20d5801d3a2c887f01fa3fb3ab8775153d78b27d760ac2c6b148dac749a4945
4
+ data.tar.gz: 9295c01a6eab70749c2a0367a99d29f90ac3e7dafd65c49315ac521820362506
5
5
  SHA512:
6
- metadata.gz: 80a77af9028ef5fed8b195d79356c0df6fc3b304a5eab26b8d094333d9148097cabb51b21592091815dc1ae0b768a3f1dbd35b88d01921d02986e5ee9b43add4
7
- data.tar.gz: 1dbc012a4c8b0895f00ac1f741c1262d6b7319de72c08ef5d92f61204acdbb4f052755dd596883a989addaae35589039623d3d82ca9eace7a3ca97ae38a8e291
6
+ metadata.gz: 31b95e54526b884b83e19e6b870b99b148114b99692b92e4c01ea092a9068d4e779d708beba850fd60471bf44821ffcf859a00e094573e7ea8e2b70b46a341f9
7
+ data.tar.gz: 68637d5bd35140a9dc851176e9e22ae341c8c1029d451f63dfc0d076d5ea103f50b6f743d2c98743d121277b59cbb335933e6f98f74484509c1fe74bd02ed33b
@@ -1,5 +1,6 @@
1
1
  require 'sf_cli'
2
2
  require 'sf_cli/sf/model'
3
+ require 'sf_cli/sf/model/query_condition'
3
4
  require 'sf_cli/sf/model/sf_command_connection'
4
5
  require 'stringio'
5
6
 
@@ -48,7 +49,8 @@ module SfCli
48
49
  sf.apex.run target_org: target_org, file: StringIO.new(apex_code)
49
50
  end
50
51
 
51
- def query(soql)
52
+ def query(_soql)
53
+ soql = _soql.is_a?(SfCli::Sf::Model::QueryMethods::QueryCondition) ? _soql.to_soql : _soql
52
54
  conf.inspect_mode = false
53
55
  puts sf.data.query(soql, format: :human, target_org: target_org)
54
56
  conf.inspect_mode = true
@@ -17,6 +17,10 @@ module SfCli::Sf::Data
17
17
  # @example
18
18
  # sf.data.query 'SELECT Id, Name FROM Account LIMIT 1' # => [{Id: "abc", Name: "account name"}]
19
19
  #
20
+ # accounts = sf.data.query('SELECT Id, Name From Account') do |record|
21
+ # record['Name'] += " Changed!" # can manipulate the record in block
22
+ # end
23
+ #
20
24
  # Account = Struct.new(:Id, :Name)
21
25
  # sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account struct object
22
26
  #
@@ -39,7 +43,7 @@ module SfCli::Sf::Data
39
43
  #
40
44
  # @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_query_unified command reference
41
45
  #
42
- def query(soql, target_org: nil, format: nil, bulk: false, wait: nil, api_version: nil, model_class: nil)
46
+ def query(soql, target_org: nil, format: nil, bulk: false, wait: nil, api_version: nil, model_class: nil, &block)
43
47
  flags = {
44
48
  :"query" => %("#{soql}"),
45
49
  :"target-org" => target_org,
@@ -53,9 +57,15 @@ module SfCli::Sf::Data
53
57
  raw_output = format ? true : false
54
58
  format = format&.to_sym || :json
55
59
 
56
- result = exec(__method__, flags: flags, switches: switches, redirection: :null_stderr, raw_output: raw_output, format: format)
60
+ exec_result = exec(__method__, flags: flags, switches: switches, redirection: :null_stderr, raw_output: raw_output, format: format)
61
+
62
+ results = return_result(exec_result, raw_output, bulk, model_class)
63
+
64
+ return results if raw_output
65
+
66
+ results.each(&block) if block_given?
57
67
 
58
- return_result(result, raw_output, bulk, model_class)
68
+ results
59
69
  end
60
70
 
61
71
  # Resume a bulk query job, which you previously started, and get records
@@ -12,17 +12,28 @@ module SfCli
12
12
  end
13
13
 
14
14
  def generate(object_name)
15
+ return false if generated? object_name
16
+
15
17
  schema = describe(object_name)
16
18
  class_definition = ClassDefinition.new(schema)
17
19
 
18
20
  instance_eval "::#{object_name} = #{class_definition}"
19
21
  klass = Object.const_get object_name.to_sym
20
22
  klass.connection = connection
23
+
24
+ true
21
25
  end
22
26
 
23
27
  def describe(object_name)
24
28
  connection.describe object_name
25
29
  end
30
+
31
+ def generated?(object_name)
32
+ Object.const_get object_name.to_sym
33
+ true
34
+ rescue NameError
35
+ false
36
+ end
26
37
  end
27
38
  end
28
39
  end
@@ -40,7 +40,7 @@ module SfCli
40
40
  def not(*expr)
41
41
  return self unless valid_expr?(expr)
42
42
 
43
- conditions.append %|NOT(#{to_string_expr(expr)})|
43
+ conditions.append %|(NOT(#{to_string_expr(expr)}))|
44
44
  self
45
45
  end
46
46
 
@@ -132,6 +132,8 @@ module SfCli
132
132
  %|'#{expr[2]}'|
133
133
  when :Time
134
134
  expr[2].to_datetime
135
+ when :NilClass
136
+ :null
135
137
  when :Array
136
138
  candidates = expr[2].map do |o|
137
139
  case o.class.name.to_sym
@@ -139,11 +141,13 @@ module SfCli
139
141
  %|'#{o}'|
140
142
  when :Time
141
143
  o.to_datetime
144
+ when :NilClass
145
+ :null
142
146
  else
143
147
  o
144
148
  end
145
149
  end
146
- %|IN (#{candidates.join(', ')})|
150
+ %|(#{candidates.join(', ')})|
147
151
  else
148
152
  expr[2]
149
153
  end
@@ -165,6 +169,8 @@ module SfCli
165
169
  %|#{k} = '#{v}'|
166
170
  when :Time
167
171
  %|#{k} = #{v.to_datetime}|
172
+ when :NilClass
173
+ %|#{k} = null|
168
174
  when :Array
169
175
  candidates = v.map do |o|
170
176
  case o.class.name.to_sym
@@ -172,6 +178,8 @@ module SfCli
172
178
  %|'#{o}'|
173
179
  when :Time
174
180
  %|#{o.to_datetime}|
181
+ when :NilClass
182
+ :null
175
183
  else
176
184
  o
177
185
  end
@@ -19,23 +19,29 @@ module SfCli
19
19
  end
20
20
 
21
21
  def field_names
22
- @field_names ||= fields.map{|f| f.name.to_sym}
22
+ @field_names ||= fields.map{|f| f.name.to_sym}.sort
23
23
  end
24
24
 
25
25
  def field_labels
26
- @field_labels ||= fields.map{|f| f.label}
26
+ @field_labels ||= fields.map{|f| f.label}.sort
27
27
  end
28
28
 
29
29
  def children_relations
30
- schema['childRelationships']
31
- .select{|r| r['relationshipName'].nil? == false}
32
- .map{|r| {name: r['relationshipName'].to_sym, field: r['field'].to_sym, class_name: r['childSObject'].to_sym}}
30
+ @children_relations ||=
31
+ schema['childRelationships']
32
+ .select{|r| r['relationshipName'].nil? == false}
33
+ .map{|r| {name: r['relationshipName'].to_sym, field: r['field'].to_sym, class_name: r['childSObject'].to_sym}}
33
34
  end
34
35
 
35
36
  def parent_relations
36
- fields
37
- .select{|f| !(f.relationship_name.nil? || f.reference_to.nil?) && f.reference_to.size > 0}
38
- .map{|f| {name: f.relationship_name.to_sym, field: f.name.to_sym, class_name: f.reference_to.first.to_sym} }
37
+ @parent_relations ||=
38
+ fields
39
+ .select{|f| !(f.relationship_name.nil? || f.reference_to.nil?) && f.reference_to.size > 0}
40
+ .map{|f| {name: f.relationship_name.to_sym, field: f.name.to_sym, class_name: f.reference_to.first.to_sym} }
41
+ end
42
+
43
+ def relations
44
+ @relations ||= Relations.new(children_relations + parent_relations)
39
45
  end
40
46
 
41
47
  def to_h
@@ -212,6 +218,35 @@ module SfCli
212
218
  @schema
213
219
  end
214
220
 
221
+ Relation = Struct.new(:name, :field, :class_name)
222
+
223
+ class Relations
224
+ include Enumerable
225
+
226
+ def initialize(relations)
227
+ @relations = relations.map{|r| Relation.new(name: r[:name], field: r[:field], class_name: r[:class_name])}
228
+ end
229
+
230
+ def each(&block)
231
+ relations.each(&block)
232
+ end
233
+
234
+ def names
235
+ map(&:name).sort
236
+ end
237
+
238
+ def find(name)
239
+ relations.find{|r| r.name == name.to_sym}
240
+ end
241
+
242
+ private
243
+
244
+ def relations
245
+ @relations
246
+ end
247
+ end
248
+
249
+
215
250
  class Fields
216
251
  include Enumerable
217
252
 
@@ -235,7 +270,7 @@ module SfCli
235
270
 
236
271
  find do |field|
237
272
  attr_val = field.__send__(attr_name.to_sym)
238
- attr_val == val
273
+ attr_val == val.to_s
239
274
  end
240
275
  end
241
276
 
@@ -1,3 +1,3 @@
1
1
  module SfCli
2
- VERSION = '1.2.1'
2
+ VERSION = '1.2.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sf_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takanobu Maekawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-04 00:00:00.000000000 Z
11
+ date: 2024-10-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A class library for introducing Salesforce CLI to Ruby scripting. Currenty
14
14
  only sf command is the target of development.