Created
March 23, 2018 19:04
-
-
Save rasouza/f9ec3f3072e522cf1bbdfa444c59c337 to your computer and use it in GitHub Desktop.
ConfigRecursive created by rasouza - https://repl.it/@rasouza/ConfigRecursive
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
require 'bundler/inline' | |
require './mock_classes' | |
gemfile true do | |
source 'http://rubygems.org' | |
gem 'config' | |
end | |
Config.load_and_set_settings(Config.setting_files(".", "dev")) | |
events = Settings.strategies.to_hash | |
def register_events_recursive(node, path = "", events = {}) | |
events[path[1..-1]][:strategy] = Object::const_get(node[:strategy]) if node.has_key?(:strategy) | |
events[path[1..-1]][:message] = Object::const_get(node[:message]) if node.has_key?(:message) | |
events[path[1..-1]][:sender] = Object::const_get(node[:sender]) if node.has_key?(:sender) | |
if (not node.has_key?(:strategy)) | |
node.each_pair do |k, v| | |
node[k] = register_events_recursive(v, "#{path}.#{k}", events) | |
end | |
end | |
node | |
end | |
new_events = {} | |
new_events.default_proc = proc { |hash, key| hash[key] = Hash.new } # creates Hash if key doesn't exist | |
events_chg = register_events_recursive(events, "", new_events) | |
p new_events |
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
class EmailStrategy | |
end | |
class BankAccountChangedMailMessage | |
end | |
class DefaultStrategy | |
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
log: | |
path: STDOUT | |
level: error | |
queue: | |
host: queue | |
name: messages | |
channel: jaime_topics | |
strategies: | |
bank_account: | |
changed: | |
strategy: EmailStrategy | |
message: BankAccountChangedMailMessage | |
default: | |
action: | |
strategy: DefaultStrategy | |
mandrill: | |
api_key: <%= ENV['MANDRILL_API_KEY'] %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment