petasos 0.1.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 +51 -8
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b1ffed36c52ec275b881ac07ff08b6dda3d4446ba8c2ab0b74266698044b7e6
4
- data.tar.gz: 3b42c94a62222b7f133c4fe0ed5caea15d1623bc49f1c953b07c9c7bf1fb64fe
3
+ metadata.gz: bb6d3349efb1d5df1e59fb199b7ee742462e25ba5b0637b3d96ae837bfddbe6a
4
+ data.tar.gz: 055bbda229afefba11e1bdc79ce3d0b32cdce8fbfb9d62d6a2ba2f7663d0608a
5
5
  SHA512:
6
- metadata.gz: 93023bc9d2cad8a5be3bf800683264b7ef20247b3824c2191a6e75dc4c0c0a311b2c595dec10d1377b8e1e3152f1d141f7d5d9a39ea1d02b7c535014dada2adb
7
- data.tar.gz: 868e3587fc99dfd6a1cdc4b74d1ac5045d948f20b149bd7bb0294c72dfb2aa8d1afef0d6cd3a03ee1a11c02c4903b2fda2df818e076e336476126f34e7fdb1f6
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,10 +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
- # this is where the "after_seen" hooks would run
45
+ process_lifecycle_hooks("after_seen", pool, new_files)
39
46
 
40
47
  # update list of seen files
41
- update_seen_pool_files(pool, seen_pool_files + new_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
54
+
55
+ def process_lifecycle_hooks(hook_prefix, pool, files)
56
+ if File.file?("petasos_after-hooks.rb")
57
+ require "./petasos_after-hooks"
58
+ end
59
+
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)
63
+
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
42
81
  end
43
82
  end
44
83
 
@@ -114,4 +153,8 @@ class Petasos::Location
114
153
  YAML.dump(content, out)
115
154
  end
116
155
  end
156
+
157
+ def methodize(phrase)
158
+ phrase.gsub("-", "_")
159
+ end
117
160
  end
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Myers