Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,26 @@ jobs:
with:
coverageCommand: bundle exec appraisal rspec

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 4.0.1
bundler-cache: true

- name: Lint code for consistent style
run: bundle exec rubocop -f github

all-passed:
runs-on: ubuntu-latest
if: always()
needs:
- test
- lint
steps:
- run: exit ${{ contains(needs.*.result, 'failure') && 1 || 0 }}
12 changes: 12 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
AllCops:
NewCops: disable
Exclude:
- 'spec/app/**/*'
- 'gemfiles/**/*'

Metrics:
Enabled: false

Style/Documentation:
Enabled: false

Layout/LineLength:
Max: 120

Expand Down
6 changes: 1 addition & 5 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
max_ruby_version = ->(version) {
RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) <= Gem::Version.new(version)
}

min_ruby_version = ->(version) {
min_ruby_version = lambda { |version|
RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version)
}

Expand Down
11 changes: 5 additions & 6 deletions Rakefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ begin
require 'bundler/setup'

Bundler::GemHelper.install_tasks

rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

##
# Testing
#
require "rspec"
require "rspec/core/rake_task"
require 'rspec'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

# Test for multiple Rails scenarios
if !ENV['APPRAISAL_INITIALIZED'] && !ENV['GITHUB_ACTIONS']
require "appraisal"
require 'appraisal'

task :default => :appraisal
task default: :appraisal
else
task :default => :spec
task default: :spec
end

##
Expand Down
9 changes: 5 additions & 4 deletions config.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'English'
require_relative 'lib/config/version'
require_relative 'lib/config/dry_validation_requirements'

Expand All @@ -8,20 +9,20 @@ Gem::Specification.new do |s|
s.authors = ['Piotr Kuczynski', 'Fred Wu', 'Jacques Crocker']
s.email = %w[piotr.kuczynski@gmail.com ifredwu@gmail.com railsjedi@gmail.com]
s.summary = 'Effortless multi-environment settings in Rails, Sinatra, Padrino and others'
s.description = 'Easiest way to manage multi-environment settings in any ruby project or framework: ' +
s.description = 'Easiest way to manage multi-environment settings in any ruby project or framework: ' \
'Rails, Sinatra, Padrino and others'
s.homepage = 'https://github.com/rubyconfig/config'
s.license = 'MIT'
s.extra_rdoc_files = %w[README.md CHANGELOG.md CONTRIBUTING.md LICENSE.md]
s.rdoc_options = ['--charset=UTF-8']

s.metadata = {
'changelog_uri' => "https://github.com/rubyconfig/config/blob/master/CHANGELOG.md",
'changelog_uri' => 'https://github.com/rubyconfig/config/blob/master/CHANGELOG.md',
'funding_uri' => 'https://opencollective.com/rubyconfig/donate',
'source_code_uri' => 'https://github.com/rubyconfig/config',
'bug_tracker_uri' => 'https://github.com/rubyconfig/config/issues'
}
s.files = `git ls-files`.split($/)
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
s.files.select! { |file| /(^lib\/|^\w+.md$|\.gemspec$)/ =~ file }

s.require_paths = ['lib']
Expand All @@ -31,6 +32,7 @@ Gem::Specification.new do |s|
s.add_dependency 'ostruct'

s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.0'
s.add_development_dependency 'rubocop', '~> 1.84'

# Testing
s.add_development_dependency 'appraisal', '~> 2.5', '>= 2.5.0'
Expand All @@ -57,6 +59,5 @@ Gem::Specification.new do |s|
else
# Static code analysis to be used locally
s.add_development_dependency 'mdl', '~> 0.15', '>= 0.15.0'
s.add_development_dependency 'rubocop', '~> 1.84'
end
end
2 changes: 1 addition & 1 deletion lib/config/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Configuration < Module
# Accepts configuration options,
# initializing a module that can be used to extend
# the necessary class with the provided config methods
def initialize(**attributes)
def initialize(**attributes) # rubocop:disable Lint/MissingSuper
attributes.each do |name, default|
define_reader(name, default)
define_writer(name)
Expand Down
9 changes: 3 additions & 6 deletions lib/config/dry_validation_requirements.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

