From 390fccb82b332eb46a0e472882ea489f458af36d Mon Sep 17 00:00:00 2001 From: Gregory Schofield Date: Wed, 15 May 2024 09:18:43 -0400 Subject: [PATCH] Do some general cleanup and bump the version of ruby tested against. Signed-off-by: Gregory Schofield --- .github/workflows/main.yml | 2 +- Gemfile | 1 - Gemfile.lock | 39 +++++++++++++++++---------------- README.md | 44 +++++++++++++++++++++++++++++++++----- lib/boa/config.rb | 2 +- lib/boa/plugin/base.rb | 2 ++ 6 files changed, 64 insertions(+), 26 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 47fd776..ffe7c79 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: ruby: - - '3.1.2' + - '3.3.1' steps: - uses: actions/checkout@v3 diff --git a/Gemfile b/Gemfile index 6b411cf..72c358b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,6 @@ source "https://rubygems.org" -# Specify your gem's dependencies in Boa.gemspec gemspec group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 980f595..6575b8b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,34 +12,37 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) - json (2.6.3) - minitest (5.16.3) - parallel (1.22.1) - parser (3.1.3.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + minitest (5.22.3) + parallel (1.24.0) + parser (3.3.1.0) ast (~> 2.4.1) + racc + racc (1.7.3) rainbow (3.1.1) - rake (13.0.6) - regexp_parser (2.6.1) - rexml (3.2.5) - rubocop (1.41.1) + rake (13.2.1) + regexp_parser (2.9.1) + rexml (3.2.6) + rubocop (1.63.5) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.23.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.24.0) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) - unicode-display_width (2.3.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + ruby-progressbar (1.13.0) + unicode-display_width (2.5.0) PLATFORMS - arm64-darwin-21 + arm64-darwin-22 ruby - x86_64-linux DEPENDENCIES boa-config! @@ -49,4 +52,4 @@ DEPENDENCIES rubocop (~> 1.21) BUNDLED WITH - 2.3.26 + 2.5.9 diff --git a/README.md b/README.md index adef695..fadd3bf 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Natively boa supports: Boa also supports these configuration types via plugins: -- TOML +- (TOML)[https://github.com/gscho/boa-toml] ## Installation @@ -27,7 +27,7 @@ If bundler is not being used to manage dependencies, install the gem by executin ## Usage -Much like the Golang implementation, boa is meant to be used like a singleton class. By default, the boa singleton class is accessible via a global variable named `$boa`. +Much like the Golang implementation, boa is meant to be used as a singleton class. By default, the boa singleton class is accessible via a global variable named `$boa`. ### Setting Defaults @@ -85,20 +85,54 @@ port: 4567 host: localhost YAML $boa.read_config(config) -$boa.automatic_env $boa.get("host") # => "localhost" $boa.get("port") # => 9292 ``` ### Writing Config Files +Write out a config file `./write_config.yaml`: + +```ruby +config = <<-YAML +foo: "bar" +YAML +$boa.set_config_type("yaml") +$boa.read_config(config) +$boa.set_config_name("write_config") +$boa.write_config +``` + +Writing a config file to another directory: + +```ruby +config = <<-YAML +foo: "bar" +YAML +$boa.set_config_type("yaml") +$boa.read_config(config) +$boa.set_config_name("write_config") +$boa.add_config_path("/my/other/directory") +$boa.write_config +``` + ### Adding Plugins +To add a plugin, update your `Gemfile` or `gemspec` to add the new dependency and then `bundle install` + ### Writing Plugins +There is an example plugin called `foo` in the `test/fixtures` directory. + +At a high level: + +- The plugin must have a dependency on `boa` +- The plugin must have a file `lib/boa/plugin/boa_.rb` +- The plugin must implement `serialize` and `deserialze` functions + ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Boa. 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]/Boa/blob/main/CODE_OF_CONDUCT.md). +Bug reports and pull requests are welcome on GitHub at https://github.com/gscho/boa. 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/gscho/boa/blob/main/CODE_OF_CONDUCT.md). ## License @@ -106,4 +140,4 @@ The gem is available as open source under the terms of the [MIT License](https:/ ## Code of Conduct -Everyone interacting in the Boa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/Boa/blob/main/CODE_OF_CONDUCT.md). +Everyone interacting in the Boa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gscho/boa/blob/main/CODE_OF_CONDUCT.md). diff --git a/lib/boa/config.rb b/lib/boa/config.rb index ab752a3..2829625 100644 --- a/lib/boa/config.rb +++ b/lib/boa/config.rb @@ -136,7 +136,7 @@ def write_config_as(path) @type ||= File.extname(@name).delete_prefix(".") if @type.empty? raise BoaConfigError, - "Must provide an extension in the config name or explicitly set the config type" + "Must provide a file extension in the config name or explicitly set the config type" end file = "#{File.basename(@name, ".#{@type}")}.#{@type}" diff --git a/lib/boa/plugin/base.rb b/lib/boa/plugin/base.rb index 97c678a..8494bb5 100644 --- a/lib/boa/plugin/base.rb +++ b/lib/boa/plugin/base.rb @@ -4,6 +4,8 @@ module Boa module Plugin class Base def deserialize(data); end + + def serialize(config); end end end end