influxer 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +34 -58
  3. data/.travis.yml +6 -1
  4. data/Changelog.md +6 -2
  5. data/Gemfile +5 -2
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +21 -21
  8. data/Rakefile +4 -2
  9. data/bin/console +8 -0
  10. data/gemfiles/rails32.gemfile +1 -1
  11. data/gemfiles/rails42.gemfile +1 -1
  12. data/gemfiles/rails5.gemfile +2 -2
  13. data/gemfiles/rails6.gemfile +7 -0
  14. data/influxer.gemspec +16 -9
  15. data/lib/influxer.rb +10 -9
  16. data/lib/influxer/client.rb +1 -1
  17. data/lib/influxer/config.rb +3 -3
  18. data/lib/influxer/engine.rb +1 -1
  19. data/lib/influxer/metrics/active_model3/model.rb +2 -4
  20. data/lib/influxer/metrics/metrics.rb +8 -8
  21. data/lib/influxer/metrics/quoting/timestamp.rb +13 -13
  22. data/lib/influxer/metrics/relation.rb +17 -13
  23. data/lib/influxer/metrics/relation/calculations.rb +1 -1
  24. data/lib/influxer/metrics/relation/time_query.rb +15 -14
  25. data/lib/influxer/metrics/relation/where_clause.rb +6 -4
  26. data/lib/influxer/metrics/scoping.rb +4 -4
  27. data/lib/influxer/metrics/scoping/current_scope.rb +2 -1
  28. data/lib/influxer/metrics/scoping/default.rb +1 -1
  29. data/lib/influxer/metrics/scoping/named.rb +2 -1
  30. data/lib/influxer/model.rb +4 -9
  31. data/lib/influxer/rails/client.rb +1 -1
  32. data/lib/influxer/version.rb +1 -1
  33. data/spec/cases/points_spec.rb +4 -4
  34. data/spec/cases/write_points_spec.rb +9 -9
  35. data/spec/client_spec.rb +4 -4
  36. data/spec/metrics/metrics_spec.rb +16 -16
  37. data/spec/metrics/relation_spec.rb +11 -11
  38. data/spec/metrics/scoping_spec.rb +2 -2
  39. data/spec/model/user_spec.rb +2 -2
  40. data/spec/spec_helper.rb +13 -14
  41. data/spec/support/shared_contexts/shared_precision.rb +1 -1
  42. metadata +27 -63
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c454bccdf9c3272a5d359f23a8788a77c3b4a8475db929af0958eec10f5ca9b0
4
- data.tar.gz: 2251b0e2015c90c1e1dbfd7bb3eb80d1838f4b16f897ebad8ac2b390e2c370fd
3
+ metadata.gz: 020023da263e0ad14394211eaab3b6388359a2ebd8de084182eeddca8b4f7569
4
+ data.tar.gz: 4648019961ea24ff2132d73b7975a801f0be0270380ba003223166191c4d924d
5
5
  SHA512:
6
- metadata.gz: 7ad48550cca618b24d924856782ab1fe0af754c36e4eb340ccbde6976c467de958e1fa2b85fe040501140e6bf6935358e0bad59f9c202bd94e780c073bc63623
7
- data.tar.gz: 7bbb917021cedd9a6e23a9ff635d9fa3b0e93a28cf5c9312806a9d471af6ed342e0424372d8cae843ad6c6c95aeb813f755d54a741d7b2db4d4cbbde3865433b
6
+ metadata.gz: 3215b0bc249ad3e927f9f77dafb417c29c915c6b32f8f2342c6507b4d165f2a46b9aae82fe815ac374a2785f46c19020b6dd2688e8a208a79cc2a7e7060eb42c
7
+ data.tar.gz: 70b27b50e9e98dcebde9b9ef4f16e1899c3f056770f31ece57af1c4c092a08ffa2484a4343e9c87795ffeca6b79553f9ab78a8dd431d40a75f0a2a808cf605b4
@@ -1,81 +1,57 @@
1
+ require:
2
+ - standard/cop/semantic_blocks
3
+ - rubocop-md
4
+
5
+ inherit_gem:
6
+ standard: config/base.yml
7
+
1
8
  AllCops:
2
- # Include gemspec and Rakefile
3
- Include:
4
- - 'lib/**/*.rb'
5
- - 'lib/**/*.rake'
6
- - 'spec/**/*.rb'
7
9
  Exclude:
8
- - 'bin/**/*'
9
- - 'spec/dummy/**/*'
10
+ - 'bin/*'
11
+ - 'tmp/**/*'
12
+ - 'docs/**/*'
13
+ - 'Gemfile'
10
14
  - 'vendor/**/*'
11
- - 'gemfiles/vendor/**/*'
12
- - '**/*.gemfile'
13
- - Gemfile
14
- - Rakefile
15
+ - 'gemfiles/**/*'
15
16
  DisplayCopNames: true
