dmao-generic-ingesters 0.4.0 → 0.5.0

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
  SHA1:
3
- metadata.gz: 8a71389705fcf4841e99d08ff0095a27663f0502
4
- data.tar.gz: 998ac6edd53d0b9cb88d634825e33d6540221789
3
+ metadata.gz: 14515f70a6f8d85f46287efdda0215af1bc1dda9
4
+ data.tar.gz: 4b358a91f560c57d6e44918cd15bcad63cb26147
5
5
  SHA512:
6
- metadata.gz: b2f670e91b1df80c0fbbf1ecae5f0e1ee3f89cc834b91eb8ab6cda7cd0b8d8da5f543151af1bf25358b6f420125001a5aabf16adbba2c016bddf942db2ff9c79
7
- data.tar.gz: 35a6f05547877fd292b65af83ba9e1ca2a63f8f09338e5243bc0d7d5ca236cd51a9f9c6bbf55f0e0f32f4517cc64a8b0e6c94927ba102ab99b06b06639cb5231
6
+ metadata.gz: fa75f4a64f4b4e86003162acdb220327ee33140b05c3beccf03784a376d3651d5198bd860fc1d3267414031dd6c3a9bba0475daa41a782b1d5bdc2690735e8a5
7
+ data.tar.gz: 2f75e695c3b0d19ce70cbb754a40e1a656d687ec36c9360663e5296dc547c197cea30a1b493c6f94766610338767cb7147058022179eec7444f6e99dc2fbfa25
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "generic/ingesters"
4
+ require "dmao/ingesters/generic/ingester"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -13,20 +13,6 @@ module DMAO
13
13
  INVALID_ENTITY_ERROR = DMAO::API::Errors::InvalidFunder
14
14
  ENTITY_ERROR_MESSAGE = "Invalid funder details"
15
15
 
16
- def ingest_funder attributes={}
17
- ingest_entity attributes
18
- end
19
-
20
- private
21
-
22
- def add_funder attributes
23
- add_entity attributes
24
- end
25
-
26
- def update_funder id, attributes
27
- update_entity id, attributes
28
- end
29
-
30
16
  end
31
17
 
32
18
  end
@@ -16,11 +16,29 @@ module DMAO
16
16
  ENTITY_ERROR_MESSAGE = nil
17
17
 
18
18
  def initialize(api_url=nil, api_token=nil, institution_id=nil)
19
+
19
20
  DMAO::API.configure do |config|
20
21
  config.base_url = api_url
21
22
  config.api_token = api_token
22
23
  config.institution_id = institution_id
23
24
  end
25
+
26
+ if self.class::ENTITY.nil?
27
+ raise "Entity not set"
28
+ end
29
+
30
+ add_method_name = "add_#{self.class.entity_name.tr(' ', '_')}"
31
+ update_method_name = "update_#{self.class.entity_name.tr(' ', '_')}"
32
+ ingest_method_name = "ingest_#{self.class.entity_name.tr(' ', '_')}"
33
+
34
+ self.class.send(:define_method, add_method_name, Proc.new {|attributes| add_entity(attributes)}) unless self.respond_to?(add_method_name, include_all: true)
35
+ self.class.send(:define_method, update_method_name, Proc.new {|id, attributes| update_entity(id, attributes)}) unless self.respond_to?(update_method_name, include_all: true)
36
+ self.class.send(:define_method, ingest_method_name, Proc.new {|attributes={}| ingest_entity(attributes)}) unless self.respond_to?(ingest_method_name, include_all: true)
37
+
38
+ end
39
+
40
+ def self.entity_name
41
+ self::ENTITY.to_s.split('::')[-1].gsub(/[A-Z]/, " \\0").downcase.strip
24
42
  end
25
43
 
26
44
  def ingest
@@ -29,7 +47,7 @@ module DMAO
29
47
 
30
48
  def ingest_entity attributes = {}
31
49
 
32
- raise DMAO::Ingesters::Errors::EmptyAttributes.new("Cannot ingest #{entity_name} without attributes.") if attributes.nil? || attributes.empty?
50
+ raise DMAO::Ingesters::Errors::EmptyAttributes.new("Cannot ingest #{self.class.entity_name} without attributes.") if attributes.nil? || attributes.empty?
33
51
 
34
52
  begin
35
53
 
@@ -45,7 +63,7 @@ module DMAO
45
63
  rescue DMAO::API::Errors::EntityNotFound
