reportier 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 370f511dd07462a7eee6dbabe9ed0b69a1ad3871
4
- data.tar.gz: 7663e4fb47322832da7aa8cd42234200a5fe093c
3
+ metadata.gz: b2a6af84f7ba493c64deb711f1a16090b1536921
4
+ data.tar.gz: 70ab0f75ab322a914775a5410f309176ddc92c4d
5
5
  SHA512:
6
- metadata.gz: 0281eecb8827893f544d8e32bb0c833c7224b360932fa9fe1585abb3ea728eff8824b8d22e183a2885e2c2e77d48bfe1e8fe223076a692671c5034290728cc19
7
- data.tar.gz: 0e90955b777f0d2bb6c8a923126150f1506b04c74b6cc4c8c8290661cc6b2fedd695341f1a76b9b975c7e73682e5574ee331bb94f20929e4c33b9e769f2f4199
6
+ metadata.gz: 60c57b1a029518c684494c8142d9aacf49dad9c59fc4b8b3681e6b9987b1e5725017320f698a68f721210a71105c1b5aa34d25749a4c33f00867443c5bb54f3e
7
+ data.tar.gz: ef60218d7121948d4611fd7c2bcfd5c9bb2b92c7f7b29ae20debf13b5b4a03afd039be32e4eb2c9b2376e4305c0897a4ebd1f509763b4a5d27c653ffc6af5179
data/README.md CHANGED
@@ -1,42 +1,44 @@
1
1
  # Reportier the stat tracker
2
2
 
3
- This is a tracker that tracks the count of events. Most notable is that
4
- as long as you keep addng items reportier will report automatically
5
- without using 3rd party software like cron.
3
+ A tracker that tracks the count of events. Most notably (as long as you keep adding items)
4
+ it can track and report automatically on time (roughly) without the use of 3rd party software like cron.
5
+ And it has an extremely thin public interface, basically you just add items.
6
6
 
7
7
  ## Usage
8
8
 
9
9
  `gem 'reportier'`
10
10
 
11
- Use Reportier to track how manny times something happened in a certain ammount of time.
12
- Reportier has a minimal public interface however is quite powerfull inside.
11
+ Use Reportier to track how many times something happened in a certain amount of time.
12
+ Reportier has a minimal public interface however is quite powerful inside.
13
13
 
14
14
  To use first configure it with intervals by setting a name and when to report
15
15
 
16
+ ```
16
17
  Reportier.configure do |c|
17
18
  # Time is in seconds
18
19
  c.trackers = {
19
- hourly: 60 * 60,
20
- bidaily: 60 * 60 * 24 * 2
20
+ daily: 60 * 60 * 24,
21
+ daily_page_visits: 60 * 60 * 24
21
22
  }
22
23
  end
24
+ ```
23
25
 
24
26
  Then you can add items to trackers and it will keep track of them.
25
27
 
26
28
  ```
27
- Reportier[:hourly].add "Home page visit"
29
+ Reportier[:daily_page_visits].add "Home page visit"
28
30
  # or
29
- Reportier[:bidaily].add @newly_registered_user # object of type User
31
+ Reportier[:daily].add @newly_registered_user # object of type User
30
32
  ```
31
33
 
32
34
  Note that you can add objects and Reporiter will track their class.
33
- You can also add the item to all trackers by doing
35
+ You can also add the item to all *registered* <sup>[1](#myfootnote1)</sup> trackers by doing
34
36
 
35
37
  ```
36
38
  Reportier.add_to_all @item
37
39
  ```
38
40
 
39
- You can make the tracker report or convert it to json.
41
+ You can manually report or convert it to json.
40
42
 
41
43
  ```
42
44
  Reportier[:daily].add('new user registration')
@@ -49,13 +51,13 @@ Reportier[:daily].to_json
49
51
  # -> "{\"new_user_registrations\": 1}"
50
52
  ```
51
53
 
52
- Tracker check if they have expired everytime an item is added.
53
- And they will reset and report when they realise that they
54
+ Each time an item is added the tracker will check if they have expired.
55
+ If they have they will report and reset.
54
56
 
55
- ## Persistance
57
+ ## Persistence
56
58
 
57
59
  Reportier saves items to memory by default however we also support long time
58
- persistance with redis, and maybe postgres in the future.
60
+ persistence with redis, and maybe postgres in the future.
59
61
 
60
62
  To use redis look on setting defaults below.
61
63
 
@@ -74,7 +76,7 @@ end
74
76
  ### Reporters
75
77
 
76
78
  By default Reportier will only report to logger and console
77
- but we also support reporting to slack through slack-reporter and to logger,
79
+ but we also support reporting to slack through slack-reporter,
78
80
  and you can easily create your custom reporting methods.
79
81
 
80
82
  ```
@@ -82,7 +84,7 @@ Reportier.configure do |c|
82
84
  c.reporters = { logger: 'logger', slack: 'slack-reporter' }
83
85
  end
84
86
 
85
- ## Note you need to ass 'slack-reporter' to your gemfile
87
+ ## Note you need to add 'slack-reporter' to your gemfile
86
88
  ```
87
89
 
88
90
  If you want to add custom reporters just add their name and library and then define a `to_#{name)` method to the `Reporter`
@@ -92,15 +94,15 @@ e.x.
92
94
  Reportier.configure { |c| c.reporters = { twilio: 'twilio-ruby' } }
93
95
 
94
96
  class Reportier::Reporter
95
- def to_twilio
96
- ## you code here
97
+ def to_twilio(message)
98
+ ## Do something with #{message}
97
99
  end
98
100
  end
99
101
  ```
100
102
 
101
103
  ### Default reporting vars
102
104
 
103
- Sometimes its usefull no have stats from other services or modules.
105
+ Sometimes its useful to have stats from other services or modules.
104
106
  To do that you can configure reportier to have some default reporting variables
105
107
 
106
108
  ```
@@ -112,17 +114,29 @@ Reportier.configure do |c|
112
114
  todays_messages: Message.where('created_at > ?', Datetime.yesterday)
113
115
  }
114
116
  end
117
+ ```
115
118
 
116
119
  ### Full configuration
117
120
 
118
- Ofcourse you can you all this in a single configuration in the startup of your
121
+ Of course you can have it all in a single configuration in the startup of your
119
122
  application. A full configuration would look something like this.
120
123
 
121
124
  ```
122
125
  Reportier.configure do |c|
123
126
  c.persister = :redis
124
- c.trackers = { daily: 60 * 60 * 24
127
+ c.trackers = { daily: 60 * 60 * 24 }
125
128
  c.reporters = { logger: 'logger', slack: 'slack-reporter' }
126
129
  c.reporting_vars = { active_users: UserRepo.active.count }
127
130
  end
128
131
  ```
132
+
133
+ ## Custom Trackers
134
+ Documentation soon
135
+
136
+
137
+ ## ToDo
138
+ Documentation for custom trackers
139
+ Event driven reports
140
+ Reportier.add_to(trackers // [])
141
+
142
+ <a name="myfootnote1">1</a>: Trackers that are configured by `Reportier.configure { |c| c.trackers = ... }`
@@ -1,6 +1,5 @@
1
1
  require 'date'
2
2
  require_relative 'reportier/naming'
3
- require_relative 'reportier/time'
4
3
  require_relative 'reportier/defaults'
5
4
  require_relative 'reportier/reporter'
6
5
  require_relative 'reportier/persister'
@@ -12,7 +12,7 @@ module Reportier
12
12
  @reporting_vars.merge! Hash(opts[:reporting_vars])
13
13
  end
14
14
 
15
- def configure
15
+ def configure
16
16
  yield self
17
17
  end
18
18
 
@@ -30,6 +30,7 @@ module Reportier
30
30
  _require_reporter_libraries
31
31
  end
32
32
 
33
+
33
34
  private
34
35
 
35
36
  def initialize_defaults
@@ -10,7 +10,6 @@ module Reportier
10
10
  def initialize(tracker)
11
11
  @tracker = tracker
12
12
  @reporting_vars = {}
13
- _initialize_reporting_vars
14
13
  end
15
14
 
16
15
  def save(item)
@@ -24,12 +23,12 @@ module Reportier
24
23
  end
25
24
 
26
25
  def to_json
27
- "{#{to_hash.map { |k,v| "\"#{k}\": #{v}" }.flatten.join(",\n")}}"
26
+ hash = to_hash.map { |k,v| "\"#{k}\": #{v}" }.join(",\n")
27
+ "{#{hash}}"
28
28
  end
29
29
 
30
30
  def clear
31
31
  @reporting_vars = {}
32
- _initialize_reporting_vars
33
32
  end
34
33
 
35
34
  def get_date
@@ -40,8 +39,8 @@ module Reportier
40
39
  @tracker.started_at = date
41
40
  end
42
41
 
43
- def to_hash
44
- @reporting_vars
42
+ def to_hash(reporting_vars = @reporting_vars)
43
+ reporting_vars.merge(@tracker.defaults.reporting_vars)
45
44
  end
46
45
 
47
46
  private
@@ -63,26 +62,21 @@ module Reportier
63
62
  "#{key}: #{val}\n"
64
63
  end
65
64
  end
66
-
65
+
67
66
  def initialize_reporting_var(name)
68
67
  set(name, 0)
69
68
  end
70
-
71
- def _initialize_reporting_vars
72
- @reporting_vars.merge!(@tracker.defaults.reporting_vars)
73
- end
74
69
  end
75
70
  class MemoryPersister < Persister; end
76
71
  class RedisPersister < Persister
77
72
 
78
73
  def clear
79
74
  Redis.current.del(Redis.current.keys(name + '*'))
80
- _initialize_reporting_vars
81
75
  rescue Redis::CommandError
82
76
  end
83
77
 
84
78
  def to_hash
85
- Hash[reporting_vars.map { |k| [k, get(k).to_i] }]
79
+ super(Hash[reporting_vars.map { |k| [k, get(k).to_i] }])
86
80
  end
87
81
 
88
82
  def get_date
@@ -115,7 +109,7 @@ module Reportier
115
109
  def get(item)
116
110
  Redis.current.get name(item)
117
111
  end
118
-
112
+
119
113
  def name(item=nil)
120
114
  "#{@tracker.name}:#{item}"
121
115
  end
@@ -31,6 +31,8 @@ module Reportier
31
31
 
32
32
  def to_logger(message)
33
33
  create_dir('log') unless Dir.exists? 'log'
34
+ ::Logger.new('log/reportier.log').info("\n" + message)
35
+ rescue NameError
34
36
  Logger.new('log/reportier.log').info("\n" + message)
35
37
  end
36
38
 
@@ -2,7 +2,7 @@ module Reportier
2
2
  class Tracker
3
3
  attr_accessor :started_at
4
4
  attr_reader :reporter, :persister, :type, :name, :defaults
5
-
5
+
6
6
 
7
7
  def self.[](type)
8
8
  @current ||= Hash.new
@@ -1,3 +1,3 @@
1
1
  module Reportier
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasilis Spilka