16
- StyleGuideCopsOnly: false
17
- TargetRubyVersion: 2.3
18
-
19
- Rails:
20
- Enabled: false
17
+ TargetRubyVersion: 2.4
21
18
 
22
- Bundler/OrderedGems:
19
+ Standard/SemanticBlocks:
23
20
  Enabled: false
24
21
 
25
- Style/SymbolArray:
26
- Enabled: false
27
-
28
- Style/SafeNavigation:
29
- Enabled: false
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: true
30
24
 
31
25
  Naming/AccessorMethodName:
32
26
  Enabled: false
33
27
 
34
- Style/TrivialAccessors:
35
- Enabled: false
28
+ Style/TrailingCommaInArrayLiteral:
29
+ EnforcedStyleForMultiline: no_comma
36
30
 
37
- Style/Documentation:
38
- Exclude:
39
- - 'spec/**/*.rb'
31
+ Style/TrailingCommaInHashLiteral:
32
+ EnforcedStyleForMultiline: no_comma
40
33
 
41
- Style/StringLiterals:
42
- Enabled: false
34
+ Layout/AlignParameters:
35
+ EnforcedStyle: with_first_parameter
43
36
 
44
- Style/DateTime:
37
+ Lint/Void:
45
38
  Exclude:
46
- - 'spec/**/*.rb'
47
-
48
- Naming/SpaceInsideStringInterpolation:
49
- EnforcedStyle: no_space
39
+ - '**/*.md'
50
40
 
51
- Style/BlockDelimiters:
41
+ # See https://github.com/rubocop-hq/rubocop/issues/4222
42
+ Lint/AmbiguousBlockAssociation:
52
43
  Exclude:
53
- - 'spec/**/*.rb'
44
+ - 'spec/**/*'
45
+ - '**/*.md'
54
46
 
55
- Lint/MissingCopEnableDirective:
56
- Enabled: false
57
-
58
- Lint/AmbiguousRegexpLiteral:
59
- Enabled: false
60
-
61
- Metrics/BlockLength:
47
+ Lint/DuplicateMethods:
62
48
  Exclude:
63
- - 'spec/**/*.rb'
49
+ - '**/*.md'
64
50
 
65
- Metrics/MethodLength:
51
+ Naming/FileName:
66
52
  Exclude:
67
- - 'spec/**/*.rb'
53
+ - '**/*.md'
68
54
 
69
- Metrics/LineLength:
70
- Max: 100
55
+ Layout/InitialIndentation:
71
56
  Exclude:
72
- - 'spec/**/*.rb'
73
-
74
- Rails/Date:
75
- Enabled: false
76
-
77
- Rails/TimeZone:
78
- Enabled: false
79
-
80
- Gemspec/OrderedDependencies:
81
- Enabled: false
57
+ - 'CHANGELOG.md'
@@ -2,9 +2,14 @@ language: ruby
2
2
  cache: bundler
3
3
  matrix:
4
4
  include:
5
- - rvm: 2.2.1
5
+ - rvm: 2.4.2
6
6
  gemfile: gemfiles/rails32.gemfile
7
7
  - rvm: 2.4.3
8
8
  gemfile: gemfiles/rails42.gemfile
9
9
  - rvm: 2.5.0
10
10
  gemfile: gemfiles/rails5.gemfile
11
+ - rvm: 2.6.2
12
+ gemfile: gemfiles/rails6.gemfile
13
+ allow_failures:
14
+ - rvm: 2.4.2
15
+ gemfile: gemfiles/rails32.gemfile
@@ -1,13 +1,17 @@
1
1
  # Change log
2
2
 
3
- ## master
3
+ ## master (unreleased)
4
+
5
+ ## 1.2.0 (2019-05-20)
6
+
7
+ - **Require Ruby 2.4+**
4
8
 
5
9
  ## 1.1.6
6
10
 
