Class: TingYun::Configuration::DefaultSource

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ting_yun/configuration/default_source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefaultSource

Returns a new instance of DefaultSource.



30
31
32
# File 'lib/ting_yun/configuration/default_source.rb', line 30

def initialize
  @defaults = default_values
end

Instance Attribute Details

#defaultsObject (readonly)

Returns the value of attribute defaults.



24
25
26
# File 'lib/ting_yun/configuration/default_source.rb', line 24

def defaults
  @defaults
end

Class Method Details

.action_tracer_action_thresholdObject



106
107
108
# File 'lib/ting_yun/configuration/default_source.rb', line 106

def self.action_tracer_action_threshold
  Proc.new { TingYun::Agent.config[:apdex_t] * 4 }
end

.app_nameObject



98
99
100
# File 'lib/ting_yun/configuration/default_source.rb', line 98

def self.app_name
  Proc.new { ::TingYun::Frameworks.framework.env }
end

.config_pathObject



64
65
66
67
68
69
70
71
# File 'lib/ting_yun/configuration/default_source.rb', line 64

def self.config_path
  Proc.new {
    found_path = TingYun::Agent.config[:config_search_paths].detect do |file|
      File.expand_path(file) if File.exist? file
    end
    found_path || ''
  }
end

.config_search_pathsObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ting_yun/configuration/default_source.rb', line 110

def self.config_search_paths
  Proc.new {
    paths = [
        File.join("config", "tingyun.yml"),
        File.join("tingyun.yml")
    ]

    if ::TingYun::Frameworks.framework.root
      paths << File.join(::TingYun::Frameworks.framework.root, "config", "tingyun.yml")
      paths << File.join(::TingYun::Frameworks.framework.root, "tingyun.yml")
    end

    if ENV["HOME"]
      paths << File.join(ENV["HOME"], ".tingyun", "tingyun.yml")
      paths << File.join(ENV["HOME"], "tingyun.yml")
    end

    # If we're packaged for warbler, we can tell from GEM_HOME
    if ENV["GEM_HOME"] && ENV["GEM_HOME"].end_with?(".jar!")
      app_name = File.basename(ENV["GEM_HOME"], ".jar!")
      paths << File.join(ENV["GEM_HOME"], app_name, "config", "tingyun.yml")
    end

    paths
  }
end

.dispatcherObject



86
87
88
# File 'lib/ting_yun/configuration/default_source.rb', line 86

def self.dispatcher
  Proc.new { ::TingYun::Frameworks.framework.local_env.discovered_dispatcher }
end

.empty_arrayObject



73
74
75
# File 'lib/ting_yun/configuration/default_source.rb', line 73

def self.empty_array
  Proc.new { [] }
end

.frameworkObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ting_yun/configuration/default_source.rb', line 34

def self.framework
  Proc.new {
    case
      when defined?(::TingYun::TEST) then
        :test
      when defined?(::Merb) && defined?(::Merb::Plugins) then
        :merb
      when defined?(::Rails::VERSION)
        case Rails::VERSION::MAJOR
          when 0..2
            :rails
          when 3
            :rails3
          when 4
            :rails4
          when 5
            :rails5
          else
            ::TingYun::Agent.logger.error "Detected unsupported Rails version #{Rails::VERSION::STRING}"
        end
      when defined?(::Sinatra) && defined?(::Sinatra::Base) then
        :sinatra
      when defined?(::TingYun::IA) then
        :external
      else
        :ruby
    end
  }
end

.normalize_json_string_encodingsObject

On Rubies with string encodings support (1.9.x+), default to always normalize encodings since it’s safest and fast. Without that support the conversions are too expensive, so only enable if overridden to.



93
94
95
# File 'lib/ting_yun/configuration/default_source.rb', line 93

def self.normalize_json_string_encodings
  Proc.new { TingYun::Support::LanguageSupport.supports_string_encodings? }
end

.portObject



102
103
104
# File 'lib/ting_yun/configuration/default_source.rb', line 102

def self.port
  Proc.new { TingYun::Agent.config[:ssl] ? 443 : 80 }
end

Instance Method Details

#default_valuesObject



78
79
80
81
82
83
84
# File 'lib/ting_yun/configuration/default_source.rb', line 78

def default_values
  result = {}
  ::TingYun::Configuration::DEFAULTS.each do |key, value|
    result[key] = value[:default]
  end
  result
end