eco-helpers 3.0.7 → 3.0.8

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: b0fea8f72b2d0037d801b6150661827607326151c71b93df924d1f1271c17166
4
- data.tar.gz: d0059328bb938ace9e481a8023a4e5574f1e37e034220418e752c4647de4e382
3
+ metadata.gz: c5f99b7ad6dad2fcd262a6269bbe2c7a2acae695b077712ce745c9f0746e2580
4
+ data.tar.gz: de2217f416b703f1cc0ae06f6c42bddbebedef906013b128b5efcdc552df40af
5
5
  SHA512:
6
- metadata.gz: 01eb1d82295aa464cad0b5898e1fa3a295a7f01953f77b1591a2c1e96a96704f1bf82beb0b41b0ce6b6e0ed6eeea07568e029f2797b62d162dd541d93b37b9ed
7
- data.tar.gz: 21258ac597601cad5559f847f26defc78a564733b0e4ed4610d4f70b404cbf6977292a462040374f36706eb69cffabafa52179aa24531c23e29e10a53d9c539b
6
+ metadata.gz: 6149a32bf28606ac1051a127deabefd66fbab577700035f36ba01b9268438b1223423a30e399c1efaed92858586722a0dfa6d7d1a180a4ff0870c894ac730fde
7
+ data.tar.gz: 1799bbf948a1725f99b567b0934c29eb53f3361db5c22c660e616e876cc857c15c85330db3d2e60df4a6d5f1c0c9697722e1ded6b114897cbe8b5a257fd06511
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [3.0.8] - 2024-08-xx
5
+ ## [3.0.9] - 2024-08-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,22 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [3.0.8] - 2024-08-30
14
+
15
+ ### Added
16
+
17
+ - options to choose `-batch-mode` [`:batch`|`:job`]
18
+
19
+ ### Changed
20
+
21
+ - When `-skip-api-policies`
22
+ - Default policy: to skip non generic logic when api policies are skept
23
+ - Still run default policies
24
+
25
+ ### Fixed
26
+
27
+ - unknown option `suggestions`
28
+
13
29
  ## [3.0.7] - 2024-08-27
14
30
 
15
31
  ### Added
data/Rakefile CHANGED
@@ -19,6 +19,11 @@ RSpec::Core::RakeTask.new(:spec_fast) do |task|
19
19
  end
20
20
  task(rspec_fast: :spec_fast)
21
21
 
22
+ desc "run rubocop diaplying cop names"
23
+ RuboCop::RakeTask.new(:rubocop) do |t|
24
+ t.options = ['--display-cop-names']
25
+ end
26
+
22
27
  # default task name is yard
23
28
  desc "Yard: generate all the documentation"
24
29
  YARD::Rake::YardocTask.new(:doc) do |t|
data/eco-helpers.gemspec CHANGED
@@ -1,3 +1,4 @@
1
+ # rubocop:disable Gemspec/DevelopmentDependencies
1
2
  lib = File.expand_path('lib', __dir__)
2
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
 
@@ -54,3 +55,5 @@ Gem::Specification.new do |spec|
54
55
  spec.add_dependency 'roo-xls', '>= 1.2.0', '< 1.3'
55
56
  spec.add_dependency 'rubyzip', '>= 2.3.2', '< 2.4'
56
57
  end
58
+
59
+ # rubocop:enable Gemspec/DevelopmentDependencies
@@ -14,8 +14,10 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
14
14
  self.account_removed_count = 0
15
15
 
16
16
  people.each do |person|
17
- remove_account_when_no_email!(person) if person.email.to_s.empty?
18
- next unless account = person.account
17
+ remove_account_when_no_email!(person)
18
+
19
+ next if options.dig(:skip, :api_policies)
20
+ next unless (account = person.account)
19
21
  next if options.dig(:exclude, :account)
20
22
 
21
23
  add_def_policy_group_if_applicable!(account)
@@ -35,6 +37,7 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
35
37
  end
36
38
 
37
39
  def remove_account_when_no_email!(person)
40
+ return unless person.email.to_s.empty?
38
41
  return unless person.account
39
42
 
40
43
  self.account_removed_count += 1 if had_account?(person)
@@ -15,8 +15,10 @@ module Eco
15
15
  end
