ecoportal-api 0.8.5 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +20 -20
  3. data/.rspec +3 -3
  4. data/.rubocop.yml +55 -55
  5. data/.travis.yml +5 -5
  6. data/.yardopts +10 -10
  7. data/CHANGELOG.md +257 -236
  8. data/Gemfile +6 -6
  9. data/LICENSE +21 -21
  10. data/README.md +34 -34
  11. data/Rakefile +27 -27
  12. data/bin/console +14 -14
  13. data/bin/setup +8 -8
  14. data/ecoportal-api.gemspec +36 -36
  15. data/lib/ecoportal/api/common/base_class.rb +33 -29
  16. data/lib/ecoportal/api/common/base_model.rb +195 -177
  17. data/lib/ecoportal/api/common/batch_operation.rb +119 -119
  18. data/lib/ecoportal/api/common/batch_response.rb +34 -34
  19. data/lib/ecoportal/api/common/client.rb +198 -196
  20. data/lib/ecoportal/api/common/doc_helpers.rb +29 -29
  21. data/lib/ecoportal/api/common/elastic_apm_integration.rb +112 -112
  22. data/lib/ecoportal/api/common/hash_diff.rb +41 -41
  23. data/lib/ecoportal/api/common/logging.rb +12 -12
  24. data/lib/ecoportal/api/common/response.rb +31 -31
  25. data/lib/ecoportal/api/common/wrapped_response.rb +54 -54
  26. data/lib/ecoportal/api/common.rb +18 -18
  27. data/lib/ecoportal/api/errors/base.rb +8 -8
  28. data/lib/ecoportal/api/errors/time_out.rb +8 -8
  29. data/lib/ecoportal/api/errors.rb +9 -9
  30. data/lib/ecoportal/api/internal/account.rb +99 -100
  31. data/lib/ecoportal/api/internal/login_provider.rb +9 -9
  32. data/lib/ecoportal/api/internal/login_providers.rb +33 -33
  33. data/lib/ecoportal/api/internal/people.rb +14 -14
  34. data/lib/ecoportal/api/internal/permissions.rb +14 -13
  35. data/lib/ecoportal/api/internal/person.rb +101 -53
  36. data/lib/ecoportal/api/internal/person_details.rb +9 -9
  37. data/lib/ecoportal/api/internal/person_schema.rb +10 -10
  38. data/lib/ecoportal/api/internal/person_schemas.rb +11 -11
  39. data/lib/ecoportal/api/internal/policy_group.rb +9 -9
  40. data/lib/ecoportal/api/internal/policy_groups.rb +32 -32
  41. data/lib/ecoportal/api/internal/preferences.rb +31 -31
  42. data/lib/ecoportal/api/internal/schema_field.rb +8 -8
  43. data/lib/ecoportal/api/internal/schema_field_value.rb +8 -8
  44. data/lib/ecoportal/api/internal.rb +31 -31
  45. data/lib/ecoportal/api/logger.rb +62 -62
  46. data/lib/ecoportal/api/v1/people.rb +218 -218
  47. data/lib/ecoportal/api/v1/person.rb +138 -135
  48. data/lib/ecoportal/api/v1/person_details.rb +94 -82
  49. data/lib/ecoportal/api/v1/person_schema.rb +53 -53
  50. data/lib/ecoportal/api/v1/person_schemas.rb +48 -48
  51. data/lib/ecoportal/api/v1/schema_field.rb +34 -34
  52. data/lib/ecoportal/api/v1/schema_field_value.rb +65 -65
  53. data/lib/ecoportal/api/v1.rb +49 -49
  54. data/lib/ecoportal/api/version.rb +5 -5
  55. data/lib/ecoportal/api.rb +16 -16
  56. metadata +3 -3
