-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
296 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require "ostruct" | ||
begin | ||
require "dry-struct" | ||
rescue LoadError | ||
raise "The dry-struct gem is required for ConfigX::TypedConfig" | ||
end | ||
|
||
module ConfigX | ||
# The Config class extends OpenStruct to provide a flexible configuration object. | ||
class Config < OpenStruct | ||
include Configurable | ||
|
||
# @param members [Hash] the initial configuration hash | ||
# @raise [ArgumentError] if any of the keys are not convertible to strings | ||
def initialize(members) | ||
super({}) | ||
|
||
members.each do |key, value| | ||
raise ArgumentError, "option keys should be strings" unless key.respond_to?(:to_s) | ||
|
||
key = key.to_s | ||
class Config < Dry::Struct | ||
transform_keys(&:to_sym) | ||
|
||
if value.is_a?(Hash) | ||
value = self.class.new(value) | ||
elsif value.is_a?(Array) | ||
value = value.map do |element| | ||
element.is_a?(Hash) ? self.class.new(element) : element | ||
end | ||
end | ||
|
||
self[key] = value | ||
end | ||
|
||
freeze | ||
end | ||
|
||
# Converts the Config object to a hash. | ||
# | ||
# @return [Hash] the configuration as a hash | ||
def to_h | ||
each_pair.each_with_object({}) do |(key, value), hash| | ||
hash[key] = value.is_a?(self.class) ? value.to_h : value | ||
end | ||
end | ||
include Configurable | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require "deep_merge/core" | ||
|
||
module ConfigX | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require "ostruct" | ||
|
||
module ConfigX | ||
# The Config class extends OpenStruct to provide a flexible configuration object. | ||
class UntypedConfig < OpenStruct | ||
include Configurable | ||
|
||
# @param members [Hash] the initial configuration hash | ||
# @raise [ArgumentError] if any of the keys are not convertible to strings | ||
def initialize(members) | ||
super({}) | ||
|
||
members.each do |key, value| | ||
raise ArgumentError, "option keys should be strings" unless key.respond_to?(:to_s) | ||
|
||
key = key.to_s | ||
|
||
if value.is_a?(Hash) | ||
value = self.class.new(value) | ||
elsif value.is_a?(Array) | ||
value = value.map do |element| | ||
element.is_a?(Hash) ? self.class.new(element) : element | ||
end | ||
end | ||
|
||
self[key] = value | ||
end | ||
|
||
freeze | ||
end | ||
|
||
# Converts the Config object to a hash. | ||
# | ||
# @return [Hash] the configuration as a hash | ||
def to_h | ||
each_pair.each_with_object({}) do |(key, value), hash| | ||
hash[key] = value.is_a?(self.class) ? value.to_h : value | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.