rustic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87aaad479d9e91bcd7181431cc2f8375b4430c1031037577267fac7432fcf69a
4
+ data.tar.gz: e75eb8091276f16c57be19d526d64bf546010bff1b2e96925438cf1932a18d53
5
+ SHA512:
6
+ metadata.gz: 22783cede44b8c30a8f93e1877928b225de776b36269b1bbcf35fefd21b1d3ce10f10650029a2143d06abc6175b0ec2c513965b3ea308c192dff8950bbb9a6d6
7
+ data.tar.gz: 02af5b50df986baa80294f7d4efb7db2432017bcc4a511bd5cad3de143b83a58cb74290eb14f0d8b1c529ecd50d2f6e94a839910f4dde02d096203e88d9490d6
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.1
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.15
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ backup.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,43 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ require:
7
+ - rubocop-performance
8
+ - rubocop-rspec
9
+
10
+ Layout/LineLength:
11
+ Max: 120
12
+ Exclude:
13
+ - spec/**/*_spec.rb
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - spec/**/*_spec.rb
18
+
19
+ RSpec/NamedSubject:
20
+ Enabled: false
21
+
22
+ Style/StringLiterals:
23
+ Enabled: true
24
+ EnforcedStyle: double_quotes
25
+
26
+ Style/StringLiteralsInInterpolation:
27
+ Enabled: true
28
+ EnforcedStyle: double_quotes
29
+
30
+ Style/Documentation:
31
+ Enabled: false
32
+
33
+ Style/ClassAndModuleChildren:
34
+ EnforcedStyle: compact
35
+
36
+ RSpec/NestedGroups:
37
+ Max: 5
38
+
39
+ RSpec/MultipleMemoizedHelpers:
40
+ Max: 9
41
+
42
+ RSpec/ExampleLength:
43
+ Max: 6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-18
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at zhulik.gleb@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rustic.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "async-rspec"
13
+ gem "rubocop"
14
+ gem "rubocop-performance"
15
+ gem "rubocop-rspec"
16
+ gem "simplecov"
17
+ gem "solargraph"
data/Gemfile.lock ADDED
@@ -0,0 +1,128 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rustic (0.1.0)
5
+ async-process (~> 1.3)
6
+ zeitwerk (~> 2.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ async (1.30.1)
13
+ console (~> 1.10)
14
+ nio4r (~> 2.3)
15
+ timers (~> 4.1)
16
+ async-io (1.32.2)
17
+ async
18
+ async-process (1.3.1)
19
+ async
20
+ async-io
21
+ async-rspec (1.16.1)
22
+ rspec (~> 3.0)
23
+ rspec-files (~> 1.0)
24
+ rspec-memory (~> 1.0)
25
+ backport (1.2.0)
26
+ benchmark (0.2.0)
27
+ console (1.13.1)
28
+ fiber-local
29
+ diff-lcs (1.4.4)
30
+ docile (1.4.0)
31
+ e2mmap (0.1.0)
32
+ fiber-local (1.0.0)
33
+ jaro_winkler (1.5.4)
34
+ kramdown (2.3.1)
35
+ rexml
36
+ kramdown-parser-gfm (1.1.0)
37
+ kramdown (~> 2.0)
38
+ nio4r (2.5.8)
39
+ nokogiri (1.12.5-x86_64-linux)
40
+ racc (~> 1.4)
41
+ parallel (1.21.0)
42
+ parser (3.0.2.0)
43
+ ast (~> 2.4.1)
44
+ racc (1.6.0)
45
+ rainbow (3.0.0)
46
+ rake (13.0.6)
47
+ regexp_parser (2.1.1)
48
+ reverse_markdown (2.1.1)
49
+ nokogiri
50
+ rexml (3.2.5)
51
+ rspec (3.10.0)
52
+ rspec-core (~> 3.10.0)
53
+ rspec-expectations (~> 3.10.0)
54
+ rspec-mocks (~> 3.10.0)
55
+ rspec-core (3.10.1)
56
+ rspec-support (~> 3.10.0)
57
+ rspec-expectations (3.10.1)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.10.0)
60
+ rspec-files (1.1.1)
61
+ rspec (~> 3.0)
62
+ rspec-memory (1.0.2)
63
+ rspec (~> 3.0)
64
+ rspec-mocks (3.10.2)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.10.0)
67
+ rspec-support (3.10.3)
68
+ rubocop (1.23.0)
69
+ parallel (~> 1.10)
70
+ parser (>= 3.0.0.0)
71
+ rainbow (>= 2.2.2, < 4.0)
72
+ regexp_parser (>= 1.8, < 3.0)
73
+ rexml
74
+ rubocop-ast (>= 1.12.0, < 2.0)
75
+ ruby-progressbar (~> 1.7)
76
+ unicode-display_width (>= 1.4.0, < 3.0)
77
+ rubocop-ast (1.13.0)
78
+ parser (>= 3.0.1.1)
79
+ rubocop-performance (1.12.0)
80
+ rubocop (>= 1.7.0, < 2.0)
81
+ rubocop-ast (>= 0.4.0)
82
+ rubocop-rspec (2.6.0)
83
+ rubocop (~> 1.19)
84
+ ruby-progressbar (1.11.0)
85
+ simplecov (0.21.2)
86
+ docile (~> 1.1)
87
+ simplecov-html (~> 0.11)
88
+ simplecov_json_formatter (~> 0.1)
89
+ simplecov-html (0.12.3)
90
+ simplecov_json_formatter (0.1.3)
91
+ solargraph (0.44.0)
92
+ backport (~> 1.2)
93
+ benchmark
94
+ bundler (>= 1.17.2)
95
+ diff-lcs (~> 1.4)
96
+ e2mmap
97
+ jaro_winkler (~> 1.5)
98
+ kramdown (~> 2.3)
99
+ kramdown-parser-gfm (~> 1.1)
100
+ parser (~> 3.0)
101
+ reverse_markdown (>= 1.0.5, < 3)
102
+ rubocop (>= 0.52)
103
+ thor (~> 1.0)
104
+ tilt (~> 2.0)
105
+ yard (~> 0.9, >= 0.9.24)
106
+ thor (1.1.0)
107
+ tilt (2.0.10)
108
+ timers (4.3.3)
109
+ unicode-display_width (2.1.0)
110
+ yard (0.9.26)
111
+ zeitwerk (2.5.1)
112
+
113
+ PLATFORMS
114
+ x86_64-linux
115
+
116
+ DEPENDENCIES
117
+ async-rspec
118
+ rake (~> 13.0)
119
+ rspec (~> 3.0)
120
+ rubocop
121
+ rubocop-performance
122
+ rubocop-rspec
123
+ rustic!
124
+ simplecov
125
+ solargraph
126
+
127
+ BUNDLED WITH
128
+ 2.2.27
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Gleb Sinyavskiy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rustic
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rustic`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rustic'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rustic
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rustic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rustic/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Rustic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rustic/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rustic"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/rustic ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rustic"
5
+
6
+ Async::Reactor.run do
7
+ Rustic::CLI.new(ARGV).run
8
+ end
data/lib/rustic/cli.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::CLI
4
+ def initialize(argv)
5
+ @argv = argv
6
+ end
7
+
8
+ def run
9
+ case @argv.first
10
+ when "script"
11
+ config = Rustic::Script::Reader.new(@argv[1]).read
12
+ Rustic::Script::Evaluator.new(config).evaluate
13
+
14
+ else
15
+ Rustic::Wrapper.new(["restic", *@argv]).run
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::Script::BackupConfig
4
+ include Rustic::Script::HooksExt
5
+
6
+ attr_reader :paths, :excluded_paths, :one_fs
7
+
8
+ def initialize
9
+ @paths = []
10
+ @excluded_paths = []
11
+ @one_fs = false
12
+ end
13
+
14
+ def backup(*paths)
15
+ raise ArgumentError if paths.empty?
16
+
17
+ @paths = paths
18
+ end
19
+
20
+ def exclude(*paths)
21
+ raise ArgumentError if paths.empty?
22
+
23
+ @excluded_paths = paths
24
+ end
25
+
26
+ def one_fs!
27
+ @one_fs = true
28
+ end
29
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::Script::CommandBuilder
4
+ class UnknownPasswordMethodError < Rustic::Error; end
5
+ class UnknownCommandError < Rustic::Error; end
6
+ class MissingConfigError < Rustic::Error; end
7
+ class MalformedConfigError < Rustic::Error; end
8
+
9
+ def initialize(command, config)
10
+ @command = command
11
+ @config = config
12
+ end
13
+
14
+ def build
15
+ @args = []
16
+ @env_variables = {}
17
+
18
+ add_repository_path!
19
+ add_password!
20
+
21
+ add_command!
22
+
23
+ [[@config.restic_path, *@args], @env_variables] # TODO: properly handle spaces in paths
24
+ end
25
+
26
+ private
27
+
28
+ def add_repository_path! = @args += ["-r", @config.repository]
29
+
30
+ def add_password!
31
+ return @env_variables.merge!("RESTIC_PASSWORD" => @config.password) if @config.password
32
+ return @env_variables.merge!("RESTIC_PASSWORD_FILE" => @config.password_file) if @config.password_file
33
+
34
+ raise UnknownPasswordMethodError
35
+ end
36
+
37
+ def add_command!
38
+ command_method = "command_#{@command}"
39
+ return @args.concat(send(command_method)) if respond_to?(command_method, true)
40
+
41
+ raise UnknownCommandError, "Unknown command #{@command}"
42
+ end
43
+
44
+ def excludes = ["--exclude"].product(@config.backup_config.excluded_paths).flatten
45
+
46
+ def command_snapshots = ["snapshots"]
47
+
48
+ def command_backup
49
+ config = @config.backup_config
50
+ raise MissingConfigError, "Command `backup` misses it's configuration" if config.nil?
51
+ raise MalformedConfigError, "Backup paths cannot be empty" if config.paths.empty?
52
+
53
+ ["backup", config.one_fs ? "-x" : nil, *config.paths, *excludes].compact
54
+ end
55
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::Script::Config
4
+ include Rustic::Script::HooksExt
5
+
6
+ attr_reader :restic_path, :backup_config
7
+
8
+ def initialize
9
+ @restic_path = "restic"
10
+ end
11
+
12
+ def restic(path)
13
+ @restic_path = path
14
+ end
15
+
16
+ def repository(path = nil)
17
+ return @path if path.nil?
18
+
19
+ @path = path
20
+ end
21
+
22
+ def password(password = nil)
23
+ return @password if password.nil?
24
+
25
+ @password = password
26
+ end
27
+
28
+ def password_file(password_file = nil)
29
+ return @password_file if password_file.nil?
30
+
31
+ @password_file = password_file
32
+ end
33
+
34
+ def on_error(&block)
35
+ return @on_error if block.nil?
36
+
37
+ @on_error = block
38
+ end
39
+
40
+ def backup(&block)
41
+ @backup_config ||= Rustic::Script::BackupConfig.new
42
+ @backup_config.instance_eval(&block)
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::Script::Evaluator
4
+ include Console
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def evaluate
11
+ check!
12
+
13
+ with_hooks(@config) do
14
+ backup! unless @config.backup_config.nil?
15
+ end
16
+ rescue StandardError => e
17
+ on_error(e)
18
+ raise
19
+ end
20
+
21
+ def check!
22
+ command, env = Rustic::Script::CommandBuilder.new("snapshots", @config).build
23
+ Rustic::Wrapper.new(command, env).run
24
+ end
25
+
26
+ def on_error(error)
27
+ @config.on_error&.call(error)
28
+ end
29
+
30
+ def backup!
31
+ with_hooks(@config.backup_config) do
32
+ command, env = Rustic::Script::CommandBuilder.new("backup", @config).build
33
+ Rustic::Wrapper.new(command, env).run
34
+ end
35
+ end
36
+
37
+ def with_hooks(config, args = nil, &block)
38
+ Rustic::Script::Hooks.new(config).with_hooks(args, &block)
39
+ end
40
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::Script::Hooks
4
+ def initialize(config)
5
+ @before = config.before
6
+ @after = config.after
7
+ end
8
+
9
+ def with_hooks(arg = nil)
10
+ raise ArgumentError unless block_given?
11
+
12
+ @before&.call(arg)
13
+ yield
14
+ @after&.call(arg) # TODO: do not call the after block if an exception was raised
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rustic::Script::HooksExt
4
+ include Console
5
+
6
+ def before(&block)
7
+ return @before if block.nil?
8
+
9
+ @before = block
10
+ end
11
+
12
+ def after(&block)
13
+ return @after if block.nil?
14
+
15
+ @after = block
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::Script::Reader
4
+ class FileReadingError < Rustic::Error; end
5
+ class EvaluationError < Rustic::Error; end
6
+
7
+ def initialize(file_path)
8
+ @file_path = file_path
9
+ end
10
+
11
+ def read
12
+ Rustic::Script::Config.new.tap do |config|
13
+ config.instance_eval(script)
14
+ Rustic::Script::Validator.new(@config).validate!
15
+ end
16
+ rescue SyntaxError, NameError
17
+ raise EvaluationError
18
+ end
19
+
20
+ private
21
+
22
+ def script
23
+ @script ||= File.read(@file_path)
24
+ rescue StandardError
25
+ raise FileReadingError
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::Script::Validator
4
+ def initialize(config)
5
+ @config = config
6
+ end
7
+
8
+ def validate!
9
+ # TODO: write me!
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rustic
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rustic::Wrapper
4
+ include Console
5
+
6
+ class ExitStatusError < Rustic::Error; end
7
+ class ExecutionError < Rustic::Error; end
8
+
9
+ def initialize(argv, env_variables = {})
10
+ @argv = argv
11
+ @env_variables = env_variables
12
+ end
13
+
14
+ def run
15
+ logger.info(self, "Executing:", @argv)
16
+ begin
17
+ status = Async::Process.spawn(@env_variables, *@argv)
18
+ rescue StandardError
19
+ raise ExecutionError
20
+ end
21
+ return if status.exitstatus.zero? # TODO: check #success?
22
+
23
+ raise ExitStatusError, "Exit status is not 0: #{status.exitstatus}"
24
+ end
25
+ end
data/lib/rustic.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "async/process"
4
+
5
+ require "zeitwerk"
6
+
7
+ loader = Zeitwerk::Loader.for_gem
8
+
9
+ loader.inflector.inflect(
10
+ "cli" => "CLI"
11
+ )
12
+
13
+ loader.setup
14
+
15
+ # Your code goes here...
16
+ class Rustic::Error < StandardError
17
+ end
data/rustic.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rustic/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rustic"
7
+ spec.version = Rustic::VERSION
8
+ spec.authors = ["Gleb Sinyavskiy"]
9
+ spec.email = ["zhulik.gleb@gmail.com"]
10
+
11
+ spec.summary = "DSL for the restic backup tool."
12
+ spec.description = "DSL for the restic backup tool."
13
+ spec.homepage = "https://github.com/zhulik/rustic"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "async-process", "~> 1.3"
31
+ spec.add_dependency "zeitwerk", "~> 2.5"
32
+
33
+ # For more information and examples about making a new gem, checkout our
34
+ # guide at: https://bundler.io/guides/creating_gem.html
35
+ spec.metadata = {
36
+ "rubygems_mfa_required" => "true"
37
+ }
38
+ end
data/rustic.rb ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ repository "tmp/repository"
4
+
5
+ password "password"
6
+
7
+ before do
8
+ logger.info(self, "BEFORE")
9
+ end
10
+
11
+ backup do
12
+ one_fs!
13
+
14
+ before do |exists|
15
+ logger.info(self, "BEFORE BACKUP #{exists}")
16
+ end
17
+
18
+ after do
19
+ logger.info(self, "AFTER BACKUP")
20
+ end
21
+
22
+ backup "lib"
23
+ exclude "lib/rustic"
24
+ end
25
+
26
+ after do
27
+ logger.info(self, "AFTER")
28
+ end
29
+
30
+ on_error do |error|
31
+ logger.warn(self, "ERROR:", error)
32
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rustic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gleb Sinyavskiy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async-process
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: zeitwerk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ description: DSL for the restic backup tool.
42
+ email:
43
+ - zhulik.gleb@gmail.com
44
+ executables:
45
+ - rustic
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".github/workflows/main.yml"
50
+ - ".gitignore"
51
+ - ".rspec"
52
+ - ".rubocop.yml"
53
+ - CHANGELOG.md
54
+ - CODE_OF_CONDUCT.md
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/console
61
+ - bin/setup
62
+ - exe/rustic
63
+ - lib/rustic.rb
64
+ - lib/rustic/cli.rb
65
+ - lib/rustic/script/backup_config.rb
66
+ - lib/rustic/script/command_builder.rb
67
+ - lib/rustic/script/config.rb
68
+ - lib/rustic/script/evaluator.rb
69
+ - lib/rustic/script/hooks.rb
70
+ - lib/rustic/script/hooks_ext.rb
71
+ - lib/rustic/script/reader.rb
72
+ - lib/rustic/script/validator.rb
73
+ - lib/rustic/version.rb
74
+ - lib/rustic/wrapper.rb
75
+ - rustic.gemspec
76
+ - rustic.rb
77
+ homepage: https://github.com/zhulik/rustic
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ rubygems_mfa_required: 'true'
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 3.0.0
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.2.22
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: DSL for the restic backup tool.
101
+ test_files: []