eco-helpers 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/eco-helpers.gemspec +0 -2
  3. data/lib/eco-helpers.rb +0 -1
  4. data/lib/eco/api/common/people/person_entry.rb +67 -30
  5. data/lib/eco/api/common/version_patches.rb +2 -1
  6. data/lib/eco/api/common/version_patches/base_model.rb +27 -0
  7. data/lib/eco/api/organization/people.rb +6 -0
  8. data/lib/eco/api/organization/tag_tree.rb +6 -0
  9. data/lib/eco/api/policies/policy.rb +2 -2
  10. data/lib/eco/api/session.rb +23 -30
  11. data/lib/eco/api/session/batch.rb +3 -2
  12. data/lib/eco/api/session/batch_job.rb +18 -10
  13. data/lib/eco/api/session/batch_status.rb +27 -11
  14. data/lib/eco/api/session/config.rb +20 -7
  15. data/lib/eco/api/usecases/default_cases/change_email_case.rb +2 -6
  16. data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +3 -2
  17. data/lib/eco/api/usecases/use_case.rb +6 -5
  18. data/lib/eco/api/usecases/use_case_chain.rb +3 -3
  19. data/lib/eco/api/usecases/use_case_io.rb +3 -3
  20. data/lib/eco/assets.rb +3 -1
  21. data/lib/eco/{common → assets}/language.rb +2 -2
  22. data/lib/eco/cli.rb +3 -4
  23. data/lib/eco/cli/config.rb +10 -0
  24. data/lib/eco/cli/config/options.rb +11 -0
  25. data/lib/eco/cli/scripting.rb +23 -0
  26. data/lib/eco/cli/scripting/args_helpers.rb +55 -0
  27. data/lib/eco/cli/scripting/argument.rb +31 -0
  28. data/lib/eco/cli/scripting/arguments.rb +70 -0
  29. data/lib/eco/common.rb +1 -3
  30. data/lib/eco/data/crypto/encryption.rb +2 -2
  31. data/lib/eco/language/models/collection.rb +1 -1
  32. data/lib/eco/version.rb +1 -1
  33. metadata +9 -62
  34. data/lib/eco/cli/api.rb +0 -14
  35. data/lib/eco/cli/root.rb +0 -9
  36. data/lib/eco/cli/session.rb +0 -9
  37. data/lib/eco/cli/session/batch.rb +0 -9
  38. data/lib/eco/common/base_cli.rb +0 -23
  39. data/lib/eco/common/base_cli_backup.rb +0 -120
  40. data/lib/eco/common/meta_thor.rb +0 -111
  41. data/lib/eco/common/meta_thor/command_group.rb +0 -36
  42. data/lib/eco/common/meta_thor/command_unit.rb +0 -48
  43. data/lib/eco/common/meta_thor/input_backup.rb +0 -111
  44. data/lib/eco/common/meta_thor/input_multi_backup.rb +0 -139
  45. data/lib/eco/common/meta_thor/pipe.rb +0 -85
  46. data/lib/eco/common/meta_thor/thor.rb +0 -1
  47. data/lib/eco/common/meta_thor/thor/command.rb +0 -36
  48. data/lib/eco/common/meta_thor/value.rb +0 -54
  49. data/lib/eco/scripting.rb +0 -32
  50. data/lib/eco/scripting/README.md +0 -11
  51. data/lib/eco/scripting/args_helpers.rb +0 -53
  52. data/lib/eco/scripting/argument.rb +0 -29
  53. data/lib/eco/scripting/arguments.rb +0 -68
