eco-helpers 1.0.8 → 1.0.9

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: f9831e1570b2ad8b1dd11128af4bf1c141dd76ead7e7d7c9fa315c089e25a866
4
- data.tar.gz: 0e328fe606aa425c68ef609c7385fe9d62500ac020769bd78a8840f5dce915fd
3
+ metadata.gz: f2cc1dbfbff9d516658984913b6c550a5c5eba25134c2fd58252dc6ce6ca4a18
4
+ data.tar.gz: 6a9af3f7c3d8bbac1cf66c37bf5e563e2b899f63275187dc1caf0a7985ab09f3
5
5
  SHA512:
6
- metadata.gz: 76fdbb40780576960262ee427d3ec563e72da484e398f0593811d5fd773f8ec31e07ae2183d58f6a6a26fa3fb135ccb4d5515113868b49fcb182ba06a35c3a40
7
- data.tar.gz: 7853f924a6b514f476c7470c6748a9bf47137ecd68b2b1541cb52d600eb6692091705e7be23cdfdb9bedb339c6c0d1812d5000bb3771804bae65d566c3eb027e
6
+ metadata.gz: c749092b76b38487931672d4fcf38cdfbcbfc3c92445c23587c53a086c02113e3f1b65e2ecacfe3d53f231014437e0e0f93b58acf0701ebf2adc661d68eb0855
7
+ data.tar.gz: f8bc01d6781aeb0791b95015206844513d91356bf981828691f841175af225c829f3a82bd85bc9a92af54993be26218a36f41435431d8622a93f598a62cf7561
@@ -15,6 +15,7 @@ module Eco
15
15
  # Select Options
16
16
  select_hashes = @schema.fields.map do |fld|
17
17
  if fld.type == "select"
18
+ raise "The schema selection field '#{fld.name}' is missing selection options." unless fld.options && !fld.options.empty?
18
19
  options_hash = fld.options.map { |v| [v.downcase.strip, v] }.to_h
19
20
  [fld.alt_id, options_hash]
20
21
  end
@@ -19,12 +19,23 @@ module Eco
19
19
  @logger = logger
20
20
  @schema = Ecoportal::API::V1::PersonSchema.new(JSON.parse(schema.doc.to_json))
21
21
 
22
- default_parser = Eco::API::Common::People::DefaultParsers.new(schema: @schema)
23
- @person_parser = default_parser.merge(person_parser)
22
+ @source_person_parser = person_parser
23
+
24
+ @person_parser = Eco::API::Common::People::DefaultParsers.new(schema: @schema)
25
+ @person_parser = @person_parser.merge(@source_person_parser)
26
+ @person_parser_patch_version = @source_person_parser.patch_version
24
27
 
25
28
  @attr_map = attr_map
26
29
  end
27
30
 
31
+ def person_parser
32
+ if @person_parser_patch_version < @source_person_parser.patch_version
33
+ @person_parser.merge(@source_person_parser)
34
+ @person_parser_patch_version = @source_person_parser.patch_version
35
+ end
36
+ @person_parser
37
+ end
38
+
28
39
  # key method to generate objects of `PersonEntry` that share dependencies via this `EntryFactory` environment.
29
40
  # @note this method is necessary to make the factory object work as a if it was a class `PersonEntry` you can call `new` on.
30
41
  # @param data [Array<Hash>] data to be parsed. The external hashed entry.
@@ -32,7 +43,7 @@ module Eco
32
43
  def new(data, dependencies: {})
