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.



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

def initialize
  @defaults = default_values
end

Instance Attribute Details

#defaultsObject (readonly)

Returns the value of attribute defaults.



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

def defaults
  @defaults
end

Class Method Details

.action_tracer_action_thresholdObject



116
117
118
# File 'lib/ting_yun/configuration/default_source.rb', line 116

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

.agent_enabledObject



110
111
112
113
114
# File 'lib/ting_yun/configuration/default_source.rb', line 110

def self.agent_enabled
  Proc.new {
    TingYun::Agent.config[:enabled]
  }
end

.app_nameObject



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

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

.audit_log_pathObject



88
89
90
91
92
# File 'lib/ting_yun/configuration/default_source.rb', line 88

def self.audit_log_path
  Proc.new {
    File.join(TingYun::Agent.config[:log_file_path], 'newrelic_audit.log')
  }
end

.config_pathObject



61
62
63
64
65
66
67
68
# File 'lib/ting_yun/configuration/default_source.rb', line 61

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ting_yun/configuration/default_source.rb', line 120

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



83
84
85
# File 'lib/ting_yun/configuration/default_source.rb', line 83

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

.empty_arrayObject



70
71
72
# File 'lib/ting_yun/configuration/default_source.rb', line 70

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

.frameworkObject



33
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
# File 'lib/ting_yun/configuration/default_source.rb', line 33

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
          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.



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

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

.portObject



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

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

Instance Method Details

#default_valuesObject



75
76
77
78
79
80
81
# File 'lib/ting_yun/configuration/default_source.rb', line 75

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