matt 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0d982bf8b24d2c37f18bc1db92ba7f7382402d33b2cda5d9e63e23c3074856d
4
- data.tar.gz: b6fdeddbf7570e4424c69e16718900b91fac8dc051f4a04bb6c8fe9246c128d2
3
+ metadata.gz: 89d30cc70cfb6d7b0bec8dbe5c26a14bdcc3b52af7d6a6a6a20194d88bc3bb47
4
+ data.tar.gz: a71165a1b2a84d8652da562e96473385e2ab8a4a7d88cf8bf3130b5faa1e2e90
5
5
  SHA512:
6
- metadata.gz: 23144f539ac737c3f89454076a96961f350c8eb642661346056bebdc37abed009af67b5454a97c2806f972a43b0d2a60ac8ffe5fa5dca6bd01fdc6b3faae9064
7
- data.tar.gz: d9d12f0a4289ab2ff1b6ac99093d15d6a374d8415f9eed06d37318281e9d6130a7d1ce3aecd09289c82b105a0ade2746e727fcca8ab2da3371db599533553f29
6
+ metadata.gz: dac740d330fa55714c282475e0ef61e39175096d088ffb1a79b47983b2c201f86753a85143a23a8e4c8ff927510fcc4350d402c650c38e9d17e9fc6fee5f2b62
7
+ data.tar.gz: 7c029f44ed6caea484a2c6937a03850f6f82ca45ac81f7b349d74ace9d7dd5a8dda8c5897901d903f7ef49b49ae80a9e66cddf521132c01c31ce6102120c7cee
data/lib/matt.rb CHANGED
@@ -38,6 +38,25 @@ module Matt
38
38
  end
39
39
  module_function :today_predicate
40
40
 
41
+ def last_predicate(arg)
42
+ raise Error, "Invalid predicate `#{arg}`" unless arg.strip =~ /^(\d+)days$/
43
+ Predicate.gte(:at, Date.today - $1.to_i) & Predicate.lt(:at, Date.today + 1)
44
+ end
45
+ module_function :last_predicate
46
+
47
+ def since_predicate(arg)
48
+ raise Error, "Invalid predicate `#{arg}`" unless since = Date.parse(arg)
49
+ Predicate.gte(:at, since) & Predicate.lt(:at, Date.today + 1)
50
+ end
51
+ module_function :since_predicate
52
+
53
+ def between_predicate(from, to)
54
+ raise Error, "Invalid predicate `#{arg}`" unless from = Date.parse(from)
55
+ raise Error, "Invalid predicate `#{arg}`" unless to = Date.parse(to)
56
+ Predicate.gte(:at, from) & Predicate.lt(:at, to)
57
+ end
58
+ module_function :between_predicate
59
+
41
60
  end # module Matt
42
61
  require_relative 'matt/version'
43
62
  require_relative 'matt/support'
data/lib/matt/command.rb CHANGED
@@ -13,6 +13,9 @@
13
13
  #/ --all-time Do not restrict measures shown/exported
14
14
  #/ --today Only show/export measures for today
15
15
  #/ --yesterday Only show/export measures for yesterday's (default)
16
+ #/ --last=Ndays Only show/export measures for the last N days
17
+ #/ --since=date Only show/export measures since a given date (YYYY-MM-DD)
18
+ #/ --between=from,to Only show/export measures between two dates (YYYY-MM-DD)
16
19
  #/ --to=exporter,... Override the default exporters
17
20
  #/ --json Use json when displaying measures on console
18
21
  #/ --csv Use csv when displaying measures on console (default)
@@ -93,7 +96,8 @@ module Matt
93
96
  def do_show(argv)
94
97
  argv_count!(argv, 1)
95
98
  m = measure_exists!(argv.first)
96
- data = m.full_data.restrict(configuration.at_predicate)
99
+ data = m.data_at(configuration.at_predicate)
100
+ debug("show -- #{data.inspect}")
97
101
  case of = output_format
98
102
  when :json
99
103
  puts_out JSON.pretty_generate(data)
@@ -114,7 +118,8 @@ module Matt
114
118
  def do_export(argv)
115
119
  which_ones = argv_to_xs(argv, :measures)
116
120
  which_ones.each do |m|
117
- data = m.full_data.restrict(configuration.at_predicate)
121
+ data = m.data_at(configuration.at_predicate)
122
+ debug("export -- #{data.inspect}")
118
123
  (@to || m.exporters).each do |e|
119
124
  exporter = exporter_exists!(e)
120
125
  exporter.export(m, data)
@@ -153,6 +158,15 @@ module Matt
153
158
  opts.on("--today") do
154
159
  self.configuration.at_predicate = Matt.today_predicate
155
160
  end
161
+ opts.on("--last=X") do |x|
162
+ self.configuration.at_predicate = Matt.last_predicate(x)
163
+ end
164
+ opts.on("--since=X") do |x|
165
+ self.configuration.at_predicate = Matt.since_predicate(x)
166
+ end
167
+ opts.on("--between=X,Y") do |arg|
168
+ self.configuration.at_predicate = Matt.between_predicate(*arg.split(','))
169
+ end
156
170
  opts.on("--to=EXPORTERS") do |exporters|
157
171
  @to = (@to || []) + exporters.split(/\s*,\s*/).map{|e|
158
172
  exporter_exists!(e.to_sym).name
@@ -24,8 +24,8 @@ module Matt
24
24
  end
25
25
  end
26
26
 
27
- def sequel(*args)
28
- Bmg.sequel(*args)
27
+ def sequel(table, type = nil)
28
+ Bmg.sequel(*[table, type, sequel_db].compact)
29
29
  end
30
30
 
31
31
  end
data/lib/matt/measure.rb CHANGED
@@ -18,5 +18,13 @@ module Matt
18
18
  configuration.datasources
19
19
  end
20
20
 
21
+ def data_at(at_predicate)
22
+ full_data.restrict(at_predicate)
23
+ end
24
+
25
+ def full_data
26
+ raise NotImplementedError, "#{self} must implement `full_data`"
27
+ end
28
+
21
29
  end # module Measure
22
30
  end # module Matt
data/lib/matt/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Matt
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 1
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
  end # module Version
7
7
  VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].join(".")
8
8
  end # module Matt
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-10 00:00:00.000000000 Z
11
+ date: 2021-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: path