eco-helpers 0.9.4 → 0.9.5

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: c80ae3aadfdbce22868e7a60c6c6a979bfcad0169fffccb47a6a412bbd7c5788
4
- data.tar.gz: ec19d4b61fe40b33e4fc1b7ac1deba98110c901e573c4c3c421c6f28409e0b46
3
+ metadata.gz: 8824e93753de01f752b0b655339fcc09ddf4da24dfdad76b25cadb25bed11225
4
+ data.tar.gz: 9db399712ea74e57ea62c696802f2dcf80e8fe01dd476f18edc4a938a66ca4ab
5
5
  SHA512:
6
- metadata.gz: 2732b578b4f14b62442d525ca028d11fbba6c888614a85975b3a01f4fc988e7c967b187fe7289e1a3506e56c6067d28ad40a97ecf8c5d52641d2232e504a88db
7
- data.tar.gz: 55a0ef82cfa791f4fb7c88588a9dc90b082cc162aeb208bb22c835e2d2d4c1171ce576378e7c13bdb4e9d64632f97dd00ba1346667b3ae91198f40da6f35c7c8
6
+ metadata.gz: d655f7beb82c00655a86d3e75e0444d4e0eb9f233a8e8b265413384d41e50c5e985ecd0588f37fb3e45209a296f9a4a8f6d02a90bb2cea8e7d09b6da2385a509
7
+ data.tar.gz: 325555d794297d40c3bfaffb8e3f500d622b3f16c274ad71001c0b56235a2560168cd6e18ce1fdfe5284bf0c91e75c5f0127b179e425f54195191629973d5349
@@ -54,21 +54,37 @@ module Eco
54
54
  @internal_entry["id"]
55
55
  end
56
56
 
57
+ def id?
58
+ @internal_entry.key?("id")
59
+ end
60
+
57
61
  # @return [String, nil] the _external id_ of this person if defined.
58
62
  def external_id
59
63
  @internal_entry["external_id"]
60
64
  end
61
65
 
66
+ def external_id?
67
+ @internal_entry.key?("external_id")
68
+ end
69
+
62
70
  # @return [String, nil] the _name_ of this person if defined.
63
71
  def name
64
72
  @internal_entry["name"]
65
73
  end
66
74
 
75
+ def name?
76
+ @internal_entry.key?("name")
77
+ end
78
+
67
79
  # @return [String, nil] the _email_ of this person if defined.
68
80
  def email
69
81
  @internal_entry["email"]
70
82
  end
71
83
 
84
+ def email?
85
+ @internal_entry.key?("email")
86
+ end
87
+
72
88
  # @return [String, nil] the _supervisor id_ of this person if defined.
73
89
  def supervisor_id
74
90
  @internal_entry["supervisor_id"]
@@ -78,6 +94,19 @@ module Eco
78
94
  @internal_entry["supervisor_id"] = value
79
95
  end
80
96
 
97
+ def supervisor_id?
98
+ @internal_entry.key?("supervisor_id")
99
+ end
100
+
101
+ def filter_tags
102
+ @internal_entry["filter_tags"]
103
+ end
104
+
105
+ def filter_tags?
106
+ @internal_entry.key?("filter_tags")
107
+ end
108
+
109
+
81
110
  # Provides a reference of this person.
82
111
  # @return [String] string summary of this person identity.
83
112
  def to_s(options)
@@ -229,7 +258,8 @@ module Eco
229
258
  return nil if !person.account
230
259
  multiple = ["policy_group_ids", "filter_tags"].include?(attr)
231
260
  value = person.account.send(attr)
232
- @person_parser.serialize(:multiple, value) if multiple
261
+ value = @person_parser.serialize(:multiple, value) if multiple
262
+ value
233
263
  end
234
264
 
235
265
  def _get_from_details(person, attr)
@@ -296,7 +326,7 @@ module Eco
296
326
  # @param aliased_entry [Hash] the entry with the _internal attribute_ names but the _external values_.
297
327
  # @return [Hash] the `internal entry` with the **internal** attributes names and values.
298
328
  def _parsed_entry(aliased_entry)
299
- parsed = @person_parser.defined_attrs.map do |attr|
329
+ parsed = @person_parser.active_attrs(aliased_entry).map do |attr|
300
330
  value = @person_parser.parse(attr, aliased_entry)
301
331
  [attr, value]
302
332
  end.to_h
@@ -85,6 +85,7 @@ module Eco
85
85
  end
86
86
 
87
87
  # Returns a list of all the internal attributes of the model that have a parser defined & that should be active.
88
+ # @param [Hash, Array<String>]
88
89
  # @return [Array<String>] list of all attribute defined parsers that should be active.
89
90
  def active_attrs(source_data)
90
91
  defined_attrs.select {|attr| @parsers[attr].parser_active?(source_data)}
@@ -18,7 +18,7 @@ module Ecoportal
18
18
  when Internal::Account
19
19
  doc["account"] = JSON.parse(value.to_json)
20
20
  when Hash
21
- doc["account"] = value.slice(*%w[policy_group_ids landing_page_id permissions_preset permissions_custom preferences prefilter filter_tags login_provider_ids starred_ids])
21
+ doc["account"] = value.slice(*%w[policy_group_ids landing_page_id permissions_preset permissions_custom preferences prefilter filter_tags default_tag login_provider_ids starred_ids])
22
22
  else
23
23
  # TODO
24
24
  raise "Invalid set on account: Need nil, Account or Hash; got #{value.class}"
@@ -2,9 +2,13 @@ module Eco
2
2
  module API
3
3
  class Session < Common::Session::BaseSession
4
4
  attr_reader :batch
5
- attr_reader :usecases
6
5
  attr_accessor :schema
7
6
 
7
+ # Class to manage the current session.
8
+ # Central helper of resources.
9
+ #
10
+ # @attr_reader batch [Eco::API::Session::Batch] provides helper to launch batch operations.
11
+ # @attr_reader schema [Ecoportal::API::V1::PersonSchema] currently active schema.
8
12
  def initialize(init = {})
9
13
  e = init
10
14
  msg = "Expected object Eco::API::Session::Config or Eco::API::Common::Session::Environment. Given: #{init}"
@@ -29,7 +33,8 @@ module Eco
29
33
  })
30
34
  end
31
35
 
32
- # TASKS & JOBS
36
+ # Helper to perform multiple operations in one go.
37
+ # @return [Eco::API::Session::Task] provides shortcuts to manage certain kind of operations.
33
38
  def do
34
39
  @task
35
40
  end
@@ -52,18 +57,24 @@ module Eco
52
57
  end
53
58
  end
54
59
 
60
+ # @see Eco::API::Session::Config#policy_groups
55
61
  def policy_groups
56
62
  config.policy_groups
57
63
  end
58
64
 
65
+ # @see Eco::API::Session::Config#tagtree
59
66
  def tagtree
60
67
  config.tagtree(enviro: enviro)
61
68
  end
62
69
 
70
+ # @see Eco::API::Session::Config#schemas
63
71
  def schemas
64
72
  config.schemas
65
73
  end
66
74
 
75
+ # Sets the current target `PersonSchema` of this session.
76
+ # @note observe that it is essential for the parsers/serialisers to identify target/present attributes.
77
+ # @param schema [String, Ecoportal::API::V1::PersonSchema] where `String` can be the _name_ or the _id_ of the schema.
67
78
  def schema=(value)
68
79
  case value
69
80
  when String
@@ -97,6 +108,10 @@ module Eco
97
108
  self
98
109
  end
99
110
 
111
+ # Builds the presets using the usergroup ids of the input.
112
+ # @note for each flag/ability it will take the highest among those mapped for the present usergroups.
113
+ # @param [Ecoportal::API::Internal::Person, Array<String>] the array should be of usegroup names or ids.
114
+ # @return [Hash] with custom presets.
100
115
  def new_preset(input)
101
116
  case input
102
117
  when Ecoportal::API::Internal::Person
@@ -112,24 +127,38 @@ module Eco
112
127
  @entry_factory.export(*args)
113
128
  end
114
129
 
130
+ # @see Eco::API::Common::People::EntryFactory#new
131
+ # @return [Ecoportal::API::Internal::Person]
115
132
  def new_person(**keyed_args)
116
133
  @person_factory.new(**keyed_args)
117
134
  end
118
135
 
136
+ # Builds the entry for the given data.
137
+ # @see Eco::API::Common::People::EntryFactory#new
138
+ # @return [Eco::API::Common::People::PersonEntry] parsed entry.
119
139
  def new_entry(data, dependencies: {})
120
140
  @entry_factory.new(data, dependencies: dependencies)
121
141
  end
122
142
 
143
+ # @see Eco::API::Common::People::EntryFactory#entries
144
+ # @return [Eco::API::Common::People::Entries] collection of entries.
123
145
  def entries(*args)
124
146
  @entry_factory.entries(*args).tap do |collection|
125
147
  logger.info("Loaded #{collection.length} input entries.")
126
148
  end
127
149
  end
128
150
 
151
+ # Generates an entries collection from a csv input file.
152
+ # @see Eco::API::Common::People::EntryFactory#entries
153
+ # @param file [String] file to generate the entries from.
154
+ # @return [Eco::API::Common::People::Entries] collection of entries.
129
155
  def csv_entries(file)
130
156
  return entries(file: file, format: :csv)
131
157
  end
132
158
 
159
+ # Generates the collection of entries that should be discarded from an update.
160
+ # @note requires `session.config.people.discarded_file` to be defined.
161
+ # @return [Eco::API::Common::People::Entries] collection of entries.
133
162
  def discarded_entries
134
163
  return @discarded_entries if instance_variable_defined?(:@discarded_entries)
135
164
  file = config.people.discarded_file
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "0.9.4"
2
+ VERSION = "0.9.5"
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.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -396,7 +396,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
396
396
  - !ruby/object:Gem::Version
397
397
  version: '0'
398
398
  requirements: []
399
- rubygems_version: 3.0.3
399
+ rubygems_version: 3.0.4
400
400
  signing_key:
401
401
  specification_version: 4
402
402
  summary: eco-helpers to manage people api cases