dotsync 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 77b4b56e47651cc2c8ab828bb4c77db6d1e8e5e58fb36df1e00f2a2a30ded2e3
4
+ data.tar.gz: f0c445bb9a6436a3e0058e589fe0373015a41e1013109272b06b0d948bd1dc6c
5
+ SHA512:
6
+ metadata.gz: 73551d747d9687c969df56906d18354c133d1f947066fd3a2de3404512152a6f8fe07a6a0404556389da9702777615e4cf1b75b231f1cc3b14d84e6cceef5acd
7
+ data.tar.gz: 3bf4d314b25b8dfcc045c3dcf7a050ca09c33341acf6978717b218a43ca394b8fd416d1437e9b0ed7c27b304c65cbf2b8621482cf948683fe808dcd8282847f8
@@ -0,0 +1,41 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby: [3.2, 3.3]
16
+
17
+ name: Ruby ${{ matrix.ruby }} tests
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby }}
26
+ bundler-cache: true
27
+
28
+ - name: Run tests
29
+ run: |
30
+ bundle exec rake
31
+
32
+ - name: Publish to RubyGems
33
+ run: |
34
+ mkdir -p $HOME/.gem
35
+ touch $HOME/.gem/credentials
36
+ chmod 0600 $HOME/.gem/credentials
37
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
38
+ gem build *.gemspec
39
+ gem push *.gem
40
+ env:
41
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,23 @@
1
+ jobs:
2
+ build:
3
+ name: Build + Publish
4
+ runs-on: ubuntu-latest
5
+ permissions:
6
+ contents: read
7
+ packages: write
8
+
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+
12
+ - name: Publish to GPR
13
+ run: |
14
+ mkdir -p $HOME/.gem
15
+ touch $HOME/.gem/credentials
16
+ chmod 0600 $HOME/.gem/credentials
17
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
18
+ gem build *.gemspec
19
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
20
+ env:
21
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
22
+ OWNER: ${{ github.repository_owner }}
23
+
data/.gitignore ADDED
@@ -0,0 +1,11 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.1.0
2
+
3
+ Initial version
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dsaenz@bebanjo.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in dotsync.gemspec
6
+ gemspec
7
+
8
+ # gem "irb"
9
+ # gem "rake", "~> 13.0"
10
+ #
11
+ # gem "rspec", "~> 3.0"
12
+ #
13
+ # gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,113 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dotsync (0.1.0)
5
+ fileutils (~> 1.7.3)
6
+ listen (~> 3.9.0)
7
+ logger (~> 1.7.0)
8
+ ostruct (~> 0.6.3)
9
+ toml-rb (~> 4.0.0)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ ast (2.4.3)
15
+ citrus (3.0.2)
16
+ diff-lcs (1.6.2)
17
+ ffi (1.17.2)
18
+ ffi (1.17.2-aarch64-linux-gnu)
19
+ ffi (1.17.2-aarch64-linux-musl)
20
+ ffi (1.17.2-arm-linux-gnu)
21
+ ffi (1.17.2-arm-linux-musl)
22
+ ffi (1.17.2-arm64-darwin)
23
+ ffi (1.17.2-x86-linux-gnu)
24
+ ffi (1.17.2-x86-linux-musl)
25
+ ffi (1.17.2-x86_64-darwin)
26
+ ffi (1.17.2-x86_64-linux-gnu)
27
+ ffi (1.17.2-x86_64-linux-musl)
28
+ fileutils (1.7.3)
29
+ json (2.15.0)
30
+ language_server-protocol (3.17.0.5)
31
+ lint_roller (1.1.0)
32
+ listen (3.9.0)
33
+ rb-fsevent (~> 0.10, >= 0.10.3)
34
+ rb-inotify (~> 0.9, >= 0.9.10)
35
+ logger (1.7.0)
36
+ ostruct (0.6.3)
37
+ parallel (1.27.0)
38
+ parser (3.3.9.0)
39
+ ast (~> 2.4.1)
40
+ racc
41
+ prism (1.5.1)
42
+ racc (1.8.1)
43
+ rainbow (3.1.1)
44
+ rake (13.3.0)
45
+ rb-fsevent (0.11.2)
46
+ rb-inotify (0.11.1)
47
+ ffi (~> 1.0)
48
+ rbs (3.9.5)
49
+ logger
50
+ regexp_parser (2.11.3)
51
+ rspec (3.13.1)
52
+ rspec-core (~> 3.13.0)
53
+ rspec-expectations (~> 3.13.0)
54
+ rspec-mocks (~> 3.13.0)
55
+ rspec-core (3.13.5)
56
+ rspec-support (~> 3.13.0)
57
+ rspec-expectations (3.13.5)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.13.0)
60
+ rspec-mocks (3.13.5)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.13.0)
63
+ rspec-support (3.13.6)
64
+ rubocop (1.81.1)
65
+ json (~> 2.3)
66
+ language_server-protocol (~> 3.17.0.2)
67
+ lint_roller (~> 1.1.0)
68
+ parallel (~> 1.10)
69
+ parser (>= 3.3.0.2)
70
+ rainbow (>= 2.2.2, < 4.0)
71
+ regexp_parser (>= 2.9.3, < 3.0)
72
+ rubocop-ast (>= 1.47.1, < 2.0)
73
+ ruby-progressbar (~> 1.7)
74
+ unicode-display_width (>= 2.4.0, < 4.0)
75
+ rubocop-ast (1.47.1)
76
+ parser (>= 3.3.7.2)
77
+ prism (~> 1.4)
78
+ ruby-lsp (0.26.1)
79
+ language_server-protocol (~> 3.17.0)
80
+ prism (>= 1.2, < 2.0)
81
+ rbs (>= 3, < 5)
82
+ ruby-progressbar (1.13.0)
83
+ timecop (0.9.10)
84
+ toml-rb (4.0.0)
85
+ citrus (~> 3.0, > 3.0)
86
+ racc (~> 1.7)
87
+ unicode-display_width (3.2.0)
88
+ unicode-emoji (~> 4.1)
89
+ unicode-emoji (4.1.0)
90
+
91
+ PLATFORMS
92
+ aarch64-linux-gnu
93
+ aarch64-linux-musl
94
+ arm-linux-gnu
95
+ arm-linux-musl
96
+ arm64-darwin
97
+ ruby
98
+ x86-linux-gnu
99
+ x86-linux-musl
100
+ x86_64-darwin
101
+ x86_64-linux-gnu
102
+ x86_64-linux-musl
103
+
104
+ DEPENDENCIES
105
+ dotsync!
106
+ rake (~> 13.3.0)
107
+ rspec (~> 3.13.1)
108
+ rubocop (~> 1.81.1)
109
+ ruby-lsp (~> 0.26.1)
110
+ timecop (~> 0.9.10)
111
+
112
+ BUNDLED WITH
113
+ 2.7.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 David Sáenz
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,98 @@
1
+ # Dotsync
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/dotsync`. 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 'dotsync'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dotsync
22
+
23
+ ## Usage
24
+
25
+ ### Configuration
26
+
27
+ The configuration file now uses a single `mappings` structure where `src` can represent both files and folders. Here is an example configuration file:
28
+
29
+ ```toml
30
+ [pull]
31
+ mappings = [
32
+ { src = "$DOTFILES_DIR/config/", dest = "$XDG_CONFIG_HOME", force = false },
33
+ { src = "$DOTFILES_DIR/home/.zshenv", dest = "$HOME" }
34
+ ]
35
+
36
+ [push]
37
+ mappings = [
38
+ { src = "$HOME/.zshenv", dest = "$DOTFILES_DIR/home/.zshenv" },
39
+ { src = "$XDG_CONFIG_HOME/alacritty", dest = "$DOTFILES_DIR/config/alacritty" },
40
+ { src = "$XDG_CONFIG_HOME/brewfile", dest = "$DOTFILES_DIR/config/brewfile" },
41
+ { src = "$XDG_CONFIG_HOME/exercism", dest = "$DOTFILES_DIR/config/exercism" },
42
+ { src = "$XDG_CONFIG_HOME/git", dest = "$DOTFILES_DIR/config/git" },
43
+ { src = "$XDG_CONFIG_HOME/nvim", dest = "$DOTFILES_DIR/config/nvim", ignore = "lazy-lock.json" },
44
+ { src = "$XDG_CONFIG_HOME/zellij", dest = "$DOTFILES_DIR/config/zellij" },
45
+ { src = "$XDG_CONFIG_HOME/zsh", dest = "$DOTFILES_DIR/config/zsh", ignore = [".zsh_sessions", ".zsh_history"] },
46
+ { src = "$XDG_CONFIG_HOME/starship.toml", dest = "$DOTFILES_DIR/config/starship.toml" },
47
+ { src = "$XDG_CONFIG_HOME/dotsync.toml", dest = "$DOTFILES_DIR/dotsync/macmini.toml" }
48
+ ]
49
+
50
+ [watch]
51
+ src = '~/.config'
52
+ dest = '~/Code/dotfiles/src/'
53
+ paths = [
54
+ '~/.config/alacritty/',
55
+ '~/.config/zellij/',
56
+ '~/.config/nvim/',
57
+ '~/.config/exercism/',
58
+ '~/.config/nvim/init.lua',
59
+ '~/.config/nvim/lua/',
60
+ '~/.config/nvim/after/'
61
+ ]
62
+ ```
63
+
64
+ ### Synchronization
65
+
66
+ To sync your configuration files, use the following commands:
67
+
68
+ - **Push**: Transfer dotfiles from your local machine to the destination repository.
69
+ ```shell
70
+ dotsync push
71
+ ```
72
+
73
+ - **Pull**: Synchronize dotfiles from the repository to your local machine.
74
+ ```shell
75
+ dotsync pull
76
+ ```
77
+
78
+ ### Development
79
+
80
+ 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.
81
+
82
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dsaenztagarro/dotsync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
91
+
92
+ ## Code of Conduct
93
+
94
+ Everyone interacting in the Dotsync project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dotsync/blob/master/CODE_OF_CONDUCT.md).
95
+
96
+ ## Rake tasks
97
+
98
+ List with `bundle exec rake -AT`
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ require 'dotsync'
5
+
6
+ # Load all tasks
7
+ Dir.glob(File.join(Gem.loaded_specs['dotsync'].full_gem_path, 'lib', 'dotsync', 'tasks', '**/*.rake')).each { |f| load f }
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |t|
10
+ # ENV['TEST_ENV'] = 'true'
11
+ end
12
+
13
+ task default: :spec
14
+
15
+ desc "hello task"
16
+ task :hello do
17
+ puts "hello world"
18
+ end
19
+
20
+ namespace :dotsync do
21
+ desc "Pull Dotfiles"
22
+ task :pull do
23
+ Dotsync::Runner.new.run(:pull)
24
+ end
25
+
26
+ desc "Push Dotfiles"
27
+ task :push do
28
+ Dotsync::Runner.new.run(:push)
29
+ end
30
+
31
+ desc "Watch Dotfiles"
32
+ task :watch do
33
+ Dotsync::Runner.new.run(:watch)
34
+ end
35
+ end
36
+
37
+ namespace :palette do
38
+ desc "Show palette background"
39
+ task :bg do
40
+ (0..255).each do |color|
41
+ print "\e[48;5;#{color}m #{color.to_s.rjust(3)} \e[0m"
42
+ puts if (color + 1) % 16 == 0
43
+ end
44
+ end
45
+
46
+ desc "Show palette foreground"
47
+ task :fg do
48
+ (0..255).each do |color|
49
+ print "\e[38;5;#{color}m\e[1m #{color.to_s.rjust(3)} \e[0m"
50
+ puts if (color + 1) % 16 == 0
51
+ end
52
+ end
53
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dotsync"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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/dotsync.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ require_relative "lib/dotsync/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "dotsync"
5
+ spec.version = Dotsync::VERSION
6
+ spec.authors = ["David Sáenz"]
7
+ spec.email = ["david.saenz.tagarro@gmail.com"]
8
+
9
+ spec.summary = "Manage dotfiles like a boss"
10
+ spec.description = "Keep in sync your dotfiles across machines with a single TOML file"
11
+ spec.homepage = "https://github.com/dsaenztagarro/dotsync"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = ">= 3.2.0"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/dsaenztagarro/dotsync"
17
+ spec.metadata["changelog_uri"] = "https://github.com/dsaenztagarro/dotsync/blob/master/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "toml-rb", "~> 4.0.0"
29
+ spec.add_dependency "listen", "~> 3.9.0"
30
+ spec.add_dependency "fileutils", "~> 1.7.3"
31
+ spec.add_dependency "logger", "~> 1.7.0" # No longer part of default gems from Ruby 3.5
32
+ spec.add_dependency "ostruct", "~> 0.6.3" # No longer part of default gems from Ruby 3.5
33
+ spec.add_development_dependency "rake", "~> 13.3.0"
34
+ spec.add_development_dependency "rspec", "~> 3.13.1"
35
+ spec.add_development_dependency "rubocop", "~> 1.81.1"
36
+ spec.add_development_dependency "timecop", "~> 0.9.10"
37
+ spec.add_development_dependency "ruby-lsp", "~> 0.26.1"
38
+ end
@@ -0,0 +1,43 @@
1
+ module Dotsync
2
+ class BaseAction
3
+ include Dotsync::PathUtils
4
+
5
+ extend Forwardable # def_delegator
6
+
7
+ attr_reader :logger
8
+ def_delegator :logger, :info
9
+ def_delegator :logger, :action
10
+
11
+ def initialize(config, logger)
12
+ @log_queue = Queue.new
13
+ @config = config
14
+ @logger = logger
15
+ setup_logger_thread
16
+ setup_signal_trap
17
+ end
18
+
19
+ def execute
20
+ raise NotImplementedError
21
+ end
22
+
23
+ private
24
+
25
+ def setup_signal_trap
26
+ Signal.trap("INT") do
27
+ @log_queue << { type: :info, message: "Shutting down gracefully...", icon: :bell }
28
+ exit
29
+ end
30
+ end
31
+
32
+ def setup_logger_thread
33
+ return if ENV['TEST_ENV'] == 'true'
34
+
35
+ Thread.new do
36
+ loop do
37
+ log_entry = @log_queue.pop
38
+ @logger.info(log_entry[:message], icon: log_entry[:icon])
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,68 @@
1
+ module Dotsync
2
+ # BaseConfig serves as an abstract class to define the structure
3
+ # and validation rules for configuration files in the Dotsync system.
4
+ class BaseConfig
5
+ include Dotsync::PathUtils
6
+
7
+ # Initialize the BaseConfig with the provided path.
8
+ # Loads the TOML configuration file and validates it.
9
+ #
10
+ # @param [String] path The file path to the configuration file.
11
+ def initialize(path = Dotsync.config_path)
12
+ absolute_path = File.expand_path(path)
13
+ @config = TomlRB.load_file(absolute_path)
14
+ validate!
15
+ end
16
+
17
+ private
18
+
19
+ # Validates the configuration file.
20
+ #
21
+ # @raise [NotImplementedError] if not implemented by a subclass.
22
+ def validate!
23
+ raise NotImplementedError
24
+ end
25
+
26
+ # Returns the name of the section to validate.
27
+ #
28
+ # @return [String] The section name.
29
+ # @raise [NotImplementedError] if not implemented by a subclass.
30
+ def section_name
31
+ raise NotImplementedError
32
+ end
33
+
34
+ # Retrieves the configuration section.
35
+ #
36
+ # @return [Hash] The section of the configuration file.
37
+ def section
38
+ @config[section_name]
39
+ end
40
+
41
+ # Validates if the required section is present in the configuration.
42
+ #
43
+ # @raise [Dotsync::ConfigError] if the section is missing.
44
+ def validate_section_present!
45
+ unless @config.key?(section_name)
46
+ raise_error "No [#{section_name}] section found in config file"
47
+ end
48
+ end
49
+
50
+ # Validates if a specific key is present in the section.
51
+ #
52
+ # @param [String] key The key to validate.
53
+ # @raise [Dotsync::ConfigError] if the key is missing.
54
+ def validate_key_present!(key)
55
+ unless section.key?(key)
56
+ raise_error "[#{section_name}] section does not include key '#{key}'"
57
+ end
58
+ end
59
+
60
+ # Raises a configuration error with the provided message.
61
+ #
62
+ # @param [String] message The error message to raise.
63
+ # @raise [Dotsync::ConfigError] Always raises this error with the given message.
64
+ def raise_error(message)
65
+ raise Dotsync::ConfigError, "Config Error: #{message}"
66
+ end
67
+ end
68
+ end