33
44
  PersonEntry.new(
34
45
  data,
35
- person_parser: @person_parser,
46
+ person_parser: person_parser,
36
47
  attr_map: @attr_map,
37
48
  dependencies: dependencies,
38
49
  logger: @logger
@@ -62,7 +73,7 @@ module Eco
62
73
  if Eco::API::Common::Session::FileManager.file_exists?(file)
63
74
  encoding ||= Eco::API::Common::Session::FileManager.encoding(file)
64
75
  file_content = File.read(file, encoding: encoding)
65
- arr_hash = @person_parser.parse(format, file_content)
76
+ arr_hash = person_parser.parse(format, file_content)
66
77
  else
67
78
  @logger.warn("File does not exist: #{file}")
68
79
  end
@@ -105,7 +116,7 @@ module Eco
105
116
  end
106
117
 
107
118
  File.open(file, "w", enconding: encoding) do |fd|
108
- fd.write(@person_parser.serialize(format, data_entries))
119
+ fd.write(person_parser.serialize(format, data_entries))
109
120
  end
110
121
  end
111
122
 
@@ -17,7 +17,8 @@ module Eco
17
17
  attr_reader :schema
18
18
  attr_reader :details_attrs, :all_attrs
19
19
  attr_reader :defined_attrs
20
-
20
+ attr_reader :patch_version
21
+
21
22
  # @example Example of usage:
22
23
  # person_parser = PersonParser.new(schema: schema)
23
24
  # person_parser.define_attribute("example") do |parser|
@@ -33,7 +34,8 @@ module Eco
33
34
  def initialize(schema: nil)
34
35
  raise "Constructor needs a PersonSchema. Given: #{schema}" if schema && !schema.is_a?(Ecoportal::API::V1::PersonSchema)
35
36
  @details_attrs = []
36
- @parsers = {}
37
+ @parsers = {}
38
+ @patch_version = 0
37
39
 
38
40
  if schema
39
41
  @schema = Ecoportal::API::Internal::PersonSchema.new(JSON.parse(schema.doc.to_json))
@@ -43,6 +45,10 @@ module Eco
43
45
  @all_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
44
46
  end
45
47
 
48
+ def patched!
49
+ @patch_version += 1
50
+ end
51
+
46
52
  # Scopes `source_attrs` using the _**core** attributes_.
47
53
  # @note use this helper to know which among your attributes are **core** ones.
48
54
  # @param source_attrs [Array<String>]
@@ -115,6 +121,7 @@ module Eco
115
121
  return self if !parser
116
122
  raise "Expected a PersonParser object. Given #{parser}" if !parser.is_a?(PersonParser)
117
123
  @parsers.merge!(parser.hash)
124
+ patched!
118
125
  self
119
126
  end
120
127
 
@@ -133,12 +140,11 @@ module Eco
133
140
  msg = "The attribute '#{attr_to_str(attr)}' is not part of core, account or target schema, or does not match any type: #{@details_attrs}"
134
141
  raise msg
135
142
  end
136
- # Eco::Language::Models::ParserSerializer
137
143
  Eco::API::Common::People::PersonAttributeParser.new(attr, dependencies: dependencies).tap do |parser|
138
144
  @parsers[attr] = parser
139
145
  definition.call(parser)
140
146
  end
141
-
147
+ patched!
142
148
  self
143
149
  end
144
150
 
@@ -50,7 +50,13 @@ module Eco
50
50
 
51
51
  def load_json(filename)
52
52
  content = file_content(filename)
53
- return content && JSON.parse(content)
53
+ begin
54
+ parsed = content && JSON.parse(content)
55
+ rescue JSON::ParserError => e
56
+ pp "Parsing error on file #{filename}"
57
+ raise e
58
+ end
59
+ return parsed
54
60
  end
55
61
 
56
62
  def touch(filename, modifier = :no_stamp, mode: :string)
@@ -113,6 +113,17 @@ module Eco
113
113
  self
114
114
  end
115
115
 
116
+ # Allows to use the defined parsers
117
+ # @note the use of these method requires to know which is the expected format of `source`
118
+ # @param attr [String] type (`Symbol`) or attribute (`String`) to target a specific parser.
119
+ # @param source [Any] source value to be parsed.
120
+ def parse_attribute(attr, source)
121
+ unless parsers = @entry_factory.person_parser
122
+ raise "There are no parsers defined"
123
+ end
124
+ parsers.parse(attr, source)
125
+ end
126
+
116
127
  # Builds the presets using the usergroup ids of the input.
117
128
  # @note for each flag/ability it will take the highest among those mapped for the present usergroups.
118
129
  # @param [Ecoportal::API::Internal::Person, Array<String>] the array should be of usegroup names or ids.
@@ -6,11 +6,12 @@ module Eco
6
6
  extend Eco::API::Common::ClassHelpers
7
7
 
8
8
  @workflow = {
9
- load: {input: nil, people: {get: nil, filter: nil}},
10
- usecases: nil,
9
+ options: nil,
10
+ load: {input: nil, people: {get: nil, filter: nil}, filter: nil},
11
+ usecases: nil,
11
12
  launch_jobs: nil,
12
13
  post_launch: {usecases: nil, launch_jobs: nil},
13
- end: nil
14
+ end: nil
14
15
  }
15
16
 
16
17
  class << self
@@ -31,7 +31,6 @@ module Eco
31
31
  )
32
32
  end
33
33
 
34
-
35
34
  entry.set_details(person) unless options.dig(:exclude, :details)
36
35
 
37
36
  unless options.dig(:exclude, :account)
@@ -72,7 +71,7 @@ module Eco
72
71
  end
73
72
  end
74
73
  end
75
-
74
+
76
75
  end
77
76
  end
78
77
  end
@@ -31,7 +31,7 @@ module Eco
31
31
  ini_tags = person.filter_tags || []
32
32
 
33
33
  core_attrs = ["name", "external_id", "email", "filter_tags"]
34
- core_excluded = core_attrs.map(&:to_sym).select {|attr| options.dig(:exclude, attr)}
34
+ core_excluded = core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
35
35
  core_excluded.push("supervisor_id")