16
16
 
17
17
  def add(policy)
18
- raise "Expected Eco::API::Policies::Policy object. Given: #{policy}" unless policy.is_a?(Eco::API::Policies::Policy)
19
- super(policy)
18
+ msg = "Expected Eco::API::Policies::Policy object. Given: #{policy}"
19
+ raise ArgumentError, msg unless policy.is_a?(Eco::API::Policies::Policy)
20
+
21
+ super
20
22
  end
21
23
 
22
24
  def launch(people:, session:, job:, options: {})
@@ -350,9 +350,12 @@ module Eco
350
350
  # Applies the changes introduced by api policies
351
351
  def apply_policies(pre_queue)
352
352
  people(pre_queue).tap do |entries|
353
- next if options.dig(:skip, :api_policies)
353
+ if options.dig(:skip, :api_policies)
354
+ policies = session.default_policies
355
+ else
356
+ policies = session.policies
357
+ end
354
358
 
355
- policies = session.policies
356
359
  next if policies.empty?
357
360
 
358
361
  policies.launch(
@@ -12,6 +12,16 @@ module Eco
12
12
  end
13
13
  end
14
14
 
15
+ # @return [Symbol] the batch mode to run
16
+ def batch_mode(opts = self.options)
17
+ opts.dig(:workflow, :batch, :mode) || :batch
18
+ end
19
+
20
+ # @return [Boolean] are we running in `:job` mode?
21
+ def job_mode?(opts = self.options)
22
+ batch_mode(opts) == :job
23
+ end
24
+
15
25
  # Gets the _people_ of the organization according `params`.
16
26
  # If `people` is not `nil`, scopes to only the people specified.
17
27
  # @note
@@ -113,6 +123,11 @@ module Eco
113
123
  )
114
124
  end
115
125
 
126
+ # Default way to retrieve options (unless provided)
127
+ def options
128
+ ASSETS.cli.options
129
+ end
130
+
116
131
  def launch_batch( # rubocop:disable Metrics/AbcSize
117
132
  data,
118
133
  method:,
@@ -120,7 +135,8 @@ module Eco
120
135
  job_mode: true, # rubocop:disable Lint/UnusedMethodArgument
121
136
  per_page: DEFAULT_BATCH_BLOCK,
122
137
  people_api: api&.people,
123
- silent: false
138
+ silent: false,
139
+ options: self.options
124
140
  )
125
141
  iteration = 1
126
142
  done = 0
@@ -145,7 +161,7 @@ module Eco
145
161
 
146
162
  start_slice = Time.now
147
163
  offer_retry_on(Ecoportal::API::Errors::TimeOut) do
148
- people_api.batch(job_mode: false) do |batch|
164
+ people_api.batch(job_mode: job_mode?(options)) do |batch|
149
165
  slice.each do |person|
150
166
  batch.public_send(method, person) do |response|
151
167
  faltal("Request with no response") unless response
@@ -365,6 +365,7 @@ module Eco
365
365
  # @return [Eco::API::Policies]
366
366
  def policies
367
367
  @policies = self["policies"] ||= Eco::API::Policies.new
368
+
368
369
  if block_given?
369
370
  yield(@policies)
370
371
  self
@@ -252,11 +252,15 @@ module Eco
252
252
  # @return [Eco::API::Policies]
253
253
  def policies
254
254
  @policies ||= config.policies.dup.tap do |policies|
255
- default_policies = Eco::API::Policies::DefaultPolicies.new
256
255
  policies.merge(default_policies)
257
256
  end
258
257
  end
259
258
 
259
+ # The native policies
260
+ def default_policies
261
+ @default_policies ||= Eco::API::Policies::DefaultPolicies.new
262
+ end
263
+
260
264
  # Set of helpers to simplify your code
261
265
  # @see Eco::API::MicroCases
262
266
  # @return [Eco::API::MicroCases]
data/lib/eco/assets.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Eco
2
2
  class Assets
3
-
4
3
  attr_reader :active_config
5
4
 
6
5
  def initialize
@@ -17,10 +16,12 @@ module Eco
17
16
 
18
17
  def config(key: active_config, update_active: true)
19
18
  configs[:default] ||= Eco::API::Session::Config.new(key)
