matt 1.0.0 → 1.1.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: 712f1cd0be5efa12e62fe0491c0c14028b76a5e4edcdaf792bf8ab9652397218
4
- data.tar.gz: e133df58cfba2501cdd806668ff6e21363150a32a9563a6fa554938dc2bfed5c
3
+ metadata.gz: 92deceb672378cd120f32646aa25b2359ed71dd6f839725b4b9f5f6399e61830
4
+ data.tar.gz: b7e1f62d36921e21e5e5ef5d78c925500989f9fa6808c6f365bd80c3eeb6617a
5
5
  SHA512:
6
- metadata.gz: ae322c7f52f9bab450bb21781b5653bd87a6e40703fadfe2768cc56305508464945f411c15584b3702cfefc969baf2af0fe4e437b6b454355b934b7602d39920
7
- data.tar.gz: d4ef94dc91c994bb4886a4b9c4beb0c863af6d62bc2c66c440fb0a594788640bca2c536bbe1f86a8f3e22ebb93bc357ef09e0e29c604256aa4f064b167ba33ef
6
+ metadata.gz: c661c1e3a8560513026e2d48cc435742e7db307866a0546006c2304290c809a5b912ee53eda7743f1be5980c90e9c36d9d7227698904dde9661cdb77c21b71ba
7
+ data.tar.gz: b518ca0a0758c9828bb1ffcdbf30f85f851098007868a5fa91cf1ab5480c2794531ad4e310efee78d6f64daecd968b614f58afa7940e19ce1aa929514d5c1493
data/lib/matt.rb CHANGED
@@ -7,6 +7,9 @@ require 'path'
7
7
  require 'bmg/sequel'
8
8
  module Matt
9
9
 
10
+ class Error < StandardError; end
11
+ class UnexpectedError < Error; end
12
+
10
13
  def env(which, default = nil)
11
14
  val = ENV.has_key?(which) ? ENV[which] : default
12
15
  val = val.strip if val.is_a?(String)
@@ -14,6 +17,12 @@ module Matt
14
17
  end
15
18
  module_function :env
16
19
 
20
+ def env!(which)
21
+ raise Matt::Error, "Missing env var `#{which}`" unless ENV.has_key?(which)
22
+ env(which)
23
+ end
24
+ module_function :env!
25
+
17
26
  def alltime_predicate
18
27
  Predicate.tautology
19
28
  end
data/lib/matt/command.rb CHANGED
@@ -16,6 +16,8 @@
16
16
  #/ --to=exporter,... Override the default exporters
17
17
  #/ --json Use json when displaying measures on console
18
18
  #/ --csv Use csv when displaying measures on console (default)
19
+ #/ --silent Do not print any info/debug messages
20
+ #/ --verbose Print debug information in addition to info messages
19
21
  #/ -h, --help Show this help message
20
22
  #/ --version Show matt version
21
23
  #/
@@ -169,6 +171,12 @@ module Matt
169
171
  puts_out "Matt v#{VERSION} - (c) Enspirit SRL"
170
172
  abort
171
173
  end
174
+ opts.on("--silent") do
175
+ self.configuration.debug_level = Configuration::DEBUG_SILENT
176
+ end
177
+ opts.on("--verbose") do
178
+ self.configuration.debug_level = Configuration::DEBUG_VERBOSE
179
+ end
172
180
  opts.on("-h", "--help", "Prints this help") do
173
181
  do_help
174
182
  abort
@@ -1,6 +1,10 @@
1
1
  module Matt
2
2
  class Configuration
3
3
 
4
+ DEBUG_SILENT = 0
5
+ DEBUG_INFO = 1
6
+ DEBUG_VERBOSE = 2
7
+
4
8
  def initialize(folder)
5
9
  @folder = folder
6
10
  @stdout = $stdout
@@ -9,12 +13,14 @@ module Matt
9
13
  :write_headers => true
10
14
  }
11
15
  @at_predicate = Matt.yesterday_predicate
16
+ @debug_level = DEBUG_INFO
12
17
  yield(self) if block_given?
13
18
  end
14
19
  attr_accessor :folder
15
20
  attr_accessor :stdout, :stderr
16
21
  attr_accessor :csv_options
17
22
  attr_accessor :at_predicate
23
+ attr_accessor :debug_level
18
24
 
19
25
  def datasources_folder
20
26
  folder/"datasources"
@@ -1,9 +1,6 @@
1
1
  module Matt
2
2
  module Datasource
3
- include Support::Puts
4
-
5
- attr_accessor :name
6
- attr_accessor :configuration
3
+ include Support::Participant
7
4
 
8
5
  def ping
9
6
  raise NotImplementedError, "#{self} should implement `ping`"
data/lib/matt/exporter.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Matt
2
2
  module Exporter
3
- include Support::Puts
3
+ include Support::Participant
4
4
 
5
- attr_accessor :name
6
- attr_accessor :configuration
5
+ def export(measure, data)
6
+ raise NotImplementedError, "#{self} should implement `export`"
7
+ end
7
8
 
8
9
  end # module Exporter
9
10
  end # module Matt
@@ -35,11 +35,16 @@ module Matt
35
35
 
36
36
  def remove_old_data!(table, data)
37
37
  dates = data.project([:at]).map{|t| t[:at] }
38
- table.where(:at => dates).delete
38
+ count = table.where(:at => dates).delete
39
+ info("Removed #{count} rows.")
40
+ count
39
41
  end
40
42
 
41
43
  def insert_new_data!(table, data)
42
- table.multi_insert(data.to_a)
44
+ data = data.to_a
45
+ result = table.multi_insert(data)
46
+ info("Inserted #{data.size} rows.")
47
+ result
43
48
  end
44
49
 
45
50
  def ensure_table!(measure)
@@ -62,6 +67,7 @@ module Matt
62
67
  }
63
68
  outdated = existing - fields
64
69
  return if missing.empty? && outdated.empty?
70
+ debug("ALTER table #{tb_name}\n Outdated: #{outdated.join(', ')}\n New: #{missing.keys.join(', ')}")
65
71
  sequel_db.alter_table(tb_name) do
66
72
  outdated.each do |out|
67
73
  drop_column(out)
@@ -73,6 +79,7 @@ module Matt
73
79
  end
74
80
 
75
81
  def create_table!(tb_name, measure, fields)
82
+ debug("CREATE table #{tb_name}\n Dimensions: #{measure.dimensions.keys.join(', ')}\n Metrics: #{measure.metrics.keys.join(', ')}")
76
83
  sequel_db.create_table(tb_name) do
77
84
  column(:at, Date, :null => false)
78
85
  column(:created_at, :timestamp, :null => false)
data/lib/matt/measure.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  module Matt
2
2
  module Measure
3
- include Support::Puts
4
-
5
- attr_accessor :name
6
- attr_accessor :configuration
3
+ include Support::Participant
7
4
 
8
5
  def dimensions
9
6
  {}
data/lib/matt/support.rb CHANGED
@@ -1 +1,2 @@
1
1
  require_relative 'support/puts'
2
+ require_relative 'support/participant'
@@ -0,0 +1,23 @@
1
+ module Matt
2
+ module Support
3
+ module Participant
4
+ include Puts
5
+
6
+ attr_accessor :name
7
+ attr_accessor :configuration
8
+
9
+ def fail!(message)
10
+ raise UnexpectedError, message
11
+ end
12
+
13
+ def class_name
14
+ self.class.name.gsub /#<Class(.*?)>::/, ""
15
+ end
16
+
17
+ def to_s
18
+ "#{class_name}(#{self.name})"
19
+ end
20
+
21
+ end # module Participant
22
+ end # module Support
23
+ end # module Matt
@@ -21,6 +21,20 @@ module Matt
21
21
  configuration.stderr.puts(*args, &bl)
22
22
  end
23
23
 
24
+ def info(message)
25
+ message = "#{self.to_s.ljust(30)} -- #{message}"
26
+ return $stderr.puts(message) unless configuration
27
+ return unless configuration.debug_level >= Configuration::DEBUG_INFO
28
+ puts_err(message)
29
+ end
30
+
31
+ def debug(message)
32
+ message = "#{self.to_s.ljust(30)} -- #{message}"
33
+ return $stderr.puts(message) unless configuration
34
+ return unless configuration.debug_level >= Configuration::DEBUG_VERBOSE
35
+ puts_err(message)
36
+ end
37
+
24
38
  end # module Puts
25
39
  end # module Support
26
40
  end # module Matt
data/lib/matt/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Matt
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 0
4
+ MINOR = 1
5
5
  TINY = 0
6
6
  end # module Version
7
7
  VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].join(".")
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.0.0
4
+ version: 1.1.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-09 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: path
@@ -149,6 +149,7 @@ files:
149
149
  - lib/matt/exporter/sql.rb
150
150
  - lib/matt/measure.rb
151
151
  - lib/matt/support.rb
152
+ - lib/matt/support/participant.rb
152
153
  - lib/matt/support/puts.rb
153
154
  - lib/matt/version.rb
154
155
  homepage: http://github.com/enspirit/matt