36
36
 
37
37
  entry.set_core(person, exclude: core_excluded)
@@ -14,8 +14,8 @@ module Eco
14
14
  end
15
15
  end
16
16
 
17
- @cases.define("remove-account", type: :sync) do |entries, people, session, options|
18
- update = session.job_group("main").new("update", type: :update, sets: [:core, :account])
17
+ @cases.define("remove-account", type: :sync) do |entries, people, session, options, usecase|
18
+ update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :account])
19
19
 
20
20
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
21
21
 
@@ -19,7 +19,7 @@ module Eco
19
19
  ini_tags = person.filter_tags || []
20
20
 
21
21
  core_attrs = ["name", "external_id", "email", "filter_tags"]
22
- core_excluded = core_attrs.map(&:to_sym).select {|attr| options.dig(:exclude, attr)}
22
+ core_excluded = core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
23
23
  core_excluded.push("supervisor_id")
24
24
 
25
25
  entry.set_core(person, exclude: core_excluded)
@@ -15,7 +15,7 @@ module Eco
15
15
  if person = people.find(entry, strict: strict_search)
16
16
  unless options.dig(:exclude, :core)
17
17
  core_attrs = ["name", "external_id", "email", "filter_tags"]
18
- core_excluded = core_attrs.map(&:to_sym).select {|attr| options.dig(:exclude, attr)}
18
+ core_excluded = core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
19
19
  core_excluded.push("supervisor_id")
20
20
 
21
21
  entry.set_core(person, exclude: core_excluded) unless options.dig(:exclude, :core)
@@ -18,11 +18,14 @@ module Eco
18
18
  person = session.new_person if create = !person
19
19
 
20
20
  unless options.dig(:exclude, :core) && !create
21
- ini_tags = person.filter_tags || []
21
+ ini_tags = person.filter_tags || []
22
22
 
23
- core_attrs = ["name", "external_id", "email", "filter_tags"]
24
- core_excluded = core_attrs.map(&:to_sym).select {|attr| options.dig(:exclude, attr)}
25
- core_excluded.push("supervisor_id")
23
+ core_excluded = ["supervisor_id"]
24
+
25
+ unless create
26
+ core_attrs = ["name", "external_id", "email", "filter_tags"]
27
+ core_excluded += core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
28
+ end
26
29
 
27
30
  entry.set_core(person, exclude: core_excluded)
28
31
  if session.tagtree && !options.dig(:exclude, :filter_tags)
data/lib/eco/assets.rb CHANGED
@@ -19,7 +19,7 @@ module Eco
19
19
  configs[:default] ||= Eco::API::Session::Config.new(key)
20
20
  unless configs.key?(key)
21
21
  @active_config = key unless !update_active
22
- configs[key] = configs[:default].clone(key)
22
+ configs[key] = configs[:default].clone(key)
23
23
  end
24
24
  configs[key].tap do |config|
25
25
  config.active_api(key) if config.apis.defined?(key)
data/lib/eco/cli.rb CHANGED
@@ -26,9 +26,9 @@ module Eco
26
26
 
27
27
  def run(session:)
28
28
  io = Eco::API::UseCases::BaseIO.new(session: session, options: options)
29
- io = io.new(options: config.options_set.process(io: io))
30
-
29
+
31
30
  session.workflow(io: io) do |wf, io|
31
+ io = wf.run(:options, io: io)
32
32
  io = wf.run(:load, io: io)
33
33
  io = wf.run(:usecases, io: io)
34
34
  io = wf.run(:launch_jobs, io: io)
@@ -1,10 +1,23 @@
1
1
  ASSETS.cli.config do |config|
2
2
  ASSETS.config.workflow do |wf|
3
3
 
4
- wf.on(:load) do |wf_load, io|
5
- io = io.new(input: config.input.get(io: io))
6
- io = io.new(people: config.people(io: io))
7
- io = io.new(people: config.people_filters.process(io: io))
4
+ io = nil
5
+ wf.on(:options) do |wf_options, io|
6
+ io = io.new(options: config.options_set.process(io: io))
7
+ end
8
+
9
+ wf.for(:load) do |wf_load|
10
+ wf_load.on(:input) do |wf_input, io|
11
+ io = io.new(input: config.input.get(io: io))
12
+ end
13
+
14
+ wf_load.on(:people) do |wf_people, io|
15
+ io = io.new(people: config.people(io: io))
16
+ end
17
+
18
+ wf_load.on(:filter) do |wf_filter, io|
19
+ io = io.new(people: config.people_filters.process(io: io))
20
+ end
8
21
  end
9
22
 
10
23
  wf.before(:usecases) do |wf_cases, io|
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
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: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura