Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on ActiveSupport #27

Merged
merged 1 commit into from
Jan 28, 2020
Merged
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
1 change: 0 additions & 1 deletion consult.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
spec.executables = ['consult']
spec.require_paths = ['lib']

spec.add_dependency 'activesupport', '> 4', '< 6'
spec.add_dependency 'diplomat', '~> 2.0.2'
spec.add_dependency 'vault', '>= 0.10.0', '< 1.0.0'

Expand Down
4 changes: 2 additions & 2 deletions lib/consult.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

require 'pathname'
require 'yaml'
require 'active_support/core_ext/hash'
require 'erb'
require 'vault'
require 'diplomat'

require 'consult/version'
require 'consult/utilities'
require 'consult/template'
require_relative './support/hash_extensions'

module Consult
@config = {}
Expand Down Expand Up @@ -45,7 +45,7 @@ def configure_consul
@config[:consul][:url] = ENV['CONSUL_HTTP_ADDR'] || configured_address || @config[:consul][:url]
# If a consul token exists, treat it as special
# See https://github.com/WeAreFarmGeek/diplomat/pull/160
(@config[:consul][:options] ||= {}).merge!(headers: {'X-Consul-Token' => consul_token}) if consul_token.present?
(@config[:consul][:options] ||= {}).merge!(headers: {'X-Consul-Token' => consul_token}) if consul_token.to_s.length > 0

Diplomat.configure do |c|
@config[:consul].each do |opt, val|
Expand Down
34 changes: 34 additions & 0 deletions lib/support/hash_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

# ActiveSupport's corresponding methods
# - https://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext/hash
module HashExtension
def deep_symbolize_keys!(object = self)
case object
when Hash
object.keys.each do |key|
value = object.delete key
object[key.to_sym] = deep_symbolize_keys! value
end
object
when Array
object.map! { |e| deep_symbolize_keys! e }
else
object
end
end

def deep_merge(other_hash, &block)
merge(other_hash) do |key, this_val, other_val|
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
this_val.deep_merge other_val, &block
elsif block_given?
block.call key, this_val, other_val
else
other_val
end
end
end
end

Hash.send(:include, HashExtension)