harmonia 0.1.8 → 0.1.9

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
  SHA256:
3
- metadata.gz: 9b3d138727a59279aa27d27f45c4f829b6fb579aaff1fcb1f96f8c9af4de7a2c
4
- data.tar.gz: 11efb0c921eaa4d3781b475e386cd617f3bc029bc463e67f1c7be544caf4cdbe
3
+ metadata.gz: 60bf90e5016a52779a8cd3400aa7a92ebb510c8b4304a38d77b6b4891d255a41
4
+ data.tar.gz: 4a7a354befe4e2d0164e0c1cdd0a2d83769a5429f205da68816faa54c2bb34df
5
5
  SHA512:
6
- metadata.gz: 85bc5b955d18ffdc0e86b276d43de07589909517cb28dd1bdaeddb6039380d4987c2f8db02d6a429cb9ad5b75221ca5b23eb0e7f9f2c674482ab6c7b4ff428cb
7
- data.tar.gz: 0727cc7e6b2c6e8dcb2ebaf2a2934aa2e5cad18c3f6cfd8b4438dbc0ac6ccf5caf3b4774c6e482a51f75732c0b96e864f75ab19ee1c95fb43103bd980f09968a
6
+ metadata.gz: b9012312d892912d09d3bb214197ffbb388d0ab11940fd0df940c8f3b9beea4a54fa66b7dd51c0fa7b759e414b90c41cde8244d9cc716f9c25da123ff2256867
7
+ data.tar.gz: 70fb50a16c8fc7a998818d89522d88432b00ec23df2630781b1752ee2f67b294a5349008a981b9c99d4de6a9c7503d64651cc1c244def6c06f9f97b7ed18f781
@@ -17,6 +17,57 @@ module Harmonia
17
17
  migration_template "add_filemaker_id_to_table.rb", "db/migrate/add_filemaker_id_to_#{table_name}.rb"
18
18
  end
19
19
 
20
+ def create_or_update_rake_task
21
+ rake_file = "lib/tasks/sync_data.rake"
22
+ task_name = "sync_#{file_name}_to_filemaker"
23
+
24
+ if File.exist?(rake_file)
25
+ # Read existing file
26
+ content = File.read(rake_file)
27
+
28
+ # Add new task before the final 'end' if it doesn't exist
29
+ unless content.include?("task #{task_name}:")
30
+ # Add the new task before the final 'end'
31
+ new_task = <<~TASK
32
+
33
+ desc 'sync #{table_name} from ActiveRecord to FileMaker'
34
+ task #{task_name}: :environment do
35
+ #{class_name}ToFileMakerSyncer.new.sync
36
+ end
37
+ TASK
38
+
39
+ # Insert before the final 'end'
40
+ content = content.sub(/^end\s*$/, "#{new_task}end")
41
+
42
+ # Add task to the 'all' array
43
+ content = content.sub(/task all: %i\[(.*?)\]/) do
44
+ tasks = $1.split.map(&:to_sym)
45
+ tasks << task_name.to_sym unless tasks.include?(task_name.to_sym)
46
+ "task all: %i[#{tasks.join(' ')}]"
47
+ end
48
+
49
+ File.write(rake_file, content)
50
+ end
51
+ else
52
+ # Create new rake file
53
+ template "sync_data.rake", rake_file
54
+
55
+ # Add the new task
56
+ content = File.read(rake_file)
57
+ new_task = <<~TASK
58
+
59
+ desc 'sync #{table_name} from ActiveRecord to FileMaker'
60
+ task #{task_name}: :environment do
61
+ #{class_name}ToFileMakerSyncer.new.sync
62
+ end
63
+ TASK
64
+
65
+ content = content.sub(/^end\s*$/, "#{new_task}end")
66
+ content = content.sub(/task all: %i\[\]/, "task all: %i[#{task_name}]")
67
+ File.write(rake_file, content)
68
+ end
69
+ end
70
+
20
71
  def show_readme
21
72
  readme_content = <<~README
22
73
 
@@ -27,6 +78,7 @@ module Harmonia
27
78
  Files created:
28
79
  - app/syncers/#{file_name}_to_filemaker_syncer.rb
29
80
  - db/migrate/..._add_filemaker_id_to_#{table_name}.rb