19
+
20
20
  unless configs.key?(key)
21
- @active_config = key unless !update_active
21
+ @active_config = key if update_active
22
22
  configs[key] = configs[:default].clone(key)
23
23
  end
24
+
24
25
  configs[key].tap do |config|
25
26
  config.active_api(key) if config.apis.defined?(key)
26
27
  yield(config) if block_given?
@@ -36,6 +37,7 @@ module Eco
36
37
  @cli_init = true
37
38
  require_relative('cli_default')
38
39
  end
40
+
39
41
  @cli.tap { yield(@cli) if block_given? }
40
42
  end
41
43
  end
@@ -2,6 +2,8 @@ module Eco
2
2
  class CLI
3
3
  class Scripting
4
4
  module ArgsHelpers
5
+ class UnknownArgument < ArgumentError; end
6
+
5
7
  # @return [Array<String] the command line arguments.
6
8
  def argv
7
9
  @argv || ARGV
@@ -31,7 +33,8 @@ module Eco
31
33
  }
32
34
  unknown = arguments.unknown(**args) do |key, correct|
33
35
  next suggestions[key] = correct unless correct.empty?
34
- suggstions[key] = '-- not known similar options! --'
36
+
37
+ suggestions[key] = ['-- not known similar options! --']
35
38
  end
36
39
  unknown = unknown.select {|arg| is_modifier?(arg)} if only_options
37
40
 
@@ -49,7 +52,7 @@ module Eco
49
52
  msg << "\nUse 'ruby main.rb -org [-usecase] --help -options' for more information"
50
53
  msg << "\n - Please, remember that use case specific options "
51
54
  msg << "should come after the use case in the command line.\n"
52
- raise msg
55
+ raise UnknownArgument, msg
53
56
  end
54
57
 
55
58
  # @return [Boolean] if `key` is in the command line.
@@ -27,7 +27,7 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
27
27
  puts conf.usecases.help(refine: huc)
28
28
  end
29
29
 
30
- puts [
30
+ help_str = [
31
31
  "Please specify one of the below:",
32
32
  " -filters to display available filters on people",
33
33
  " -input-filters to display available filters on input data",
@@ -36,7 +36,9 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
36
36
  "TIPS:",
37
37
  " * You may specify the usecase to know its specific options by: -usecase_name --help -options",
38
38
  " * You may specify a refinement to show specific information only: --help -usecases tags"
39
- ].join("\n") unless hpf || hif || ho || huc
39
+ ].join("\n")
40
+
41
+ puts help_str unless hpf || hif || ho || huc
40
42
  exit
41
43
  end
42
44
 
@@ -151,6 +153,26 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
151
153
  session.config.dry_run!
152
154
  end
153
155
 
156
+ desc = "It specifies the type of batch to be used (default: ':batch')"
157
+ options_set.add("-batch-mode", desc) do |options, session|
158
+ mode_in = SCR.get_arg("-batch-mode", with_param: true)
159
+ mode_str = mode_in.to_s.downcase
160
+ mode_sym = %i[batch job].find do |md|
161
+ next true if md.to_s == mode_str
162
+
163
+ md.to_s == mode_str.gsub(':', '')
164
+ end
165
+
166
+ unless mode_sym
167
+ session.log(:warn) {
168
+ "Unknown job_mode: #{mode_in}. Switching to default: ':batch'"
169
+ }
170
+ mode_sym = :batch
171
+ end
172
+
173
+ options.deep_merge!(workflow: {batch: {mode: mode_sym}})
174
+ end
175
+
154
176
  desc = "Runs runs post_launch cases even if in dry-run"
155
177
  options_set.add("-run-postlaunch", desc) do |options, session|
156
178
  options.deep_merge!(post_launch: {run: true})
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = '3.0.7'.freeze
2
+ VERSION = '3.0.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.7
4
+ version: 3.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-26 00:00:00.000000000 Z
11
+ date: 2024-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -922,7 +922,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
922
922
  - !ruby/object:Gem::Version
923
923
  version: '0'
924
924
  requirements: []
925
- rubygems_version: 3.5.6
925
+ rubygems_version: 3.5.18
926
926
  signing_key:
927
927
  specification_version: 4
928
928
  summary: eco-helpers to manage people api cases