@@ -0,0 +1,31 @@
1
+ module Eco
2
+ class CLI
3
+ class Scripting
4
+ class Argument
5
+
6
+ attr_reader :key
7
+
8
+ def initialize(key, with_param: false)
9
+ @key = key
10
+ @with_param = !!with_param
11
+ end
12
+
13
+ def args_slice(*args)
14
+ #pp "known arg '#{key}' => included? #{args.include?(key)}"
15
+ return args unless args.include?(key)
16
+ i = args.index(key)
17
+ j = with_param?? i+1 : i
18
+ args - args.slice(i..j)
19
+ end
20
+
21
+ def with_param!
22
+ @with_param = true
23
+ end
24
+
25
+ def with_param?
26
+ @with_param
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,70 @@
1
+ module Eco
2
+ class CLI
3
+ class Scripting
4
+ class Arguments
5
+ include Enumerable
6
+
7
+ attr_reader :args
8
+
9
+ def initialize(args = ARGV)
10
+ @args = args
11
+ @known = {}
12
+ end
13
+
14
+ def each(params: {}, &block)
15
+ return to_enum(:each) unless block
16
+ @known.values.each(&block)
17
+ end
18
+
19
+ def add(key, with_param: false)
20
+ self << Argument.new(key, with_param: with_param)
21
+ end
22
+
23
+ def <<(arg)
24
+ raise "Expected Argument. Given #{arg.class}" unless arg.is_a?(Argument)
25
+ if karg = @known[arg.key]
26
+ #puts "Found already existent option #{arg.key} (with_param: arg.with_param?)"
27
+ karg.with_param! if arg.with_param?
28
+ else
29
+ #puts "Adding unexistent option #{arg.key}"
30
+ @known[arg.key] = arg
31
+ end
32
+ self
33
+ end
34
+
35
+ def known?(value)
36
+ @known.key?(to_key(value))
37
+ end
38
+
39
+ def keys
40
+ @known.keys
41
+ end
42
+
43
+ def unknown(exclude: [])
44
+ reduce(args.dup - exclude) do |not_known, arg|
45
+ arg.args_slice(*not_known)
46
+ end
47
+ end
48
+
49
+ def any_unkown?(exclude: [])
50
+ unknown(exclude: exclude).length > 0
51
+ end
52
+
53
+ private
54
+
55
+ def to_key(value)
56
+ case value
57
+ when String
58
+ value
59
+ when Argument
60
+ value.key
61
+ else
62
+ "Missuse: only able to transform to key a String or an Argument. Given #{value.class}"
63
+ end
64
+ end
65
+
66
+
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/eco/common.rb CHANGED
@@ -3,6 +3,4 @@ module Eco
3
3
  end
4
4
  end
5
5
 
6
- require_relative 'common/meta_thor'
7
- require_relative 'common/base_cli'
8
- require_relative 'common/language'
6
+ #require_relative 'common/'
@@ -3,12 +3,12 @@ require 'json'
3
3
  require 'base64'
4
4
  require 'pp'
5
5
 
6
- require_relative '../../scripting'
6
+ require_relative '../../cli/scripting'
7
7
 
8
8
  # see some ramblings here: http://distributed-frostbite.blogspot.com/2010/06/file-encryption-in-ruby-with-openssl.html
9
9
 
10
10
  def run! # this will run only if called from command line (not when require'd nor load'd)
11
- include Eco::Scripting
11
+ include Eco::CLI::Scripting
12
12
  include Eco::Data::Crypto
13
13
  # script arguments
14
14
  keygen = get_arg("-keygen")
@@ -37,7 +37,7 @@ module Eco
37
37
 
38
38
  #attr_reader :items
39
39
 
40
- def initialize(data = [], klass:, factory: nil, handy: Eco::Common::Language.new)
40
+ def initialize(data = [], klass:, factory: nil, handy: Eco::Assets::Language.new)
41
41
  raise "Raise klass required, given: #{klass}" if !klass
42
42
  @klass = klass
43
43
  @factory = factory
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -118,46 +118,6 @@ dependencies:
118
118
  - - ">="
119
119
  - !ruby/object:Gem::Version
120
120
  version: 0.4.3
121
- - !ruby/object:Gem::Dependency
122
- name: thor
123
- requirement: !ruby/object:Gem::Requirement
124
- requirements:
125
- - - "~>"
126
- - !ruby/object:Gem::Version
127
- version: '0'
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: '0.20'
131
- type: :runtime
132
- prerelease: false
133
- version_requirements: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: '0.20'
141
- - !ruby/object:Gem::Dependency
142
- name: nokogiri
143
- requirement: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - "~>"
146
- - !ruby/object:Gem::Version
147
- version: '1.6'
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: 1.6.8
151
- type: :runtime
152
- prerelease: false
153
- version_requirements: !ruby/object:Gem::Requirement
154
- requirements:
155
- - - "~>"
156
- - !ruby/object:Gem::Version
157
- version: '1.6'
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: 1.6.8
161
121
  - !ruby/object:Gem::Dependency
162
122
  name: aws-sdk-s3
163
123
  requirement: !ruby/object:Gem::Requirement
@@ -299,6 +259,7 @@ files:
299
259
  - lib/eco/api/common/session/mailer.rb
300
260
  - lib/eco/api/common/session/s3_uploader.rb
301
261
  - lib/eco/api/common/version_patches.rb
262
+ - lib/eco/api/common/version_patches/base_model.rb
302
263
  - lib/eco/api/common/version_patches/external_person.rb