@@ -1,135 +1,138 @@
1
- module Ecoportal
2
- module API
3
- class V1
4
- # @attr id [String] the internal unique id of this person (unique in all the system).
5
- # @attr external_id [String] the alternative unique id of this person (unique in one organization).
6
- # @attr name [String] the name of the person.
7
- # @attr supervisor_id [String] internal or external id of the supervisor of this person.
8
- # @attr_reader subordinates [Integer] the number of people this person is supervisor of.
9
- # @attr details [PersonDetails, nil] the details of the person or `nil` if missing.
10
- class Person < Common::BaseModel
11
- passthrough :id, :external_id, :name, :email, :supervisor_id, :subordinates, :filter_tags, :freemium
12
-
13
- class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema"
14
- class_resolver :person_details_class, "Ecoportal::API::V1::PersonDetails"
15
- embeds_one :details, nullable: true, klass: :person_details_class
16
-
17
- VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/
18
- VALID_EMAIL_REGEX = /^[^@\s]+@[^@\s]+\.[^@\s]+$/
19
-
20
- # Gets the supervisor (`Person`) of this person, with given his `supervisor_id`.
21
- #
22
- # **Example Usage**:
23
- # ```ruby
24
- # API_KEY = 'some-private-api-key-version'
25
- # HOST = "live.ecoportal.com"
26
- # api = Ecoportal::API::Internal.new(API_KEY, host: HOST)
27
- # person = api.people.get({"id": "my-dummy-user"})
28
- # super = person.supervisor(api.client)
29
- # pp "#{person.name}'s supervisor is #{super.name}."
30
- # ```
31
- #
32
- # @param client [Common::Client] the api client to make the request.
33
- def supervisor(client)
34
- return @supervisor if defined?(@supervisor)
35
- return @supervisor = nil if supervisor_id.nil?
36
- @supervisor = client.people.get(supervisor_id).result
37
- end
38
-
39
- # Sets the supervisor of a person.
40
- # @param person [Person, nil] the supervisor of this person.
41
- def supervisor=(person)
42
- self.supervisor_id = person&.id || person&.external_id
43
- end
44
-
45
- # Sets the email of a person.
46
- # @param value [String, nil] the email of this person.
47
- def email=(value)
48
- unless !value || value.match(VALID_EMAIL_REGEX)
49
- raise "Invalid email #{value.inspect}"
50
- end
51
- doc["email"] = value&.downcase
52
- end
53
-
54
- # Validates the string tags of the array, and sets the `filter_tags` property of the account.
55
- # @note all is set in upper case and preserves the original order.
56
- # @raise [Exception] if there was any invalid string tag.
57
- # @param value [Array<String>] array of tags.
58
- def filter_tags=(value)
59
- unless value.is_a?(Array)
60
- raise "filter_tags= needs to be passed an Array, got #{value.class}"
61
- end
62
- end_tags = value.compact.map do |tag|
63
- unless tag.match(VALID_TAG_REGEX)
64
- raise "Invalid filter tag #{tag.inspect}"
65
- end
66
- tag.upcase
67
- end
68
- set_uniq_array_keep_order("filter_tags", end_tags)
69
- end
70
-
71
- # @return [Array<String>] the filter tags of this person.
72
- def filter_tags
73
- doc["filter_tags"] ||= []
74
- end
75
-
76
- def as_json
77
- super.merge "details" => details&.as_json
78
- end
79
-
80
- def as_update(ref = :last, ignore: [])
81
- super(ignore: ignore | ["subordinates"])
82
- end
83
-
84
- # Sets the PersonDetails to the person, depending on the paramter received:
85
- # - `nil`: blanks the details.
86
- # - `PersonDetails`: sets a copy of the object param as details.
87
- # - `Hash`: sets respectivelly the `schema_id` and the `fields` keys of the Hash to the person details.
88
- # @note unique point of access to update the PersonDetails.
89
- # @param value [nil, PersonDetails, Hash] value to be set.
90
- # @return [nil, PersonDetails] the resulting `PersonDetails` set to the person.
91
- def details=(value)
92
- case value
93
- when NilClass
94
- doc["details"] = nil
95
- when person_details_class
96
- doc["details"] = value.as_json
97
- when Hash
98
- doc["details"] = value.slice("schema_id", "fields")
99
- else
100
- raise "Invalid type set on details. Required nil, PersonDetails or Hash; got #{value.class}"
101
- end
102
- remove_instance_variable("@details") if defined?(@details)
103
- end
104
-
105
- # Sets the PersonDetails to the person, depending on the parameter received:
106
- # - `PersonSchema`: initializes the `PersonDetails` as per the schema specified (`schema_id` and `fields`).
107
- # - `String`: it just sets the `schema_id` on the `PersonDetails` (as `fields` is not include, `details[key]=` will throw error).
108
- # (see #details=)
109
- # @note
110
- # - this method alone only sets the internal structure of the details.
111
- # - you will not be able to `reset!` after using this method.
112
- # @param schema_or_id [PersonSchema, String, nil, PersonDetails, Hash] value to be set.
113
- # @return [nil, PersonDetails] the resulting `PersonDetails` that set to the person.
114
- def add_details(schema_or_id)
115
- person_details_class.new.tap do |new_details|
116
- case schema_or_id
117
- when person_schema_class
118
- schema_or_id.initialize_details(new_details)
119
- when String
120
- new_details.schema_id = schema_or_id
121
- else
122
- raise "Invalid set on details: Requierd PersonSchema or String; got #{schema_or_id.class}"
123
- end
124
- self.details = new_details
125
- # Patch out static data from as_update
126
- original_doc["details"] = {
127
- "fields" => JSON.parse(doc["details"]["fields"].to_json)
128
- }
129
- end
130
- end
131
-
132
- end
133
- end
134
- end
135
- end
1
+ module Ecoportal
2
+ module API
3
+ class V1
4
+ # @attr id [String] the internal unique id of this person (unique in all the system).
5
+ # @attr external_id [String] the alternative unique id of this person (unique in one organization).
6
+ # @attr name [String] the name of the person.
7
+ # @attr supervisor_id [String] internal or external id of the supervisor of this person.
8
+ # @attr contractor_organization_id [String] internal id of the contractor entity of this person.
9
+ # @attr_reader subordinates [Integer] the number of people this person is supervisor of.
10
+ # @attr details [PersonDetails, nil] the details of the person or `nil` if missing.
11
+ class Person < Common::BaseModel
12
+ passthrough :id, :external_id, :name, :email, :filter_tags
13
+ passthrough :supervisor_id, :subordinates, :contractor_organization_id
14
+ passthrough :freemium
15
+
16
+ class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema"
17
+ class_resolver :person_details_class, "Ecoportal::API::V1::PersonDetails"
18
+ embeds_one :details, nullable: true, klass: :person_details_class
19
+
20
+ VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/.-]+$/
21
+ VALID_EMAIL_REGEX = /^[^@\s]+@[^@\s]+\.[^@\s]+$/
22
+
23
+ # Gets the supervisor (`Person`) of this person, with given his `supervisor_id`.
24
+ #
25
+ # **Example Usage**:
26
+ # ```ruby
27
+ # API_KEY = 'some-private-api-key-version'
28
+ # HOST = "live.ecoportal.com"
29
+ # api = Ecoportal::API::Internal.new(API_KEY, host: HOST)
30
+ # person = api.people.get({"id": "my-dummy-user"})
31
+ # super = person.supervisor(api.client)
32
+ # pp "#{person.name}'s supervisor is #{super.name}."
33
+ # ```
34
+ #
35
+ # @param client [Common::Client] the api client to make the request.
36
+ def supervisor(client)
37
+ return @supervisor if defined?(@supervisor)
38
+ return @supervisor = nil if supervisor_id.nil?
39
+ @supervisor = client.people.get(supervisor_id).result
40
+ end
41
+
42
+ # Sets the supervisor of a person.
43
+ # @param person [Person, nil] the supervisor of this person.
44
+ def supervisor=(person)
45
+ self.supervisor_id = person&.id || person&.external_id
46
+ end
47
+
48
+ # Sets the email of a person.
49
+ # @param value [String, nil] the email of this person.
50
+ def email=(value)
51
+ unless !value || value.match(VALID_EMAIL_REGEX)
52
+ raise "Invalid email #{value.inspect}"
53
+ end
54
+ doc["email"] = value&.downcase
55
+ end
56
+
57
+ # Validates the string tags of the array, and sets the `filter_tags` property of the account.
58
+ # @note all is set in upper case and preserves the original order.
59
+ # @raise [Exception] if there was any invalid string tag.
60
+ # @param value [Array<String>] array of tags.
61
+ def filter_tags=(value)
62
+ unless value.is_a?(Array)
63
+ raise "filter_tags= needs to be passed an Array, got #{value.class}"
64
+ end
65
+ end_tags = value.compact.map do |tag|
66
+ unless tag.match(VALID_TAG_REGEX)
67
+ raise "Invalid filter tag #{tag.inspect}"
68
+ end
69
+ tag.upcase
70
+ end
71
+ set_uniq_array_keep_order("filter_tags", end_tags)
72
+ end
73
+
74
+ # @return [Array<String>] the filter tags of this person.
75
+ def filter_tags
76
+ doc["filter_tags"] ||= []
77
+ end
78
+
79
+ def as_json
80
+ super.merge "details" => details&.as_json
81
+ end
82
+
83
+ def as_update(ref = :last, ignore: [])
84
+ super(ignore: ignore | ["subordinates"])
85
+ end
86
+
87
+ # Sets the PersonDetails to the person, depending on the paramter received:
88
+ # - `nil`: blanks the details.
89
+ # - `PersonDetails`: sets a copy of the object param as details.
90
+ # - `Hash`: sets respectivelly the `schema_id` and the `fields` keys of the Hash to the person details.
91
+ # @note unique point of access to update the PersonDetails.
92
+ # @param value [nil, PersonDetails, Hash] value to be set.
93
+ # @return [nil, PersonDetails] the resulting `PersonDetails` set to the person.
94
+ def details=(value)
95
+ case value
96
+ when NilClass
97
+ doc["details"] = nil
98
+ when person_details_class
99
+ doc["details"] = value.as_json
100
+ when Hash
101
+ doc["details"] = value.slice("schema_id", "fields")
102
+ else
103
+ raise "Invalid type set on details. Required nil, PersonDetails or Hash; got #{value.class}"
104
+ end
105
+ remove_instance_variable("@details") if defined?(@details)
106
+ end
107
+
108
+ # Sets the PersonDetails to the person, depending on the parameter received:
109
+ # - `PersonSchema`: initializes the `PersonDetails` as per the schema specified (`schema_id` and `fields`).
110
+ # - `String`: it just sets the `schema_id` on the `PersonDetails` (as `fields` is not include, `details[key]=` will throw error).
111
+ # (see #details=)
112
+ # @note
113
+ # - this method alone only sets the internal structure of the details.
114
+ # - you will not be able to `reset!` after using this method.
115
+ # @param schema_or_id [PersonSchema, String, nil, PersonDetails, Hash] value to be set.
116
+ # @return [nil, PersonDetails] the resulting `PersonDetails` that set to the person.
117
+ def add_details(schema_or_id)
118
+ person_details_class.new.tap do |new_details|
119
+ case schema_or_id
120
+ when person_schema_class
121
+ schema_or_id.initialize_details(new_details)
122
+ when String
123
+ new_details.schema_id = schema_or_id
124
+ else
125
+ raise "Invalid set on details: Requierd PersonSchema or String; got #{schema_or_id.class}"
126
+ end
127
+ self.details = new_details
128
+ # Patch out static data from as_update
129
+ original_doc["details"] = {
130
+ "fields" => JSON.parse(doc["details"]["fields"].to_json)
131
+ }
132
+ end
133
+ end
134
+
135
+ end
136
+ end
137
+ end
138
+ end
@@ -1,82 +1,94 @@
1
- module Ecoportal
2
- module API
3
- class V1
4
- class PersonDetails < Common::BaseModel
5
- class MissingId < StandardError
6
- end
7
-
8
- passthrough :schema_id
9
-
10
- class_resolver :schema_field_value_class, "Ecoportal::API::V1::SchemaFieldValue"
11
-
12
- def as_json
13
- super.merge "fields" => fields.map(&:as_json)
14
- end
15
-
16
- # Sets the `id` of the PersonDetails.
17
- # @note unless the new `id` is `nil`, this does not reset the `fields`.
18
- # @param value [nil, String] the id of the schema.
19
- def schema_id=(value)
20
- @fields = [] if value.nil?
21
- doc["schema_id"] = value
22
- end
23
-
24
- # Gets all the fields of the PersonDetails.
25
- # @return [Array<SchemaFieldValue>] the array of fields of the schema.
26
- def fields
27
- return @fields if defined?(@fields)
28
- @fields = (doc["fields"] || []).each_with_index.map do |field, i|
29
- schema_field_value_class.new(field, parent: self, key: ["fields", i])
30
- end
31
- end
32
-
33
- # Gets one specific field of the PersonDetails.
34
- # @param id [String] the `id` or the `alt_id` of the target field.
35
- # @return [nil, SchemaFieldValue] the field or `nil` if missing.
36
- def get_field(id)
37
- @fields_by_id or index_fields
38
- @fields_by_id[id] || @fields_by_alt_id[id]
39
- end
40
-
41
- # Gets the value of one specific field of the PersonDetails.
42
- # @param id [String] the `id` or the `alt_id` of the target field.
43
- # @return [String, Array<String>, Boolean, Array<Boolean>, Date, Array<Date>, Numberic, Array<Numeric>] the value of field or `nil` if missing.
44
- def [](id)
45
- get_field(id)&.value
46
- end
47
-
48
- # Sets the value to one specific field of the PersonDetails.
49
- # @raise MisssingId if the `id` or `alt_id` is missing.
50
- # @param id [String] the `id` or the `alt_id` of the target field.
51
- # @return [void]
52
- def []=(id, value)
53
- if field = get_field(id)
54
- field.value = value
55
- else
56
- raise MissingId.new("details[#{id.inspect}] is missing. Did you forget to load the schema?")
57
- end
58
- end
59
-
60
- # Checks if an `id` or `alt_id` exists
61
- # @param id [String] the `id` or the `alt_id` of the target field.
62
- # @return [Boolean] `true` if it exists, `false` otherwise
63
- def key?(id)
64
- @fields_by_id.key?(id) || @fields_by_alt_id.key?(id)
65
- end
66
-
67
- protected
68
-
69
- # Rebuilds the internal `id` and `alt_id` references to the fields.
70
- def index_fields
71
- @fields_by_id = {}
72
- @fields_by_alt_id = {}
73
- fields.each do |wrapped|
74
- @fields_by_id[wrapped.id] = wrapped
75
- @fields_by_alt_id[wrapped.alt_id] = wrapped
76
- end
77
- end
78
-
79
- end
80
- end
81
- end
82
- end
1
+ module Ecoportal
2
+ module API
3
+ class V1
4
+ class PersonDetails < Common::BaseModel
5
+ class MissingId < StandardError
6
+ end
7
+
8
+ passthrough :schema_id
9
+
10
+ class_resolver :schema_field_value_class, "Ecoportal::API::V1::SchemaFieldValue"
11
+
12
+ def as_json
13
+ super.merge "fields" => fields.map(&:as_json)
14
+ end
15
+
16
+ # Sets the `id` of the PersonDetails.
17
+ # @note unless the new `id` is `nil`, this does not reset the `fields`.
18
+ # @param value [nil, String] the id of the schema.
19
+ def schema_id=(value)
20
+ @fields = [] if value.nil?
21
+ doc["schema_id"] = value
22
+ end
23
+
24
+ # Gets all the fields of the PersonDetails.
25
+ # @return [Array<SchemaFieldValue>] the array of fields of the schema.
26
+ def fields
27
+ return @fields if defined?(@fields)
28
+ @fields = (doc["fields"] || []).each_with_index.map do |field, i|
29
+ schema_field_value_class.new(field, parent: self, key: ["fields", i])
30
+ end
31
+ end
32
+
33
+ # Gets one specific field of the PersonDetails.
34
+ # @param id [String] the `id` or the `alt_id` of the target field.
35
+ # @return [nil, SchemaFieldValue] the field or `nil` if missing.
36
+ def get_field(id)
37
+ @fields_by_id or index_fields
38
+ @fields_by_id[id] || @fields_by_alt_id[id]
39
+ end
40
+
41
+ # Gets the value of one specific field of the PersonDetails.
42
+ # @param id [String] the `id` or the `alt_id` of the target field.
43
+ # @return [String, Array<String>, Boolean, Array<Boolean>, Date, Array<Date>, Numberic, Array<Numeric>] the value of field or `nil` if missing.
44
+ def [](id)
45
+ get_field(id)&.value
46
+ end
47
+
48
+ # Sets the value to one specific field of the PersonDetails.
49
+ # @raise MisssingId if the `id` or `alt_id` is missing.
50
+ # @param id [String] the `id` or the `alt_id` of the target field.
51
+ # @return [void]
52
+ def []=(id, value)
53
+ if field = get_field(id)
54
+ field.value = value
55
+ else
56
+ raise MissingId.new("details[#{id.inspect}] is missing. Did you forget to load the schema?")
57
+ end
58
+ end
59
+
60
+ # Checks if an `id` or `alt_id` exists
61
+ # @param id [String] the `id` or the `alt_id` of the target field.
62
+ # @return [Boolean] `true` if it exists, `false` otherwise
63
+ def key?(id)
64
+ @fields_by_id or index_fields
65
+ @fields_by_id.key?(id) || @fields_by_alt_id.key?(id)
66
+ end
67
+
68
+ # @return [Boolean] `true` if `id` exists and `value` has changed, `false` otherwise
69
+ def changed?(id, doc = :original)
70
+ return false unless field = get_field(id)
71
+ field.as_update.key?("value")
72
+ end
73
+
74
+ def original_value(id)
75
+ return nil unless field = get_field(id)
76
+ field.original_doc["value"]
77
+ end
78
+
79
+ protected
80
+
81
+ # Rebuilds the internal `id` and `alt_id` references to the fields.
82
+ def index_fields
83
+ @fields_by_id = {}
84
+ @fields_by_alt_id = {}
85
+ fields.each do |wrapped|
86
+ @fields_by_id[wrapped.id] = wrapped
87
+ @fields_by_alt_id[wrapped.alt_id] = wrapped
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,53 +1,53 @@
1
- module Ecoportal
2
- module API
3
- class V1
4
- class PersonSchema < Common::BaseModel
5
- passthrough :id, :name
6
- passthrough :enable_tags, :tags
7
-
8
- class_resolver :schema_field_class, "Ecoportal::API::V1::SchemaField"
9
-
10
- def fields
11
- @fields_by_id or index_fields
12
- @fields_by_id.values
13
- end
14
-
15
- def fields_by_id
16
- @fields_by_id or index_fields
17
- @fields_by_id
18
- end
19
-
20
- def fields_by_alt_id
21
- @fields_by_alt_id or index_fields
22
- @fields_by_alt_id
23
- end
24
-
25
- def [](id)
26
- @fields_by_alt_id or index_fields
27
- @fields_by_id[id] || @fields_by_alt_id[id]
28
- end
29
-
30
- def index_fields
31
- @fields_by_id = {}
32
- @fields_by_alt_id = {}
33
- doc["fields"].each do |field|
34
- wrapped = schema_field_class.new(field)
35
- @fields_by_id[wrapped.id] = wrapped
36
- @fields_by_alt_id[wrapped.alt_id] = wrapped
37
- end
38
- end
39
-
40
- def initialize_details(details)
41
- details.schema_id = id
42
- details.doc["fields"] = fields.map do |field|
43
- field.doc.slice(*%w[id alt_id name multiple type shared]).merge(
44
- "value" => field.multiple ? [] : nil
45
- )
46
- end
47
- end
48
-
49
- end
50
- end
51
- end
52
- end
53
- require 'ecoportal/api/v1/schema_field'
1
+ module Ecoportal
2
+ module API
3
+ class V1
4
+ class PersonSchema < Common::BaseModel
5
+ passthrough :id, :name
6
+ passthrough :enable_tags, :tags
7
+
8
+ class_resolver :schema_field_class, "Ecoportal::API::V1::SchemaField"
9
+
10
+ def fields
11
+ @fields_by_id or index_fields
12
+ @fields_by_id.values
13
+ end
14
+
15
+ def fields_by_id
16
+ @fields_by_id or index_fields
17
+ @fields_by_id
18
+ end
19
+
20
+ def fields_by_alt_id
21
+ @fields_by_alt_id or index_fields
22
+ @fields_by_alt_id
23
+ end
24
+
25
+ def [](id)
26
+ @fields_by_alt_id or index_fields
27
+ @fields_by_id[id] || @fields_by_alt_id[id]
28
+ end
29
+
30
+ def index_fields
31
+ @fields_by_id = {}
32
+ @fields_by_alt_id = {}
33
+ doc["fields"].each do |field|
34
+ wrapped = schema_field_class.new(field)
35
+ @fields_by_id[wrapped.id] = wrapped
36
+ @fields_by_alt_id[wrapped.alt_id] = wrapped
37
+ end
38
+ end
39
+
40
+ def initialize_details(details)
41
+ details.schema_id = id
42
+ details.doc["fields"] = fields.map do |field|
43
+ field.doc.slice(*%w[id alt_id name multiple type shared]).merge(
44
+ "value" => field.multiple ? [] : nil
45
+ )
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ require 'ecoportal/api/v1/schema_field'