7
11
  - [Fixes [#41](https://github.com/palkan/influxer/issues/41)] Fix query building with empty arrays in `where` clause ([@dimiii][])
8
12
 
9
13
  [PR](https://github.com/palkan/influxer/pull/44)
10
-
14
+
11
15
  **BREAKING:** `where.not` now returns non-empty result for an empty array.
12
16
 
13
17
  - Support of year alias in queries ([@dimiii][])
data/Gemfile CHANGED
@@ -1,10 +1,13 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
- local_gemfile = 'Gemfile.local'
4
+ local_gemfile = "Gemfile.local"
5
+
6
+ gem "pry-byebug", platform: :mri
5
7
 
6
8
  if File.exist?(local_gemfile)
7
9
  eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
8
10
  else
9
- gem 'activerecord', '~>4.2'
11
+ gem "activerecord", "~>4.2"
12
+ gem "sqlite3", "~> 1.3.0"
10
13
  end
@@ -1,4 +1,4 @@
1
- Copyright 2014 palkan
1
+ Copyright 2014-2019 palkan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -3,48 +3,48 @@
3
3
 
4
4
  **NOTE**: Version 0.3.x supports InfluxDB >= 0.9.0. For InfluxDB 0.8.x use [version 0.2.5](https://github.com/palkan/influxer/tree/0.2.5).
5
5
 
6
- **NOTE**: Influxer is Rails 4+ compatible!
6
+ **NOTE**: Influxer is Rails 4+ compatible! (Rails 3.2 support is still included but no longer required to pass all the tests).
7
7
 
8
8
  Influxer provides an ActiveRecord-style way to work with [InfluxDB](https://influxdb.com/) with many useful features, such as:
9
9
  - Familar query language (use `select`, `where`, `not`, `group` etc).
10
10
  - Support for Regex conditions: `where(page_id: /^home\/.*/) #=> select * ... where page_id=~/^home\/.*/`.
11
- - Special query methods for InfluxDB:
11
+ - Special query methods for InfluxDB:
12
12
  - `time` - group by time (e.g. `Metrics.time(:hour) => # select * ... group by time(1h)`);
13
13
  - `past` - get only points for last hour/minute/whatever (e.g. `Metrics.past(:day) => # select * ... where time > now() - 1d`);
14
14
  - `since` - get only points since date (e.g. `Metrics.since(Time.utc(2014,12,31)) => # select * ... where time > 1419984000s`);
15
15
  - `merge` - merge series.
16
16
  - Scopes support
17
17
  ```ruby
18
- class Metrics < Influxer::Metrics
19
- default_scope -> { time(:hour).limit(1000) }
20
- tags :account_id
21
- attributes :value
22
- scope :unlimited, -> { limit(nil) }
23
- scope :by_account, -> (id) { where(account_id: id) if id.present? }
24
- end
25
-
26
- Metrics.by_account(1)
18
+ class Metrics < Influxer::Metrics
19
+ default_scope -> { time(:hour).limit(1000) }
20
+ tags :account_id
21
+ attributes :value
22
+ scope :unlimited, -> { limit(nil) }
23
+ scope :by_account, ->(id) { where(account_id: id) if id.present? }
24
+ end
25
+
26
+ Metrics.by_account(1)
27
27
  # => select * from "metrics" group by time(1h) where account_id=1 limit 1000
28
28
 
29
- Metrics.unlimited.by_account(1).time(:week)
29
+ Metrics.unlimited.by_account(1).time(:week)
30
30
  # => select * from "metrics" group by time(1w) where account_id=1
31
31
 
32
32
  ```
33
33
  - Integrate with your model:
34
34
  ```ruby
35
- class UserVisits < Influxer::Metrics
36
- end
35
+ class UserVisits < Influxer::Metrics
36
+ end
37
37
 
38
- class User < ActiveRecord::Base
39
- has_metrics :visits
40
- end
38
+ class User < ActiveRecord::Base
39
+ has_metrics :visits
40
+ end
41
41
 
42
- user = User.find(1)
43
- user.visits.write(page_id: 'home')
42
+ user = User.find(1)
43
+ user.visits.write(page_id: "home")
44
44
  #=> < creates point {user_id: 1, page_id: 'home'} in 'user_visits' series >
45
45
 
46
- user.visits.where(page_id: 'home')
46
+ user.visits.where(page_id: "home")
47
47
  #=> select * from user_visits where page_id='home'
48
48
  ```
49
-
49
+
50
50
  Find more on [Wiki](https://github.com/palkan/influxer/wiki).
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
3
- require 'rspec/core/rake_task'
5
+ require "rspec/core/rake_task"
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
8
  require "rubocop/rake_task"
@@ -9,5 +11,5 @@ RuboCop::RakeTask.new
9
11
  task default: [:rubocop, :spec]
10
12
 
11
13
  task :console do
12
- sh 'pry -r ./lib/influxer.rb'
14
+ sh "pry -r ./lib/influxer.rb"
13
15
  end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "influxer"
5
+ require "pry"
6
+
7
+ require "pry"
8
+ Pry.start
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', platform: :mri
3
+ gem 'sqlite3', '~> 1.3.0', platform: :mri
4
4
  gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
5
  gem 'activerecord', '~> 3.2.22'
6
6
 
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', platform: :mri
3
+ gem 'sqlite3', '~> 1.3.0', platform: :mri
4
4
  gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
5
  gem 'activerecord', '~> 4.2.0'
6
6
 
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', platform: :mri
3
+ gem 'sqlite3', '~> 1.3.0', platform: :mri
4
4
  gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
- gem 'activerecord', '~> 5.0.0'
5
+ gem 'activerecord', '~> 5.2'
6
6
 
7
7
  gemspec path: '..'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sqlite3', platform: :mri
4
+ gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
+ gem 'activerecord', '6.0.0.rc1'
6
+
7
+ gemspec path: '..'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.push File.expand_path('lib', __dir__)
3
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
4
4
 
5
5
  require "influxer/version"
6
6
 
@@ -17,17 +17,24 @@ Gem::Specification.new do |s|
17
17
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency "activemodel", '>= 3.2.0'
20
+ s.required_ruby_version = ">= 2.4.0"
21
+
22
+ s.metadata = {
23
+ "bug_tracker_uri" => "http://github.com/palkan/influxer/issues",
24
+ "changelog_uri" => "https://github.com/palkan/influxer/blob/master/Changelog.md",
25
+ "documentation_uri" => "http://github.com/palkan/influxer",
26
+ "homepage_uri" => "http://github.com/palkan/influxer",
27
+ "source_code_uri" => "http://github.com/palkan/influxer"
28
+ }
29
+
30
+ s.add_dependency "activemodel", ">= 3.2.0"
21
31
  s.add_dependency "influxdb", "~> 0.3"
22
- s.add_dependency "anyway_config", "~> 1.0"
32
+ s.add_dependency "anyway_config", ">= 1.0"
23
33
 
24
34
  s.add_development_dependency "timecop"
25
- s.add_development_dependency "simplecov", ">= 0.3.8"
26
- s.add_development_dependency 'rake', '~> 10.1'
27
- s.add_development_dependency 'sqlite3'
28
- s.add_development_dependency 'activerecord', '>= 3.2.0'
29
- s.add_development_dependency 'pry-byebug'
35
+ s.add_development_dependency "rake", "~> 10.1"
30
36
  s.add_development_dependency "rspec", ">= 3.1.0"
37
+ s.add_development_dependency "standard", "~> 0.0.39"
38
+ s.add_development_dependency "rubocop-md", "~> 0.2.0"
31
39
  s.add_development_dependency "webmock", "~> 2.1"
32
- s.add_development_dependency "rubocop", "~> 0.52"
33
40
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'influxer/version'
4
- require 'active_model'
3
+ require "influxer/version"
4
+ require "active_model"
5
+ require "active_support/core_ext"
5
6
 
6
7
  # Rails client for InfluxDB
7
8
  module Influxer
@@ -9,16 +10,16 @@ module Influxer
9
10
  ActiveModel::VERSION::MAJOR == 3
10
11
  end
11
12
 
12
- require 'influxer/config'
13
- require 'influxer/client'
14
- require 'influxer/metrics/metrics'
13
+ require "influxer/config"
14
+ require "influxer/client"
15
+ require "influxer/metrics/metrics"
15
16
 
16
17
  module Model # :nodoc:
17
- require 'influxer/model'
18
+ require "influxer/model"
18
19
  end
19
20
 
20
- require 'influxer/rails/client' if defined?(Rails)
21
- require 'influxer/engine' if defined?(Rails)
21
+ require "influxer/rails/client" if defined?(Rails)
22
+ require "influxer/engine" if defined?(Rails)
22
23
 
23
24
  def self.config
24
25
  @config ||= Config.new
@@ -33,7 +34,7 @@ module Influxer
33
34
  end
34
35
 
35
36
  def self.reset!
36
- @client.stop! unless @client.nil?
37
+ @client&.stop!
37
38
  @config = nil
38
39
  @client = nil
39
40
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'influxdb'
3
+ require "influxdb"
4
4
 
5
5
  module Influxer
6
6
  # InfluxDB API client
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'anyway_config'
3
+ require "anyway_config"
4
4
 
5
5
  module Influxer
6
6
  # Influxer configuration
@@ -28,8 +28,8 @@ module Influxer
28
28
  :denormalize,
29
29
  :udp,
30
30
  :async,
31
- database: 'db',
32
- time_precision: 'ns',
31
+ database: "db",
32
+ time_precision: "ns",
33
33
  cache: false,
34
34
  time_duration_suffix_enabled: false
35
35
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'influxer'
3
+ require "influxer"
4
4
 
5
5
  module Influxer
6
6
  class Engine < Rails::Engine # :nodoc:
@@ -5,10 +5,8 @@ module Influxer
5
5
  # Replacement of ActiveModel::Model for ActiveModel 3
6
6
  module Model
7
7
  def initialize(attributes = {})
8
- if attributes
9
- attributes.each do |attr, value|
10
- public_send("#{attr}=", value)
11
- end
8
+ attributes&.each do |attr, value|
9
+ public_send("#{attr}=", value)
12
10
  end
13
11
 
14
12
  super()