lib/ting_yun/configuration/manager.rb in tingyun_rpm-1.1.4.2 vs lib/ting_yun/configuration/manager.rb in tingyun_rpm-1.2.0

- old
+ new

@@ -3,16 +3,60 @@ require 'ting_yun/configuration/default_source' require 'ting_yun/configuration/environment_source' require 'ting_yun/configuration/yaml_source' require 'ting_yun/configuration/server_source' require 'ting_yun/configuration/manual_source' +require 'ting_yun/configuration' - module TingYun module Configuration class Manager + # module Arel + # module Visitors + # class Visitor + # def initialize + # @dispatch = get_dispatch_cache + # end + # + # def accept object + # visit object + # end + # + # private + # + # def self.dispatch_cache + # Hash.new do |hash, klass| + # hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}" + # end + # end + # + # def get_dispatch_cache + # self.class.dispatch_cache + # end + # + # def dispatch + # @dispatch + # end + # + # def visit object + # send dispatch[object.class], object + # rescue NoMethodError => e + # raise e if respond_to?(dispatch[object.class], true) + # superklass = object.class.ancestors.find { |klass| + # respond_to?(dispatch[klass], true) + # } + # raise(TypeError, "Cannot visit #{object.class}") unless superklass + # dispatch[object.class] = dispatch[superklass] + # retry + # end + # end + # end + # end + # 实现缓存的一种方式 + + def initialize reset_to_defaults end def [](key) @@ -29,30 +73,18 @@ def app_names if TingYun::Agent.config[:'nbs.auto_app_naming'] begin [::TingYun::Frameworks.framework.root.split('/').last] - rescue Exception => e - get_name + rescue + ::TingYun::Configuration.get_name end else - get_name + ::TingYun::Configuration.get_name end - end - def get_name - case TingYun::Agent.config[:app_name] - when Array then - TingYun::Agent.config[:app_name] - when String then - TingYun::Agent.config[:app_name].split(';') - else - [] - end - end - def reset_to_defaults @default_source = DefaultSource.new @environment_source = EnvironmentSource.new @yaml_source = nil @server_source = nil @@ -72,11 +104,11 @@ config_stack.each do |config| next unless config accessor = key.to_sym if config.has_key?(accessor) - return evaluated = evaluate_procs(config[accessor]) #if it's proc + return evaluate_procs(config[accessor]) #if it's proc end end nil end @@ -142,15 +174,12 @@ end reset_cache log_config(:add, source) - notify_finished_configuring if !was_finished && finished_configuring? + TingYun::Agent.instance.events.notify(:finished_configuring) if !was_finished && finished_configuring? end - def notify_finished_configuring - TingYun::Agent.instance.events.notify(:finished_configuring) - end def finished_configuring? !@server_source.nil? end \ No newline at end of file