hanami-settings-stores 0.1.0 → 0.1.1

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: 7c8228cf550f63d29462cb128f2949d9fa9a744aac843fbac90a811a5d550ec4
4
- data.tar.gz: f4abd1d91b57a4946712d602f1f37d1274d5ac89dc2e2e18eeb5f756877e4875
3
+ metadata.gz: ce06f133c66bd28ca84dc455d158dea1037aafd6b09d5a3234a0c46f7ea4d7b3
4
+ data.tar.gz: 6a1353b35214301a89a3a43ccd34b580733c7a92e61fc32b0e2303ba1f4ec3fc
5
5
  SHA512:
6
- metadata.gz: 6986d005390d907eadd3342e78da83016f495c91c48dbd7c53ecdb84d0aa3979ed459d2f5307445ae2e358fdae9db1ffa8cda6ddc02813cd199c61f39a81440f
7
- data.tar.gz: bf07691cc6721383c34c095f4c8122ee0fc6724e970c2084db25cea20e3fa93d579f751d19a81bfbd299642e28cb4d8b2fa9fc7cf849c0fd6db6ff716b795c6e
6
+ metadata.gz: ba70b140ad251b828e18e1746e28bafedb8a40468b0fe49a0e80f40b1e7a27296880fabca5d6888d82928d801ed9788f7aa1846e9c3a61fcfbe975cb0e460ac4
7
+ data.tar.gz: '038e9c869bbff980f5eb563f412bf3c321ce61e216a2e269bf53e1e22eb58dd8180d2552b4dc1a3b9594cf3a0f691523dd443efb3c24d6c63920b3d7deba5afe'
data/CHANGELOG.md CHANGED
@@ -7,8 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ## v0.1.0 - 2026-03-17
10
+ ## [v0.1.1] - 2026-08-20
11
+
12
+ ### Added
13
+
14
+ - `FileStore` with json, toml, and yaml support
15
+
16
+ ### Removed
17
+
18
+ - removed unnecessary `hanami` gem as a runtime dependency
19
+
20
+ ## [v0.1.0] - 2026-03-17
11
21
 
12
22
  Initial release.
13
23
 
14
- [Unreleased]: https://github.com/aaronmallen/hanami-settings-stores/compare/v0.1.0...HEAD
24
+ [Unreleased]: https://github.com/aaronmallen/hanami-settings-stores/compare/0.1.1...HEAD
25
+ [v0.1.1]: https://github.com/aaronmallen/hanami-settings-stores/compare/0.1.0...0.1.1
26
+ [v0.1.0]: https://github.com/aaronmallen/hanami-settings-stores/releases/tag/0.1.0
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+
5
+ module Hanami
6
+ class Settings
7
+ # A settings store backed by a local JSON, TOML, or YAML file.
8
+ #
9
+ # The file is read and parsed once, when the store is built. Its contents run through ERB
10
+ # first, so a file can interpolate Ruby.
11
+ #
12
+ # Only top level keys resolve. Keys are compared as strings, so a setting named
13
+ # `:database_url` matches the `database_url` key in the file.
14
+ #
15
+ # @example
16
+ # # config/settings.yml
17
+ # database_url: postgres://localhost/myapp
18
+ # session_secret: <%= ENV.fetch("SESSION_SECRET") %>
19
+ #
20
+ # # config/app.rb
21
+ # config.settings_store = Hanami::Settings::CompositeStore.new(
22
+ # Hanami::Settings::EnvStore.new,
23
+ # Hanami::Settings::FileStore.new("config/settings.yml")
24
+ # )
25
+ #
26
+ # @api public
27
+ # @since 0.1.1
28
+ class FileStore
29
+ # @api private
30
+ # @since 0.1.1
31
+ JSON_EXTENSIONS = %w[.json].freeze
32
+ private_constant :JSON_EXTENSIONS
33
+
34
+ # @api private
35
+ # @since 0.1.1
36
+ TOML_EXTENSIONS = %w[.toml].freeze
37
+ private_constant :TOML_EXTENSIONS
38
+
39
+ # @api private
40
+ # @since 0.1.1
41
+ YAML_EXTENSIONS = %w[.yaml .yml].freeze
42
+ private_constant :YAML_EXTENSIONS
43
+
44
+ # @api private
45
+ # @since 0.1.1
46
+ EXTENSIONS = (JSON_EXTENSIONS + TOML_EXTENSIONS + YAML_EXTENSIONS).freeze
47
+ private_constant :EXTENSIONS
48
+
49
+ # @param filepath [String, Pathname] path to the settings file
50
+ # @raise [Errno::ENOENT] if the file does not exist
51
+ # @raise [ArgumentError] if the store cannot parse the file extension
52
+ def initialize(filepath)
53
+ source = ERB.new(File.read(filepath)).result
54
+ @settings = case File.extname(filepath.to_s)
55
+ when *JSON_EXTENSIONS
56
+ require "json"
57
+ JSON.parse(source)
58
+ when *TOML_EXTENSIONS
59
+ require "toml"
60
+ TOML::Parser.new(source).parsed
61
+ when *YAML_EXTENSIONS
62
+ require "yaml"
63
+ YAML.safe_load(source, aliases: true) || {}
64
+ else raise ArgumentError, "cannot parse #{filepath}: expected one of #{EXTENSIONS.join(", ")}"
65
+ end
66
+ end
67
+
68
+ # Fetches a setting value from the parsed file.
69
+ #
70
+ # @param name [String, Symbol] the setting name
71
+ # @param args [Array] optional default value
72
+ # @yield [name] optional block for default value
73
+ # @return [Object] the setting value
74
+ # @raise [KeyError] if the file has no such key and no default is given
75
+ #
76
+ # @api public
77
+ # @since 0.1.1
78
+ def fetch(name, *args, &block)
79
+ @settings.fetch(name.to_s, *args, &block)
80
+ end
81
+ end
82
+ end
83
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-settings-stores
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-17 00:00:00.000000000 Z
11
+ date: 2026-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: hanami
14
+ name: toml
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
19
+ version: '0.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2'
26
+ version: '0.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: zeitwerk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2'
41
- description: Pluggable settings stores that fetch secrets from password managers like
42
- 1Password and Bitwarden for use with Hanami::Settings.
41
+ description: Settings stores that fetch values from password managers like 1Password
42
+ and Bitwarden, or from a local JSON, TOML, or YAML file, for use with Hanami::Settings.
43
43
  email:
44
44
  - hello@aaronmallen.me
45
45
  executables: []
@@ -51,6 +51,7 @@ files:
51
51
  - lib/hanami-settings-stores.rb
52
52
  - lib/hanami/settings/bitwarden_store.rb
53
53
  - lib/hanami/settings/composite_store.rb
54
+ - lib/hanami/settings/file_store.rb
54
55
  - lib/hanami/settings/one_password_store.rb
55
56
  homepage: https://github.com/aaronmallen/hanami-settings-stores
56
57
  licenses:
@@ -79,5 +80,5 @@ requirements: []
79
80
  rubygems_version: 3.4.19
80
81
  signing_key:
81
82
  specification_version: 4
82
- summary: Password manager-backed settings stores for Hanami
83
+ summary: Pluggable settings stores for Hanami
83
84
  test_files: []