Skip to content

Commit f59825c

Browse files
committed
Write necessary documentation for essential methods and classes
Make rubocop happy 👮
1 parent 5b4b559 commit f59825c

9 files changed

+36
-11
lines changed

.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Metrics/BlockLength:
1010
- "Gemfile"
1111
- "spec/**/*"
1212

13+
Metrics/LineLength:
14+
Max: 120
15+
1316
Style/BracesAroundHashParameters:
1417
EnforcedStyle: context_dependent
1518

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: false
33
language: ruby
44
cache: bundler
55
rvm:
6-
- 2.5.1
7-
- 2.4.4
8-
- 2.3.7
9-
before_install: gem install bundler -v 1.16.5
6+
- 2.5.3
7+
- 2.4.5
8+
- 2.3.8
9+
before_install: gem install bundler -v 1.17.0

Rakefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
require "bundler/gem_tasks"
44
require "rspec/core/rake_task"
5+
require "rubocop/rake_task"
6+
7+
RuboCop::RakeTask.new
58

69
RSpec::Core::RakeTask.new(:spec)
710

8-
task default: :spec
11+
task default: %i[rubocop spec]

lib/yabeda.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@
55
require "yabeda/version"
66
require "yabeda/dsl"
77

8+
# Extendable framework for collecting and exporting metrics from Ruby apps
89
module Yabeda
910
include DSL
1011

1112
class << self
13+
# @return [Hash<String, Yabeda::Metric>] All registered metrics
1214
def metrics
1315
@metrics ||= Concurrent::Hash.new
1416
end
1517

18+
# @return [Hash<String, Yabeda::BaseAdapter>] All loaded adapters
1619
def adapters
1720
@adapters ||= Concurrent::Hash.new
1821
end
1922

23+
# @return [Array<Proc>] All collectors for periodical retrieving of metrics
2024
def collectors
2125
@collectors ||= Concurrent::Array.new
2226
end
23-
27+
2428
# @param [Symbol] name
2529
# @param [BaseAdapter] instance
2630
def register_adapter(name, instance)

lib/yabeda/base_adapter.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
module Yabeda
4+
# Base class for adapters to particular monitoring systems
45
class BaseAdapter
56
def register!(metric)
67
case metric

lib/yabeda/dsl.rb

+12
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,44 @@
66
require "yabeda/histogram"
77

88
module Yabeda
9+
# DSL for ease of work with Yabeda
910
module DSL
1011
def self.included(base)
1112
base.extend ClassMethods
1213
end
1314

15+
# rubocop: disable Style/Documentation
1416
module ClassMethods
17+
# Block for grouping and simplifying configuration of related metrics
1518
def configure(&block)
1619
class_exec(&block)
1720
@group = nil
1821
end
1922

23+
# Define the actions that should be performed
2024
def collect(&block)
2125
::Yabeda.collectors.push(block)
2226
end
2327

28+
# Specify metric category or group for all consecutive metrics in this
29+
# +configure+ block.
30+
# On most adapters it is only adds prefix to the metric name but on some
31+
# (like NewRelic) it is treated individually and have special meaning.
2432
def group(group_name)
2533
@group = group_name
2634
end
2735

36+
# Register a growing-only counter
2837
def counter(*args, **kwargs)
2938
register(Counter.new(*args, **kwargs, group: @group))
3039
end
3140

41+
# Register a gauge
3242
def gauge(*args, **kwargs)
3343
register(Gauge.new(*args, **kwargs, group: @group))
3444
end
3545

46+
# Register an histogram
3647
def histogram(*args, **kwargs)
3748
register(Histogram.new(*args, **kwargs, group: @group))
3849
end
@@ -49,5 +60,6 @@ def register(metric)
4960
metric
5061
end
5162
end
63+
# rubocop: enable Style/Documentation
5264
end
5365
end

lib/yabeda/gauge.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Yabeda
4-
# Arbitrary value
4+
# Arbitrary value, can be changed in both sides
55
class Gauge < Metric
66
def set(tags, value)
77
values[tags] = value

lib/yabeda/histogram.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
module Yabeda
4+
# Base class for complex metric for measuring time values that allow to
5+
# calculate averages, percentiles, and so on.
46
class Histogram < Metric
57
option :buckets
68

spec/yabeda_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
expect(Yabeda::VERSION).not_to be nil
66
end
77

8-
it 'exposes the public api' do
9-
expect(Yabeda.metrics).to eq({})
10-
expect(Yabeda.adapters).to eq({})
11-
expect(Yabeda.collectors).to eq([])
8+
it "exposes the public api" do
9+
expect(described_class.metrics).to eq({})
10+
expect(described_class.adapters).to eq({})
11+
expect(described_class.collectors).to eq([])
1212
end
1313
end

0 commit comments

Comments
 (0)