rescuetime 0.3.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/.rubocop.yml +4 -1
- data/.rubocop_todo.yml +32 -54
- data/.travis.yml +3 -1
- data/CHANGELOG.md +320 -0
- data/CODE_OF_CONDUCT.md +67 -6
- data/Gemfile +1 -3
- data/README.md +184 -41
- data/Rakefile +1 -1
- data/lib/rescuetime.rb +68 -3
- data/lib/rescuetime/client.rb +6 -13
- data/lib/rescuetime/collection.rb +32 -11
- data/lib/rescuetime/configuration.rb +22 -0
- data/lib/rescuetime/core_extensions.rb +8 -0
- data/lib/rescuetime/core_extensions/object.rb +8 -0
- data/lib/rescuetime/core_extensions/object/blank.rb +49 -0
- data/lib/rescuetime/core_extensions/string.rb +10 -0
- data/lib/rescuetime/date_parser.rb +12 -10
- data/lib/rescuetime/errors.rb +79 -73
- data/lib/rescuetime/formatters.rb +48 -0
- data/lib/rescuetime/formatters/array_formatter.rb +23 -0
- data/lib/rescuetime/formatters/base_formatter.rb +46 -0
- data/lib/rescuetime/formatters/csv_formatter.rb +23 -0
- data/lib/rescuetime/query_buildable.rb +18 -16
- data/lib/rescuetime/report_formatters.rb +83 -0
- data/lib/rescuetime/requester.rb +56 -27
- data/lib/rescuetime/version.rb +3 -2
- data/rescuetime.gemspec +7 -9
- metadata +30 -43
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,13 +1,74 @@
|
|
1
1
|
# Contributor Code of Conduct
|
2
2
|
|
3
|
-
|
3
|
+
## Our Pledge
|
4
4
|
|
5
|
-
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
6
11
|
|
7
|
-
|
12
|
+
## Our Standards
|
8
13
|
|
9
|
-
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
10
16
|
|
11
|
-
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
12
22
|
|
13
|
-
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the maintainer at lee@leesharma.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
rescuetime
|
2
2
|
==========
|
3
3
|
|
4
|
-
[![
|
5
|
-
[![Coverage](
|
4
|
+
[![Maintainability](https://img.shields.io/codeclimate/maintainability/leesharma/rescuetime.svg?style=flat-square)](https://codeclimate.com/github/leesharma/rescuetime)
|
5
|
+
[![Coverage](https://img.shields.io/codeclimate/coverage/leesharma/rescuetime.svg?style=flat-square)](https://codeclimate.com/github/leesharma/rescuetime)
|
6
6
|
[![Build](https://img.shields.io/travis/leesharma/rescuetime.svg?style=flat-square)](https://travis-ci.org/leesharma/rescuetime)
|
7
|
-
[![Dependencies](https://img.shields.io/gemnasium/leesharma/rescuetime.svg?style=flat-square)](https://gemnasium.com/leesharma/rescuetime)
|
8
7
|
|
9
8
|
[![Downloads](https://img.shields.io/gem/dt/rescuetime.svg?style=flat-square)](https://rubygems.org/gems/rescuetime)
|
10
9
|
[![Release](https://img.shields.io/github/release/leesharma/rescuetime.svg?style=flat-square)](https://github.com/leesharma/rescuetime/releases/)
|
@@ -21,11 +20,13 @@ For more information about RescueTime, visit [the RescueTime homepage](https://w
|
|
21
20
|
* [Usage](#usage)
|
22
21
|
* [Prerequisites](#prerequisites)
|
23
22
|
* [In a Nutshell](#in-a-nutshell) (skip to here if you want to see the syntax)
|
23
|
+
* [Custom Report Formatters](#custom-report-formatters)
|
24
24
|
* [Finding Answers (Documentation)](#finding-answers-documentation)
|
25
25
|
* [Defaults](#defaults)
|
26
26
|
* [Rescuetime Exceptions](#rescuetime-exceptions)
|
27
27
|
* [Development](https://github.com/leesharma/rescuetime/wiki/Development) ([section](#development))
|
28
28
|
* [Contributing](CONTRIBUTING.md) ([section](#contributing))
|
29
|
+
* [TODO](#todo)
|
29
30
|
|
30
31
|
#### Useful Links
|
31
32
|
* [RDoc](http://www.rubydoc.info/gems/rescuetime)
|
@@ -51,7 +52,7 @@ Or install it yourself as:
|
|
51
52
|
|
52
53
|
### Prerequisites
|
53
54
|
|
54
|
-
Ensure that you are using a [supported ruby version](https://github.com/leesharma/rescuetime/wiki/Supported-Rubies) for your project.
|
55
|
+
Ensure that you are using a [supported ruby version](https://github.com/leesharma/rescuetime/wiki/Supported-Rubies) for your project.
|
55
56
|
|
56
57
|
In order to use access your RescueTime data, you will need an API key. If you do not already have a key, visit the [API key management page](https://www.rescuetime.com/anapi/manage).
|
57
58
|
|
@@ -66,7 +67,7 @@ require 'rescuetime'
|
|
66
67
|
|
67
68
|
# Rescuetime uses lazy evaluation, so until you either manipulate the collection
|
68
69
|
# or explicitly call for it (with #all), it will remain in the Rescuetime::Collection
|
69
|
-
# format.
|
70
|
+
# format.
|
70
71
|
@client.overview.class #=> Rescuetime::Collection
|
71
72
|
@client.overview.all.class #=> Array
|
72
73
|
@client.overview.map {...} #=> Array
|
@@ -89,9 +90,9 @@ require 'rescuetime'
|
|
89
90
|
# - Object#strftime
|
90
91
|
@client.overview # Fetches results from today
|
91
92
|
@client.overview.date('2014-12-31') # Fetches results from Dec 31, 2014.
|
92
|
-
@client.overview.from('2015-01-01').to('2015-02-01')
|
93
|
-
@client.overview.from('2015-04-01')
|
94
|
-
|
93
|
+
@client.overview.from('2015-01-01').to('2015-02-01')
|
94
|
+
@client.overview.from('2015-04-01')
|
95
|
+
|
95
96
|
|
96
97
|
##
|
97
98
|
# Report Order (:order_by)
|
@@ -99,7 +100,7 @@ require 'rescuetime'
|
|
99
100
|
# Defaults:
|
100
101
|
# Efficiency defaults to chronological order; everything else defaults to "rank" order
|
101
102
|
#
|
102
|
-
# You can order_by:
|
103
|
+
# You can order_by:
|
103
104
|
# :rank, :time, or :member (note: efficiency can't be sorted by :rank)
|
104
105
|
#
|
105
106
|
# When ordering by time, default interval is 1 hour.
|
@@ -107,15 +108,15 @@ require 'rescuetime'
|
|
107
108
|
# :minute (5-minute chunks), :hour, :day, :week, :month
|
108
109
|
@client.efficiency # Defaults to :time
|
109
110
|
@client.productivity # Defaults to :rank
|
110
|
-
|
111
|
-
@client.productivity.order_by(:rank)
|
112
|
-
@client.productivity.order_by(:time)
|
113
|
-
@client.productivity.order_by(:member)
|
114
|
-
|
111
|
+
|
112
|
+
@client.productivity.order_by(:rank)
|
113
|
+
@client.productivity.order_by(:time)
|
114
|
+
@client.productivity.order_by(:member)
|
115
|
+
|
115
116
|
@client.productivity.order_by(:time) # Defaults to :hour
|
116
|
-
@client.productivity.order_by(:time, interval: :minute)
|
117
|
-
@client.productivity.order_by(:time, interval: :hour)
|
118
|
-
@client.productivity.order_by(:time, interval: :day)
|
117
|
+
@client.productivity.order_by(:time, interval: :minute)
|
118
|
+
@client.productivity.order_by(:time, interval: :hour)
|
119
|
+
@client.productivity.order_by(:time, interval: :day)
|
119
120
|
@client.productivity.order_by(:time, interval: :week)
|
120
121
|
@client.productivity.order_by(:time, interval: :month)
|
121
122
|
|
@@ -131,10 +132,10 @@ require 'rescuetime'
|
|
131
132
|
# Try the query sans document for a list of valid options
|
132
133
|
#
|
133
134
|
# Names must be exact matches.
|
134
|
-
@client.activities.where(name: 'github.com')
|
135
|
-
@client.categories.where(name: 'Intelligence')
|
136
|
-
@client.overview.where(name: 'Utilities')
|
137
|
-
@client.activities.where(name: 'github.com', document: 'vcr/vcr')
|
135
|
+
@client.activities.where(name: 'github.com')
|
136
|
+
@client.categories.where(name: 'Intelligence')
|
137
|
+
@client.overview.where(name: 'Utilities')
|
138
|
+
@client.activities.where(name: 'github.com', document: 'vcr/vcr')
|
138
139
|
|
139
140
|
##
|
140
141
|
# Formatting options (:csv, :array)
|
@@ -144,9 +145,113 @@ require 'rescuetime'
|
|
144
145
|
@client.efficiency.format(:array) # Returns Array<Hash>
|
145
146
|
```
|
146
147
|
|
148
|
+
### Custom Report Formatters
|
149
|
+
|
150
|
+
*Feature available in v0.4.0 and later*
|
151
|
+
|
152
|
+
Rescuetime ships with two report formats: CSV and Array. If you would like your
|
153
|
+
report in a different format, don't worry–it's easy to add a custom formatter.
|
154
|
+
|
155
|
+
Three things are required to add a custom formatter:
|
156
|
+
|
157
|
+
1. [Write a class](#writing-a-formatter) within the module
|
158
|
+
`Rescuetime::Formatters` that inherits from `Rescuetime::Formatters::BaseFormatter`
|
159
|
+
or one of its descendants
|
160
|
+
2. Define the class methods `.name` and `.format`
|
161
|
+
4. [Register your formatters](#registering-your-formatters) using `Rescuetime.configure`
|
162
|
+
|
163
|
+
#### Writing a Formatter
|
164
|
+
|
165
|
+
First, the formatters themselves. Here is a basic formatter:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
# config/formatters/nil_formatter.rb
|
169
|
+
module Rescuetime::Formatters
|
170
|
+
# Turns a productivity report into nothing useful.
|
171
|
+
class NilFormatter < BaseFormatter
|
172
|
+
# @return [String] name of this report format
|
173
|
+
def self.name
|
174
|
+
'nil'
|
175
|
+
end
|
176
|
+
|
177
|
+
# @param [CSV] _report the raw CSV report from Rescuetime
|
178
|
+
# @return [nil] the formatted output (in this case, nil)
|
179
|
+
def self.format(_report)
|
180
|
+
nil
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
```
|
185
|
+
|
186
|
+
You can even inherit from an existing formatter:
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
# config/formatters/shouty_array_formatter.rb
|
190
|
+
module Rescuetime::Formatters
|
191
|
+
# Formats a rescuetime report as an array of hashes, except shouting.
|
192
|
+
class ShoutyArrayFormatter < ArrayFormatter
|
193
|
+
# @return [String] name of this report format
|
194
|
+
def self.name
|
195
|
+
'shouty_array'
|
196
|
+
end
|
197
|
+
|
198
|
+
# @param [CSV] report the raw CSV report from Rescuetime
|
199
|
+
# @return [Array<Hash>] the formatted output (in this case, a shouty
|
200
|
+
# array of hashes)
|
201
|
+
def self.format(report)
|
202
|
+
array = super(report)
|
203
|
+
array.map do |hash|
|
204
|
+
terms = hash.map { |key, value| [key.to_s.upcase, value.to_s.upcase] }
|
205
|
+
Hash[terms]
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
#### Registering your Formatters
|
213
|
+
|
214
|
+
Before setting your report format, add the path to your formatter(s) to the
|
215
|
+
Rescuetime configuration using the `Rescuetime.configure` method. You will be
|
216
|
+
able to set, append to, or manipulate the `formatter_paths` setting.
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
Rescuetime.configure do |config|
|
220
|
+
path = File.expand_path('../my_custom_formatter.rb', __FILE__)
|
221
|
+
config.formatter_paths = [path]
|
222
|
+
end
|
223
|
+
```
|
224
|
+
|
225
|
+
Now Rescuetime will look for the `my_custom_formatter.rb` file. Multiple paths
|
226
|
+
may be added as well.
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
Rescuetime.configure do |config|
|
230
|
+
config.formatter_paths = [
|
231
|
+
'config/formatters/*_formatter.rb',
|
232
|
+
'lib/formatters/**/*_formatter.rb',
|
233
|
+
]
|
234
|
+
end
|
235
|
+
```
|
236
|
+
|
237
|
+
##### Rails Example
|
238
|
+
|
239
|
+
For example, in a Rails app, you could add the configuration file to `config/initializers`:
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
# config/initializers/rescuetime.rb
|
243
|
+
Rescuetime.configure do |config|
|
244
|
+
path = File.expand_path('../../formatters/*_formatter.rb', __FILE__)
|
245
|
+
config.formatter_paths += [path]
|
246
|
+
end
|
247
|
+
```
|
248
|
+
|
249
|
+
Rails can now find any formatters ending in `_formatter.rb` in the folder `config/formatters`
|
250
|
+
(ex. `config/formatters/xml_formatter.rb`).
|
251
|
+
|
147
252
|
### Finding Answers (Documentation)
|
148
253
|
|
149
|
-
For more details, please see [official gem documentation](http://www.rubydoc.info/gems/rescuetime) or [read the wiki](https://github.com/leesharma/rescuetime/wiki).
|
254
|
+
For more details, please see [official gem documentation](http://www.rubydoc.info/gems/rescuetime) or [read the wiki](https://github.com/leesharma/rescuetime/wiki).
|
150
255
|
|
151
256
|
### Defaults
|
152
257
|
|
@@ -162,27 +267,32 @@ The `Rescuetime::Client#activities` action has the following defaults:
|
|
162
267
|
|
163
268
|
### Rescuetime Exceptions
|
164
269
|
|
165
|
-
|
270
|
+
*Note: In v0.4.0, custom exceptions were moved from the base `Rescuetime`
|
271
|
+
namespace to the `Rescuetime::Errors` namespace. For example, in v0.3.3,
|
272
|
+
a bad request was represented by `Rescuetime::BadRequest`. In >= v0.4.0,
|
273
|
+
it is represented by `Rescuetime::Errors::BadRequest`.*
|
166
274
|
|
167
|
-
|
168
|
-
|
169
|
-
*
|
170
|
-
*
|
275
|
+
There are a number of exceptions that extend from the `Rescuetime::Errors::Error` class:
|
276
|
+
|
277
|
+
* **`Rescuetime::Errors::MissingCredentialsError`** is raised when a request is attempted by a client with no credentials. Try setting credentials with `@client.api_key = <YOUR_API_KEY>`.
|
278
|
+
* **`Rescuetime::Errors::InvalidCredentialsError`** is raised when a request is attempted by a client with invalid credentials. Double-check your API key and fix your client with `@client.api_key = <VALID_API_KEY>`.
|
279
|
+
* **`Rescuetime::Errors::InvalidQueryError`** is raised if you enter an invalid value for any of the RescueTime query methods (or if the server returns a bad query error)
|
280
|
+
* **`Rescuetime::Errors::InvalidFormatError`** is raised if you pass a disallowed format to the client
|
171
281
|
* HTTP Response Errors:
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
282
|
+
* **4xx => `Rescuetime::Errors::ClientError`**
|
283
|
+
* 400 => `Rescuetime::Errors::BadRequest`
|
284
|
+
* 401 => `Rescuetime::Errors::Unauthorized`
|
285
|
+
* 403 => `Rescuetime::Errors::Forbidden`
|
286
|
+
* 404 => `Rescuetime::Errors::NotFound`
|
287
|
+
* 406 => `Rescuetime::Errors::NotAcceptable`
|
288
|
+
* 422 => `Rescuetime::Errors::UnprocessableEntity`
|
289
|
+
* 429 => `Rescuetime::Errors::TooManyRequests`
|
290
|
+
* **5xx => `Rescuetime::Errors::ServerError`**
|
291
|
+
* 500 => `Rescuetime::Errors::InternalServerError`
|
292
|
+
* 501 => `Rescuetime::Errors::NotImplemented`
|
293
|
+
* 502 => `Rescuetime::Errors::BadGateway`
|
294
|
+
* 503 => `Rescuetime::Errors::ServiceUnavailable`
|
295
|
+
* 504 => `Rescuetime::Errors::GatewayTimeout`
|
186
296
|
|
187
297
|
## Development
|
188
298
|
|
@@ -191,3 +301,36 @@ See the [development page](https://github.com/leesharma/rescuetime/wiki/Developm
|
|
191
301
|
## Contributing
|
192
302
|
|
193
303
|
See the [contributing page](CONTRIBUTING.md).
|
304
|
+
|
305
|
+
### TODO
|
306
|
+
|
307
|
+
The eventual goal of this gem is full coverage of all Rescuetime APIs.
|
308
|
+
|
309
|
+
Associated issues from our issue tracker are linked when applicable. If you are interested in contributing, please feel free to work on any of these issues! If there is a feature you want that's not on the TODO list, open an issue and we can discuss it.
|
310
|
+
|
311
|
+
- [x] Minimum viable functionality (in [v0.1.0])
|
312
|
+
- [x] Add support for major query params in Data Analytic API (in [v0.2.0])
|
313
|
+
- [x] Lazy query evaluation and method chaining (in [v0.3.0], [v0.3.1], [v0.3.2], [v0.3.3])
|
314
|
+
- [x] Add custom report formatters (in [v0.4.0])
|
315
|
+
- [ ] Add full coverage of Data Analytics API
|
316
|
+
- [ ] Restrict results by group ([#14])
|
317
|
+
- [ ] Restrict results by person
|
318
|
+
- [ ] Add support for "Daily Summary API" ([#28])
|
319
|
+
- [ ] Add support for "Alerts Feed API"
|
320
|
+
- [ ] Add support for "Daily Highlights Feed API"
|
321
|
+
- [ ] Add support for "Daily Highlights POST API"
|
322
|
+
- [ ] Add OAuth2 support
|
323
|
+
|
324
|
+
For details about completed items, please see [the release page][releases].
|
325
|
+
|
326
|
+
[#14]: https://github.com/leesharma/rescuetime/issues/14
|
327
|
+
[#28]: https://github.com/leesharma/rescuetime/issues/28
|
328
|
+
|
329
|
+
[v0.1.0]:https://github.com/leesharma/rescuetime/releases/tag/v0.1.0
|
330
|
+
[v0.2.0]:https://github.com/leesharma/rescuetime/releases/tag/v0.2.0
|
331
|
+
[v0.3.0]:https://github.com/leesharma/rescuetime/releases/tag/v0.3.0
|
332
|
+
[v0.3.1]:https://github.com/leesharma/rescuetime/releases/tag/v0.3.1
|
333
|
+
[v0.3.2]:https://github.com/leesharma/rescuetime/releases/tag/v0.3.2
|
334
|
+
[v0.3.3]:https://github.com/leesharma/rescuetime/releases/tag/v0.3.3
|
335
|
+
[v0.4.0]:https://github.com/leesharma/rescuetime/releases/tag/v0.4.0
|
336
|
+
[releases]:https://github.com/leesharma/rescuetime/releases
|
data/Rakefile
CHANGED
data/lib/rescuetime.rb
CHANGED
@@ -1,10 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rescuetime/version'
|
4
|
+
require 'rescuetime/configuration'
|
2
5
|
require 'rescuetime/client'
|
3
6
|
require 'rescuetime/errors'
|
4
7
|
|
5
|
-
#
|
8
|
+
# Wrapper module for rescuetime gem
|
9
|
+
#
|
10
|
+
# @since v0.1.0
|
6
11
|
module Rescuetime
|
7
|
-
#
|
12
|
+
# class << self
|
13
|
+
# attr_writer :configuration
|
14
|
+
# end
|
15
|
+
|
16
|
+
# Passes a block to the Rescuetime configuration, allowing configuration
|
17
|
+
# options to be set.
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# # In an initializer or before any report formatters are called:
|
21
|
+
# Rescuetime.configure do |config|
|
22
|
+
# config.formatter_paths += ['path/to/local/formatters/*_formatter.rb']
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# # Let's say that directory contains the valid formatters pdf_formatter.rb
|
26
|
+
# # and json_formatter.rb
|
27
|
+
# report_formatters = Rescuetime::ReportFormatters.new
|
28
|
+
# puts report_formatters.all
|
29
|
+
# #=> ["array", "csv", "pdf", "json"]
|
30
|
+
#
|
31
|
+
# @see Rescuetime.configuration
|
32
|
+
# @see Rescuetime::Configuration
|
33
|
+
# @since v0.4.0
|
34
|
+
def self.configure
|
35
|
+
yield(configuration)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns either the current configuration (if set) or initializes a new
|
39
|
+
# default configuration.
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# Rescuetime.configuration.formatter_paths
|
43
|
+
# #=> []
|
44
|
+
#
|
45
|
+
# Rescuetime.configure do |config|
|
46
|
+
# config.formatter_paths += ['formatters/*.rb']
|
47
|
+
# end
|
48
|
+
# Rescuetime.configuration.formatter_paths
|
49
|
+
# #=> ["formatters/*.rb"]
|
50
|
+
#
|
51
|
+
# @see Rescuetime::Configuration
|
52
|
+
# @return [Rescuetime::Configuration] the current Rescuetime configuration
|
53
|
+
# @since v0.4.0
|
54
|
+
def self.configuration
|
55
|
+
@configuration ||= Configuration.new
|
56
|
+
end
|
57
|
+
|
58
|
+
# Resets the configuration back to the initial state. Mainly useful for
|
59
|
+
# resetting the class after testing, making specs order-independent.
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# before :each do
|
63
|
+
# Rescuetime.configure { |c| c.formatter_paths += ['formatters/*.rb'] }
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# after :each do
|
67
|
+
# Rescuetime.reset
|
68
|
+
# end
|
8
69
|
#
|
9
|
-
# @
|
70
|
+
# @see Rescuetime::Configuration#initialize
|
71
|
+
# @since v0.4.0
|
72
|
+
def self.reset
|
73
|
+
@configuration = Configuration.new
|
74
|
+
end
|
10
75
|
end
|