leap_salesforce 0.2.12 → 0.2.13

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
  SHA256:
3
- metadata.gz: cf476f468493821057b919e67cec01450df2e4776edeae3cf94ddccaac1d1539
4
- data.tar.gz: '0364379e8b68a5873451b01411ae32346468e651729f8b6e883ca9393fb4b156'
3
+ metadata.gz: b3feb0e688629698af297a150795edc17670b52fdfc8660f8b2bd61c8459b69c
4
+ data.tar.gz: fcb2b17118935240b16cab2411396d1fef974f6d8a1bc8d8bc78939a10ed904f
5
5
  SHA512:
6
- metadata.gz: feb85dd56212f73a939b83f3e5bd0c6c92ad366580b986b24e55acfeb01ab476fca9c9547bf0cb002dea17c1d430520913357274b37ff33ec05110990f306a55
7
- data.tar.gz: 2ac29878de67c8f57b03025f901dd09bf53556eb1493c120b53a3e8466c55fa5dcaeee7111b58464a3b07150a8d92b2aa5bdd1a9ecc256095965a704e3757cb2
6
+ metadata.gz: 921f6485c50ed5afcc6a1f85e28ef135beac369d1deb7f7ed67e21cf2cab551bd59b23033dc4864b2db46228fcbb44e2eee73949bb5ff84600b9ba1d395fdd45
7
+ data.tar.gz: 28c1803bc0e76cb8b333fdfbc898f24c26887d228a2a3f39c29f5d0d24d493dd3e99a48b89f9f805d70d4a1ab3a16df121912a2867921495e835920107c22681
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ Version 0.2.13
2
+ * Enhancement
3
+ * 'Leaps::User'
4
+ * Method to extract actual information regarding user, having accessor
5
+ for first name
6
+ * 'each' method to iterate over all/subset of users
7
+
1
8
  Version 0.2.12
2
9
  * Enhancement
3
10
  * Made optional alias 'Leaps' as shorter form of LeapSalesforce
@@ -22,17 +22,20 @@ module LeapSalesforce
22
22
  self.description = description
23
23
  end
24
24
 
25
+ # @return [User] Salesforce soql object for User
26
+ def soql_object
27
+ admin_query_user { ::User.find username: username }
28
+ end
29
+
30
+ # @return [String] First name of user
31
+ def first_name
32
+ admin_query_user { soql_object.first_name }
33
+ end
34
+
25
35
  # Query for user in Salesforce instance
26
36
  # @return [Boolean] Whether Salesforce user exists in environment running against
27
37
  def exists?
28
- if defined? ::User
29
- Users.execute_as_if_present key: :admin do
30
- ::User.any?(username: username)
31
- end
32
- else
33
- raise LeapSalesforce::SetupError, "'User' class must be defined " \
34
- " to check presence of user in environment #{LeapSalesforce.environment}"
35
- end
38
+ admin_query_user { ::User.any?(username: username) }
36
39
  end
37
40
 
38
41
  # @return [String] Username of User interpreted by ERB (in email address format).
@@ -52,5 +55,19 @@ module LeapSalesforce
52
55
  actual_value == criteria
53
56
  end
54
57
  end
58
+
59
+ private
60
+
61
+ # Execute block as admin user, raising error if User class is not defined
62
+ def admin_query_user
63
+ if defined? ::User
64
+ Users.execute_as_if_present key: :admin do
65
+ yield
66
+ end
67
+ else
68
+ raise LeapSalesforce::SetupError, "'User' class must be defined " \
69
+ " to check presence of user in environment #{LeapSalesforce.environment}"
70
+ end
71
+ end
55
72
  end
56
73
  end
@@ -22,29 +22,41 @@ module LeapSalesforce
22
22
  @list << User.new(*user)
23
23
  end
24
24
 
25
- # @return [LeapSalesforce::User] A user that meets the criteria
26
- def where(filter)
25
+ # @param [Symbol, Hash, String, Regexp, LeapSalesforce::User] filter Filter to find users by
26
+ # @param [Boolean] all Whether to return all users matching criteria, not just first
27
+ # @return [LeapSalesforce::User, Array] A user that meets the criteria
28
+ def where(filter, all: false)
29
+ @all = all
27
30
  case filter
28
31
  when :default then list.first # Will then use first user defined
29
32
  when Hash then match_params filter
30
33
  when String then match_params(username: filter)
31
34
  when Symbol then match_params(key: filter)
32
35
  when Regexp then match_params(description: filter)
33
- when LeapSalesforce::User then filter
36
+ when User then filter
34
37
  else
35
- raise "Unable to find user using class #{filter.class}"
38
+ raise UserError, "Unable to find user using class #{filter.class}"
36
39
  end
37
40
  end
38
41
 
39
- # @return [LeapSalesforce::User] A user that meets the criteria
42
+ # Iterate through each user, narrowing on filter if provided
43
+ def each(filter = nil)
44
+ if filter
45
+ where(filter, all: true).each { yield }
46
+ else
47
+ list.each { yield }
48
+ end
49
+ end
50
+
51
+ # @return [LeapSalesforce::User, Array] A user that meets the criteria
40
52
  def match_params(hash_filter)
41
53
  lookup_key, lookup_value = hash_filter.first
42
- user = list.find { |user_queried| user_queried.match?(lookup_key, lookup_value) }
43
- unless user
54
+ users = list.find_all { |user_queried| user_queried.match?(lookup_key, lookup_value) }
55
+ if users.empty?
44
56
  raise UserError, "Unable to find user based on filer #{hash_filter}. " \
45
57
  "Users are: #{list}"
46
58
  end
47
- user
59
+ @all ? users : users.first
48
60
  end
49
61
 
50
62
  # Execute block as user matching filter if that user is present
@@ -2,5 +2,5 @@
2
2
 
3
3
  module LeapSalesforce
4
4
  # @return [String] Version of leap salesforce
5
- VERSION = '0.2.12'
5
+ VERSION = '0.2.13'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leap_salesforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - IQA
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-10-31 00:00:00.000000000 Z
12
+ date: 2019-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler