awesome_backup 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e8adf991524a36db67665ca7b5b979450694d83f4b84b7b872108f296f72849e
4
+ data.tar.gz: 77a57034104bac734982dcb4ad7e9c242168031a0de3d0b995a8fee7612d6601
5
+ SHA512:
6
+ metadata.gz: 5eccebb1aeda734740ac0b3e4778006cc75197f71ea40bb89a81d413db3e3e598a835216ec978f5a1ee498a712d038986e2a60225fdf8df2342d179cfa06c036
7
+ data.tar.gz: 44bbd200454d3b122ee929bcf90f762022b1253586f185e73c6012cf2b78bb21ef69dcafd004c3b2638de521646b300ba646b2306d058568d47de2bd61462229
@@ -0,0 +1,20 @@
1
+ Copyright 2018 kaspernj
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # AwesomeBackup
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'awesome_backup'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install awesome_backup
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,23 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
7
+ require "rdoc/task"
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "AwesomeBackup"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.md")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
18
+ load "rails/tasks/engine.rake"
19
+
20
+
21
+ load "rails/tasks/statistics.rake"
22
+
23
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/awesome_backup .js
2
+ //= link_directory ../stylesheets/awesome_backup .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,3 @@
1
+ class AwesomeBackup::ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,2 @@
1
+ module AwesomeBackup::ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class AwesomeBackup::ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,10 @@
1
+ if defined?(Sidekiq)
2
+ # This class can be used with Sidekiq Scheduler
3
+ class AwesomeBackup::PostgresBackupSidekiqJob
4
+ include Sidekiq::Worker
5
+
6
+ def perform
7
+ AwesomeBackup::PostgresBackupService.execute!
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ class AwesomeBackup::ApplicationMailer < ActionMailer::Base
2
+ default from: "from@example.com"
3
+ layout "mailer"
4
+ end
@@ -0,0 +1,3 @@
1
+ class AwesomeBackup::ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,3 @@
1
+ class AwesomeBackup::PostgresBackup < AwesomeBackup::ApplicationRecord
2
+ has_one_attached :file
3
+ end
@@ -0,0 +1,2 @@
1
+ class AwesomeBackup::ApplicationService < ServicePattern::Service
2
+ end
@@ -0,0 +1,54 @@
1
+ require "English"
2
+
3
+ class AwesomeBackup::PostgresBackupService < AwesomeBackup::ApplicationService
4
+ def execute
5
+ result = `#{pg_dump_command} > \"#{tempfile_path}\"`
6
+ raise "Command failed: #{result}" unless $CHILD_STATUS.exitstatus.zero?
7
+
8
+ backup = AwesomeBackup::PostgresBackup.create!
9
+ backup.file.attach(
10
+ io: File.open(tempfile_path),
11
+ filename: "database.dump"
12
+ )
13
+
14
+ succeed!(backup: backup)
15
+ end
16
+
17
+ private
18
+
19
+ def database_config
20
+ @database_config ||= Rails.configuration.database_configuration.fetch(Rails.env)
21
+ end
22
+
23
+ def pg_dump_command
24
+ command = "pg_dump --format=c"
25
+ command << pg_dump_username_argument.to_s
26
+ command << pg_dump_host_argument.to_s
27
+ command << pg_dump_port_argument.to_s
28
+
29
+ if database_config["password"].present?
30
+ command.prepend("PGPASSWORD=\"#{database_config.fetch("password")}\" ")
31
+ else
32
+ command << " --no-password"
33
+ end
34
+
35
+ command << " \"#{database_config.fetch("database")}\""
36
+ command
37
+ end
38
+
39
+ def pg_dump_host_argument
40
+ " \"--host=#{database_config.fetch("host")}\"" if database_config["host"].present?
41
+ end
42
+
43
+ def pg_dump_port_argument
44
+ " \"--port=#{database_config.fetch("port")}\"" if database_config["port"].present?
45
+ end
46
+
47
+ def pg_dump_username_argument
48
+ " -U \"#{database_config.fetch("username")}\"" if database_config["username"].present?
49
+ end
50
+
51
+ def tempfile_path
52
+ @tempfile_path ||= "#{Dir.tmpdir}/#{SecureRandom.hex}.dump"
53
+ end
54
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Awesome backup</title>
5
+ <%= stylesheet_link_tag "awesome_backup/application", media: "all" %>
6
+ <%= javascript_include_tag "awesome_backup/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,2 @@
1
+ AwesomeBackup::Engine.routes.draw do
2
+ end
@@ -0,0 +1,5 @@
1
+ class CreatePostgresBackups < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :awesome_backup_postgres_backups, &:timestamps
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require "awesome_backup/engine"
2
+ require "service_pattern"
3
+
4
+ module AwesomeBackup
5
+ end
@@ -0,0 +1,5 @@
1
+ module AwesomeBackup; end
2
+
3
+ class AwesomeBackup::Engine < ::Rails::Engine
4
+ isolate_namespace AwesomeBackup
5
+ end
@@ -0,0 +1,3 @@
1
+ module AwesomeBackup
2
+ VERSION = "0.0.0".freeze
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :awesome_backup do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awesome_backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - kaspernj
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: service_pattern
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_bot_rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pg
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: tzinfo-data
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Make backups of your stuff in a simple way.
168
+ email:
169
+ - kaspernj@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - MIT-LICENSE
175
+ - README.md
176
+ - Rakefile
177
+ - app/assets/config/awesome_backup_manifest.js
178
+ - app/assets/javascripts/awesome_backup/application.js
179
+ - app/assets/stylesheets/awesome_backup/application.css
180
+ - app/controllers/awesome_backup/application_controller.rb
181
+ - app/helpers/awesome_backup/application_helper.rb
182
+ - app/jobs/awesome_backup/application_job.rb
183
+ - app/jobs/awesome_backup/postgres_backup_sidekiq_job.rb
184
+ - app/mailers/awesome_backup/application_mailer.rb
185
+ - app/models/awesome_backup/application_record.rb
186
+ - app/models/awesome_backup/postgres_backup.rb
187
+ - app/services/awesome_backup/application_service.rb
188
+ - app/services/awesome_backup/postgres_backup_service.rb
189
+ - app/views/layouts/awesome_backup/application.html.erb
190
+ - config/routes.rb
191
+ - db/migrate/20180526184050_create_postgres_backups.rb
192
+ - lib/awesome_backup.rb
193
+ - lib/awesome_backup/engine.rb
194
+ - lib/awesome_backup/version.rb
195
+ - lib/tasks/awesome_backup_tasks.rake
196
+ homepage: https://github.com/kaspernj/awesome_backup
197
+ licenses:
198
+ - MIT
199
+ metadata: {}
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ requirements: []
215
+ rubygems_version: 3.0.6
216
+ signing_key:
217
+ specification_version: 4
218
+ summary: Make backups of your stuff in a simple way.
219
+ test_files: []