303
264
  - lib/eco/api/common/version_patches/internal_person.rb
304
265
  - lib/eco/api/eco_faker.rb
@@ -361,24 +322,15 @@ files:
361
322
  - lib/eco/api/usecases/use_case_io.rb
362
323
  - lib/eco/api/usecases/use_group.rb
363
324
  - lib/eco/assets.rb
325
+ - lib/eco/assets/language.rb
364
326
  - lib/eco/cli.rb
365
- - lib/eco/cli/api.rb
366
- - lib/eco/cli/root.rb
367
- - lib/eco/cli/session.rb
368
- - lib/eco/cli/session/batch.rb
327
+ - lib/eco/cli/config.rb
328
+ - lib/eco/cli/config/options.rb
329
+ - lib/eco/cli/scripting.rb
330
+ - lib/eco/cli/scripting/args_helpers.rb
331
+ - lib/eco/cli/scripting/argument.rb
332
+ - lib/eco/cli/scripting/arguments.rb
369
333
  - lib/eco/common.rb
370
- - lib/eco/common/base_cli.rb
371
- - lib/eco/common/base_cli_backup.rb
372
- - lib/eco/common/language.rb
373
- - lib/eco/common/meta_thor.rb
374
- - lib/eco/common/meta_thor/command_group.rb
375
- - lib/eco/common/meta_thor/command_unit.rb
376
- - lib/eco/common/meta_thor/input_backup.rb
377
- - lib/eco/common/meta_thor/input_multi_backup.rb
378
- - lib/eco/common/meta_thor/pipe.rb
379
- - lib/eco/common/meta_thor/thor.rb
380
- - lib/eco/common/meta_thor/thor/command.rb
381
- - lib/eco/common/meta_thor/value.rb
382
334
  - lib/eco/data.rb
383
335
  - lib/eco/data/crypto.rb
384
336
  - lib/eco/data/crypto/encryption.rb
@@ -403,11 +355,6 @@ files:
403
355
  - lib/eco/language/models/parser_serializer.rb
404
356
  - lib/eco/language/models/wrap.rb
405
357
  - lib/eco/language/values_at.rb
406
- - lib/eco/scripting.rb
407
- - lib/eco/scripting/README.md
408
- - lib/eco/scripting/args_helpers.rb
409
- - lib/eco/scripting/argument.rb
410
- - lib/eco/scripting/arguments.rb
411
358
  - lib/eco/tester.rb
412
359
  - lib/eco/version.rb
413
360
  homepage: https://www.ecoportal.com