46
64
  add_entity attributes
47
65
  rescue DMAO::API::Errors::InvalidResponseLength
48
- raise self.class::ENTITY_ERROR.new("More than one #{entity_name} returned for system uuid #{attributes[:system_uuid]}.")
66
+ raise self.class::ENTITY_ERROR.new("More than one #{self.class.entity_name} returned for system uuid #{attributes[:system_uuid]}.")
49
67
  end
50
68
 
51
69
  end
@@ -66,12 +84,14 @@ module DMAO
66
84
 
67
85
  end
68
86
 
87
+ private
88
+
69
89
  def add_entity attributes={}
70
90
 
71
91
  begin
72
92
  self.class::ENTITY.create attributes
73
93
  rescue DMAO::API::Errors::InstitutionNotFound
74
- raise self.class::ENTITY_ERROR.new("Institution not found, cannot ingest #{entity_name} to non-existent institution")
94
+ raise self.class::ENTITY_ERROR.new("Institution not found, cannot ingest #{self.class.entity_name} to non-existent institution")
75
95
  rescue self.class::INVALID_ENTITY_ERROR => e
76
96
  parse_unprocessable_errors(e.errors)
77
97
  end
@@ -83,17 +103,13 @@ module DMAO
83
103
  begin
84
104
  self.class::ENTITY.update entity_id, attributes
85
105
  rescue DMAO::API::Errors::EntityNotFound
86
- raise self.class::ENTITY_ERROR.new("#{entity_name.capitalize} not found, cannot update #{entity_name} that does not exist")
106
+ raise self.class::ENTITY_ERROR.new("#{self.class.entity_name.capitalize} not found, cannot update #{self.class.entity_name} that does not exist")
87
107
  rescue self.class::INVALID_ENTITY_ERROR => e
88
108
  parse_unprocessable_errors(e.errors)
89
109
  end
90
110
 
91
111
  end
92
112
 
93
- def entity_name
94
- self.class::ENTITY.to_s.split('::')[-1].gsub(/[A-Z]/, " \\0").strip.downcase
95
- end
96
-
97
113
  end
98
114
 
99
115
  end
@@ -16,10 +16,6 @@ module DMAO
16
16
  ENTITY_ERROR = DMAO::Ingesters::Errors::IngestOrganisationUnitError
17
17
  ENTITY_ERROR_MESSAGE = "Invalid organisation unit details"
18
18
 
19
- def ingest_organisation_unit attributes={}
20
- ingest_entity attributes
21
- end
22
-
23
19
  def link_child_to_parent child_system_uuid, parent_system_uuid
24
20
 
25
21
  child_unit = find_unit_or_raise_link_error child_system_uuid, "Organisation unit not found for child system uuid #{child_system_uuid}"
@@ -33,16 +29,6 @@ module DMAO
33
29
 
34
30
  end
35
31
 
36
- private
37
-
38
- def add_entity attributes
39
- add_organisation_unit attributes
40
- end
41
-
42
- def update_entity id, attributes
43
- update_organisation_unit id, attributes
44
- end
45
-
46
32
  def add_organisation_unit attributes
47
33
 
48
34
  begin
@@ -73,6 +59,16 @@ module DMAO
73
59
 
74
60
  end
75
61
 
62
+ protected
63
+
64
+ def add_entity attributes
65
+ add_organisation_unit attributes
66
+ end
67
+
68
+ def update_entity id, attributes
69
+ update_organisation_unit id, attributes
70
+ end
71
+
76
72
  def find_unit_or_raise_link_error unit_system_uuid, error_message
77
73
 
78
74
  begin
@@ -17,20 +17,6 @@ module DMAO
17
17
  INVALID_ENTITY_ERROR = DMAO::API::Errors::InvalidPerson
18
18
  ENTITY_ERROR_MESSAGE = "Invalid person details"
19
19
 
20
- def ingest_person attributes={}
21
- ingest_entity attributes
22
- end
23
-
24
- private
25
-
26
- def add_person attributes
27
- add_entity attributes
28
- end
29
-
30
- def update_person id, attributes
31
- update_entity id, attributes
32
- end
33
-
34
20
  end
35
21
 
36
22
  end
@@ -1,7 +1,7 @@
1
1
  module DMAO
2
2
  module Ingesters
3
3
  module Generic
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmao-generic-ingesters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Robinson