81
+ - lib/tasks/sync_data.rake (updated with sync_#{file_name}_to_filemaker task)
30
82
 
31
83
  Next steps:
32
84
  1. Run migrations: rails db:migrate
@@ -58,6 +110,10 @@ module Harmonia
58
110
  Note: The total_required count used for sync tracking is automatically calculated
59
111
  from @total_create_required + @total_update_required
60
112
 
113
+ 7. Run the sync task:
114
+ - Individual sync: rake sync:sync_#{file_name}_to_filemaker
115
+ - All syncs: rake sync:all
116
+
61
117
  README
62
118
 
63
119
  say readme_content, :green if behavior == :invoke
@@ -17,6 +17,57 @@ module Harmonia
17
17
  migration_template "add_filemaker_id_to_table.rb", "db/migrate/add_filemaker_id_to_#{table_name}.rb"
18
18
  end
19
19
 
20
+ def create_or_update_rake_task
21
+ rake_file = "lib/tasks/sync_data.rake"
22
+ task_name = "sync_#{file_name}"
23
+
24
+ if File.exist?(rake_file)
25
+ # Read existing file
26
+ content = File.read(rake_file)
27
+
28
+ # Add new task before the final 'end' if it doesn't exist
29
+ unless content.include?("task #{task_name}:")
30
+ # Add the new task before the final 'end'
31
+ new_task = <<~TASK
32
+
33
+ desc 'sync #{table_name} from FileMaker to ActiveRecord'
34
+ task #{task_name}: :environment do
35
+ #{class_name}Syncer.new.sync
36
+ end
37
+ TASK
38
+
39
+ # Insert before the final 'end'
40
+ content = content.sub(/^end\s*$/, "#{new_task}end")
41
+
42
+ # Add task to the 'all' array
43
+ content = content.sub(/task all: %i\[(.*?)\]/) do
44
+ tasks = $1.split.map(&:to_sym)
45
+ tasks << task_name.to_sym unless tasks.include?(task_name.to_sym)
46
+ "task all: %i[#{tasks.join(' ')}]"
47
+ end
48
+
49
+ File.write(rake_file, content)
50
+ end
51
+ else
52
+ # Create new rake file
53
+ template "sync_data.rake", rake_file
54
+
55
+ # Add the new task
56
+ content = File.read(rake_file)
57
+ new_task = <<~TASK
58
+
59
+ desc 'sync #{table_name} from FileMaker to ActiveRecord'
60
+ task #{task_name}: :environment do
61
+ #{class_name}Syncer.new.sync
62
+ end
63
+ TASK
64
+
65
+ content = content.sub(/^end\s*$/, "#{new_task}end")
66
+ content = content.sub(/task all: %i\[\]/, "task all: %i[#{task_name}]")
67
+ File.write(rake_file, content)
68
+ end
69
+ end
70
+
20
71
  def show_readme
21
72
  readme_content = <<~README
22
73
 
@@ -27,6 +78,7 @@ module Harmonia
27
78
  Files created:
28
79
  - app/syncers/#{file_name}_syncer.rb
29
80
  - db/migrate/..._add_filemaker_id_to_#{table_name}.rb
81
+ - lib/tasks/sync_data.rake (updated with sync_#{file_name} task)
30
82
 
31
83
  Next steps:
32
84
  1. Run migrations: rails db:migrate
@@ -45,6 +97,10 @@ module Harmonia
45
97
  Note: The total_required count used for sync tracking is automatically calculated
46
98
  from @total_create_required + @total_update_required
47
99
 
100
+ 5. Run the sync task:
101
+ - Individual sync: rake sync:sync_#{file_name}
102
+ - All syncs: rake sync:all
103
+
48
104
  README
49
105
 
50
106
  say readme_content, :green if behavior == :invoke
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :sync do
4
+ desc 'sync all'
5
+ task all: %i[]
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harmonia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kempen Automatisering
@@ -43,6 +43,7 @@ files:
43
43
  - lib/generators/harmonia/templates/database_connector.rb
44
44
  - lib/generators/harmonia/templates/filemaker_to_activerecord_syncer_template.rb
45
45
  - lib/generators/harmonia/templates/harmonia_sync.rb
46
+ - lib/generators/harmonia/templates/sync_data.rake
46
47
  - lib/generators/harmonia/templates/trophonius_model_extension.rb
47
48
  - lib/harmonia.rb
48
49
  - lib/harmonia/railtie.rb