module Config
module DryValidationRequirements
VERSIONS = ['~> 1.0', '>= 1.0.0'].freeze
Expand All @@ -10,11 +8,10 @@ def self.load_dry_validation!
begin
require 'dry/validation/version'
version = Gem::Version.new(Dry::Validation::VERSION)
unless VERSIONS.all? { |req| Gem::Requirement.new(req).satisfied_by?(version) }
raise LoadError
end
raise LoadError unless VERSIONS.all? { |req| Gem::Requirement.new(req).satisfied_by?(version) }
rescue LoadError
raise ::Config::Error, "Could not find a dry-validation version matching requirements (#{VERSIONS.map(&:inspect) * ','})"
raise ::Config::Error,
"Could not find a dry-validation version matching requirements (#{VERSIONS.map(&:inspect) * ','})"
end

require 'dry/validation'
Expand Down
32 changes: 16 additions & 16 deletions lib/config/integrations/heroku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Config
module Integrations
class Heroku < Struct.new(:app)
Heroku = Struct.new(:app) do
def invoke
puts 'Setting vars...'
heroku_command = "config:set #{vars}"
Expand All @@ -14,14 +14,14 @@ def invoke
def vars
# Load only local options to Heroku
Config.load_and_set_settings(
Rails.root.join("config", "#{Config.file_name}.local.yml").to_s,
Rails.root.join("config", Config.dir_name, "#{environment}.local.yml").to_s,
Rails.root.join("config", "environments", "#{environment}.local.yml").to_s
Rails.root.join('config', "#{Config.file_name}.local.yml").to_s,
Rails.root.join('config', Config.dir_name, "#{environment}.local.yml").to_s,
Rails.root.join('config', 'environments', "#{environment}.local.yml").to_s
)

out = ''
dotted_hash = to_dotted_hash Kernel.const_get(Config.const_name).to_hash, {}, Config.const_name
dotted_hash.each {|key, value| out += " #{key}=#{value} "}
dotted_hash.each { |key, value| out += " #{key}=#{value} " }
out
end

Expand All @@ -30,7 +30,7 @@ def environment
end

def heroku(command)
with_app = app ? " --app #{app}" : ""
with_app = app ? " --app #{app}" : ''
`heroku #{command}#{with_app}`
end

Expand All @@ -41,16 +41,16 @@ def `(command)
def to_dotted_hash(source, target = {}, namespace = nil)
prefix = "#{namespace}." if namespace
case source
when Hash
source.each do |key, value|
to_dotted_hash(value, target, "#{prefix}#{key}")
end
when Array
source.each_with_index do |value, index|
to_dotted_hash(value, target, "#{prefix}#{index}")
end
else
target[namespace] = source
when Hash
source.each do |key, value|
to_dotted_hash(value, target, "#{prefix}#{key}")
end
when Array
source.each_with_index do |value, index|
to_dotted_hash(value, target, "#{prefix}#{index}")
end
else
target[namespace] = source
end
target
end
Expand Down
3 changes: 2 additions & 1 deletion lib/config/integrations/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def preload

# Parse the settings before any of the initializers
Config.load_and_set_settings(
Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym)
Config.setting_files(::Rails.root.join('config'),
Config.environment.nil? ? ::Rails.env : Config.environment.to_sym)
)
end

Expand Down
5 changes: 2 additions & 3 deletions lib/config/integrations/sinatra.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "config/rack/reloader"
require 'config/rack/reloader'

module Config
# provide helper to register within your Sinatra app
Expand All @@ -8,8 +8,7 @@ module Config
#
def self.registered(app)
app.configure do |inner_app|

env = inner_app.environment || ENV["RACK_ENV"]
env = inner_app.environment || ENV['RACK_ENV']
root = inner_app.root

# use Padrino settings if applicable
Expand Down
Loading