petasos 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/petasos/location.rb +45 -39
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f8a7a7547d0f7abd9458a88a04c49a00e5b7b09a872d94727f47c39f4e9e941
4
- data.tar.gz: 0a2ae19945687b6e4ca55c898d03ce2dca5c0e6da95ec6ab1d14f78f2a8026e6
3
+ metadata.gz: bb6d3349efb1d5df1e59fb199b7ee742462e25ba5b0637b3d96ae837bfddbe6a
4
+ data.tar.gz: 055bbda229afefba11e1bdc79ce3d0b32cdce8fbfb9d62d6a2ba2f7663d0608a
5
5
  SHA512:
6
- metadata.gz: 23e7481f06bebcb2835342cee3afbb5fa18e0dce5e6401b03b2965cb5898ee7e225b7002622938e9aba45919ea88d0ab4d3c1abd582c591231ee90c0d1203584
7
- data.tar.gz: 97ad57afb7f8447919379d405952c810fd04a7c480a7aa1a215adc2f83779815ef5298be5ac7b7042d2bd1f07afe1f63d3c391c5fc208de3c74abd7915abeed4
6
+ metadata.gz: 9b683fe0a0cecf5685fbfaf459335b97bea7e69a34207ea90967235a415facdb996c8e0614d71417ce9dfc632df7b6a2e9121a43ad339cf83506e7094a014f5a
7
+ data.tar.gz: 8d73c62519cc0b98c566e8b27d51be01c3ca071488f21be3999a0ba407be4e212bf252af5c8e974b89dedcca6ed28f8528506c0d85c3d376d106874ef25c7614
@@ -13,13 +13,20 @@ class Petasos::Location
13
13
  end
14
14
 
15
15
  def run
16
- # delete exports file if completed file exists
17
- FileList.new(File.join(Dir.pwd, "exports_#{@config["name"]}*.yaml")).each do |export_file_path|
18
- completed_export_file_path = "completed-" + export_file_path
19
- `rm #{export_file_path}` if File.file?(completed_export_file_path)
20
- end
21
-
22
16
  pools.each do |pool|
17
+ # delete exports file if completed file exists
18
+ FileList.new(File.join(Dir.pwd, "exports_#{@config["name"]}_#{pool["name"]}_*.yaml")).each do |export_file_path|
19
+ completed_export_file_path = File.join(File.dirname(export_file_path), "completed-" + File.basename(export_file_path))
20
+ if File.file?(completed_export_file_path)
21
+ completed_files = YAML.load_file(completed_export_file_path)
22
+
23
+ process_lifecycle_hooks("after_export", pool, completed_files)
24
+ end
25
+ `mkdir -p logs`
26
+ `mv #{export_file_path} logs/`
27
+ `mv #{completed_export_file_path} logs/`
28
+ end
29
+
23
30
  # get all filenames in this location that belong to this pool
24
31
  current_files = current_pool_files(pool)
25
32
 
@@ -35,43 +42,42 @@ class Petasos::Location
35
42
  create_file_export_list(pool, new_files.to_a) if new_files.length > 0
36
43
  end
37
44
 
38
- # "after_seen" hooks
39
- if File.file?("petasos_after-seen.rb")
40
- require "./petasos_after-seen"
41
- # after seen for all files
42
- if defined?(after_seen_all)
43
- new_files.each do |file|
44
- after_seen_all(file)
45
- end
46
- end
45
+ process_lifecycle_hooks("after_seen", pool, new_files)
47
46
 
48
- # after seen for every file in this location
49
- location_hook = "after_seen_#{methodize(config["name"])}"
50
- if eval("defined?(#{location_hook})")
51
- new_files.each do |file|
52
- eval("#{location_hook}(\"#{file}\")")
53
- end
54
- end
47
+ # update list of seen files
48
+ # unless the location opts out
49
+ unless config["disable_seen"]
50
+ update_seen_pool_files(pool, seen_pool_files + new_files)
51
+ end
52
+ end
53
+ end
55
54
 
56
- # after seen for every file in this pool
57
- pool_hook = "after_seen_#{methodize(pool["name"])}"
58
- if eval("defined?(#{pool_hook})")
59
- new_files.each do |file|
60
- eval("#{pool_hook}(\"#{file}\")")
61
- end
62
- end
55
+ def process_lifecycle_hooks(hook_prefix, pool, files)
56
+ if File.file?("petasos_after-hooks.rb")
57
+ require "./petasos_after-hooks"
58
+ end
63
59
 
64
- # after seen for every file in this pool in this location
65
- location_and_pool_hook = "after_seen_#{methodize(config["name"])}_#{methodize(pool["name"])}"
66
- if eval("defined?(#{location_and_pool_hook})")
67
- new_files.each do |file|
68
- eval("#{location_and_pool_hook}(\"#{file}\")")
69
- end
70
- end
71
- end
60
+ # after seen for every file in this pool in this location
61
+ location_and_pool_hook = "#{hook_prefix}_#{methodize(config["name"])}_#{methodize(pool["name"])}"
62
+ check_if_defined_and_eval(location_and_pool_hook, files)
72
63
 
73
- # update list of seen files
74
- update_seen_pool_files(pool, seen_pool_files + new_files)
64
+ # after seen for every file in this pool
65
+ pool_hook = "#{hook_prefix}_#{methodize(pool["name"])}"
66
+ check_if_defined_and_eval(pool_hook, files)
67
+
68
+ # after seen for every file in this location
69
+ location_hook = "#{hook_prefix}_#{methodize(config["name"])}"
70
+ check_if_defined_and_eval(location_hook, files)
71
+
72
+ # after seen for all files
73
+ check_if_defined_and_eval("#{hook_prefix}_all", files)
74
+ end
75
+
76
+ def check_if_defined_and_eval(lifecycle_hook, files)
77
+ if eval("defined?(#{lifecycle_hook})")
78
+ files.each do |file|
79
+ eval("#{lifecycle_hook}(\"#{file}\")")
80
+ end
75
81
  end
76
82
  end
77
83
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petasos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Myers