data/lib/eco/cli/api.rb DELETED
@@ -1,14 +0,0 @@
1
- module Eco
2
- module CLI
3
- class API < Eco::Common::BaseCLI
4
- class_option :csv_in, :type => :string, :banner => "FILE", :desc => "CSV input file"
5
- class_option :csv_out, :type => :string, :banner => "FILE", :desc => "CSV output file"
6
- class_option :json_in, :type => :string, :banner => "FILE", :desc => "CSV input file"
7
- class_option :json_out, :type => :string, :banner => "FILE", :desc => "CSV input file"
8
-
9
- class_option :config_file, :aliases => "o", :type => :string,
10
- :banner => "FILE", :desc => "specifes the session configuration file"
11
- #class_option :csv_in, :alisaes =>
12
- end
13
- end
14
- end
data/lib/eco/cli/root.rb DELETED
@@ -1,9 +0,0 @@
1
- module Eco
2
- module CLI
3
- class Root < Eco::Common::BaseCLI
4
- class_option :config_file, :aliases => "o", :type => :string,
5
- :banner => "FILE", :desc => "specifes the session configuration file"
6
- #class_option :csv_in, :alisaes =>
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Eco
2
- module CLI
3
- class Session < Eco::Common::BaseCLI
4
-
5
- end
6
- end
7
- end
8
-
9
- require_relative 'session/batch'
@@ -1,9 +0,0 @@
1
- module Eco
2
- module CLI
3
- class Session
4
- class Batch < Eco::Common::BaseCLI
5
-
6
- end
7
- end
8
- end
9
- end
@@ -1,23 +0,0 @@
1
- module Eco
2
- module Common
3
- class BaseCLI < MetaThor
4
- CUSTOM_HELP_MAPPINGS = ["?", "help"]
5
- ALL_HELP_MAPPINGS = Thor::HELP_MAPPINGS + CUSTOM_HELP_MAPPINGS
6
-
7
- class_option :simulate, type: :boolean, aliases: :s, desc: "do not launch updates or rewrite files"
8
- #class_option :verbosity, type: :numeric, default: 0, desc: "defines the level of verbosity to show feedback"
9
-
10
- class << self
11
- def start(given_args = ARGV, config = {})
12
- super(given_args, config)
13
- end
14
- end
15
-
16
- protected
17
-
18
- no_commands do
19
- end
20
-
21
- end
22
- end
23
- end
@@ -1,120 +0,0 @@
1
- require 'thor'
2
-
3
- module Eco
4
- module Common
5
- class BaseCLI < MethaThor
6
- PIPE = "!"
7
- CUSTOM_HELP_MAPPINGS = ["?", "help"]
8
- ALL_HELP_MAPPINGS = Thor::HELP_MAPPINGS + CUSTOM_HELP_MAPPINGS
9
-
10
- class_option :simulate, type: :boolean, aliases: :s, desc: "do not launch updates or rewrite files"
11
- class_option :verbosity, type: :numeric, default: 0, desc: "defines the level of verbosity to show feedback"
12
-
13
- class_option :input, type: :hash, default: {json: nil}, required: false, desc: "--input=json:STRING"
14
- class_option :pipe, type: :boolean, default: false, required: false, desc: "--pipe subcommand"
15
-
16
- def self.start(given_args = ARGV, config = {})
17
- #given_args = splat_namespaces(given_args)
18
- given_args = BaseCLI.parse_help(given_args)
19
- super(given_args, config)
20
- end
21
-
22
- # incompatible with options / arguments of Hash type
23
- # see: parse_hash here: https://github.com/erikhuda/thor/blob/master/lib/thor/parser/arguments.rb
24
- def self.splat_namespaces(args)
25
- args.reduce([]) do |done, arg|
26
- done.concat(arg.split(":"))
27
- end
28
- end
29
-
30
- def self.parse_help(args)
31
- # Help enhancement. Adapted from: https://stackoverflow.com/a/49044225/4352306
32
- last = args.last
33
- if args.length > 1 && help?(last)
34
- # switch last and second last position
35
- last = "help" if custom_help?(last)
36
- args.insert(args.length - 2, last).pop
37
- puts "> #{args.join(" ")}"
38
- end
39
- args
40
- end
41
-
42
- def self.help?(value)
43
- case value
44
- when String
45
- ALL_HELP_MAPPINGS.include?(value)
46
- when Symbol
47
- help?(value.to_s)
48
- when Array
49
- value.any? { |v| help?(v) }
50
- when Hash
51
- value.keys.any { |k| help?(v) }
52
- end
53
- end
54
-
55
- def self.custom_help?(value)
56
- CUSTOM_HELP_MAPPINGS.include?(value)
57
- end
58
-
59
- protected
60
-
61
- no_commands do
62
- def input?(options)
63
- if options
64
- options.key?("input") || options.key?(:input) ||
65
- options.key?("json") || options.key?(:json)
66
- end
67
- end
68
-
69
- def input_object(input)
70
- Eco::CLI::Input.new(input)
71
- end
72
-
73
- def input(value)
74
- case
75
- when value.is_a?(Eco::CLI::Input)
76
- value.value
77
- when value.is_a?(Eco::CLI::MultiInput)
78
- value.to_h
79
- when value.is_a?(String)
80
- input(JSON.parse(value))
81
- when value&.key?("input")
82
- input(value["input"])
83
- when value&.key?(:input)
84
- input(value[:input])
85
- when value&.key?("json")
86
- JSON.parse(value["json"])
87
- when value&.key?(:json)
88
- JSON.parse(value[:json])
89
- end
90
- end
91
-
92
- def pipe(input, args)
93
- command, args, piped = parse_pipe(args)
94
- invoke command, args, {input: input_object(input)} if piped
95
- piped
96
- end
97
-
98
- def parse_pipe(args)
99
- args.shift if piped = (args.first == PIPE)
100
- subcommand = ""
101
- if piped
102
- raise "Error: bad usage of pipe ('#{PIPE}'). Expected: '#{PIPE} command' " unless subcommand = args.slice!(0)
103
- if help?(subcommand)
104
- # Idea adapted from: https://stackoverflow.com/a/46167300/4352306
105
- self.class.command_help(Thor::Base.shell.new, args.first)
106
- exit
107
- end
108
- end
109
- [subcommand, args, piped]
110
- end
111
-
112
- def help?(value)
113
- BaseCLI.help?(value)
114
- end
115
-
116
- end
117
-
118
- end
119
- end
120
- end