Skip to content

Commit

Permalink
Merge pull request #1 from 3dcl/add_beginnless_and_endless_ranges_in_…
Browse files Browse the repository at this point in the history
…where

Add beginnless and endless ranges in where
  • Loading branch information
jklimke authored Aug 30, 2024
2 parents 0229ac2 + 59ac570 commit 69bd7a8
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 147 deletions.
19 changes: 2 additions & 17 deletions .github/workflows/docs-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
ruby-version: 2.7
- name: Lint Markdown files with RuboCop
run: |
gem install bundler
gem install bundler -v 2.4.22
bundle install --gemfile gemfiles/rubocop.gemfile --jobs 4 --retry 3
bundle exec --gemfile gemfiles/rubocop.gemfile rubocop -c .rubocop-md.yml
forspell:
Expand All @@ -45,7 +45,7 @@ jobs:
sudo apt-get install hunspell
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.1
- name: Cache installed gems
uses: actions/cache@v1
with:
Expand All @@ -55,18 +55,3 @@ jobs:
run: gem install forspell
- name: Run Forspell
run: forspell *.md
liche:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
- name: Run liche
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go get -u github.com/raviqqe/liche
liche README.md CHANGELOG.md
12 changes: 3 additions & 9 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Rspec

on:
push:
Expand All @@ -16,17 +16,11 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.5", "2.6", "2.7"]
ruby: ["2.7", "3.1"]
gemfile: [
"gemfiles/rails6.gemfile",
"gemfiles/rails5.gemfile",
"gemfiles/rails42.gemfile"
"gemfiles/rails7.gemfile"
]
exclude:
- ruby: "2.5"
gemfile: "gemfiles/rails6.gemfile"
- ruby: "2.7"
gemfile: "gemfiles/rails42.gemfile"
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
ruby-version: 2.7
- name: Lint Ruby code with RuboCop
run: |
gem install bundler
gem install bundler -v 2.4.22
bundle install --gemfile gemfiles/rubocop.gemfile --jobs 4 --retry 3
bundle exec --gemfile gemfiles/rubocop.gemfile rubocop
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

## master (unreleased)

- Upgraded Ruby and Rails version to Ruby 2.7.6 and Rails 6
- added support for providing hash objects as arguments to where condition in ruby >= 3

## 1.4.0 (2022-01-24)

- Fixes [#55](https://github.com/palkan/influxer/issues/55) Rails 7 deprecation warning
- Add Ruby3 Support
- Updates InfluxDB client dependency
- Removes Ruby 2.4 supporting

## 1.3.0 (2020-10-27)

- Fixes [#53](https://github.com/palkan/influxer/issues/53) Influxer client configuration issue with anyway config v2 and higher.([@AlexanderShvaykin][])

## 1.2.2 (2020-10-27)

- Fixes [#49](https://github.com/palkan/influxer/issues/49) Cache hash configuration cannot be applied.([@AlexanderShvaykin][])
- Fixes [#47](https://github.com/palkan/influxer/issues/47) Can't delete data when retention policy is set for a metric. ([@MPursche][])

## 1.2.1 (2020-07-09)

- Support for setting timezone in queries to configure influx time calculations, e.g., time epoch aggregation ([@jklimke][])
Expand Down Expand Up @@ -87,6 +106,7 @@ end
See [changelog](https://github.com/palkan/influxer/blob/1.0.0/Changelog.md) for earlier versions.

[@palkan]: https://github.com/palkan
[@MPursche]: https://github.com/MPursche
[@mpursche]: https://github.com/MPursche
[@jklimke]: https://github.com/jklimke
[@dimiii]: https://github.com/dimiii
[@alexandershvaykin]: https://github.com/AlexanderShvaykin
92 changes: 0 additions & 92 deletions Changelog.md

This file was deleted.

4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ gem "pry-byebug", platform: :mri
if File.exist?(local_gemfile)
eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
else
gem "activerecord", "~> 5.2"
gem "sqlite3", "~> 1.3.0"
gem 'sqlite3', '1.4', platform: :mri
gem 'activerecord', '~> 7.0'
end
1 change: 1 addition & 0 deletions forspell.dict
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# Example: deduplicate: duplicate
Influxer
type-casted
InfluxDB
7 changes: 0 additions & 7 deletions gemfiles/rails42.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/rails6.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'sqlite3', platform: :mri
gem 'sqlite3', '~> 1.4', platform: :mri
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
gem 'activerecord', '~> 6.0'

Expand Down
4 changes: 2 additions & 2 deletions gemfiles/rails5.gemfile → gemfiles/rails7.gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

gem 'sqlite3', '~> 1.3.0', platform: :mri
gem 'sqlite3', '~> 1.4', platform: :mri
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
gem 'activerecord', '~> 5.2'
gem 'activerecord', '~> 7.0'

gemspec path: '..'
8 changes: 4 additions & 4 deletions influxer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.files = Dir.glob("lib/**/*") + %w[README.md LICENSE.txt CHANGELOG.md]
s.require_paths = ["lib"]

s.required_ruby_version = ">= 2.4.0"
s.required_ruby_version = ">= 2.7.6"

s.metadata = {
"bug_tracker_uri" => "http://github.com/palkan/influxer/issues",
Expand All @@ -25,9 +25,9 @@ Gem::Specification.new do |s|
"source_code_uri" => "http://github.com/palkan/influxer"
}

s.add_dependency "activemodel", ">= 3.2.0"
s.add_dependency "influxdb", "~> 0.3"
s.add_dependency "anyway_config", ">= 1.0"
s.add_dependency "activemodel", ">= 6.0"
s.add_dependency "influxdb", "~> 0.8"
s.add_dependency "anyway_config", ">= 2.0"

s.add_development_dependency "timecop"
s.add_development_dependency "rake", "~> 10.1"
Expand Down
4 changes: 4 additions & 0 deletions lib/influxer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def self.active_model3?
ActiveModel::VERSION::MAJOR == 3
end

def self.thread_registry_support?
ActiveModel::VERSION::MAJOR < 7
end

require "influxer/config"
require "influxer/client"
require "influxer/metrics/metrics"
Expand Down
2 changes: 1 addition & 1 deletion lib/influxer/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Influxer
# InfluxDB API client
class Client < ::InfluxDB::Client
def initialize
super(nil, Influxer.config.as_json.symbolize_keys!)
super(**Influxer.config.to_h.symbolize_keys)
end

def time_precision
Expand Down
15 changes: 15 additions & 0 deletions lib/influxer/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ class Config < Anyway::Config

def load(*)
super

# we want pass @cache value as options to cache store, so we want it to be a Hash
self.cache_enabled = false if cache.blank? || cache_enabled == false
if cache_enabled.nil?
self.cache_enabled = cache_enabled_value
end
end

def cache=(value)
super
self.cache_enabled = cache_enabled_value
end

private

def cache_enabled_value
cache.present?
end
end
end
20 changes: 20 additions & 0 deletions lib/influxer/metrics/relation/time_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ def since(val)
where("time > #{val.to_i}s")
end

# Shortcut to define start point of the time interval including the time provided.
# Accepts DateTime objects.

def since_including(val)
where("time >= #{quoted(val, "time")}")
end

# Shortcut to define end point of the time interval excluding the time provided.
# Accepts DateTime objects.

def before(val)
where("time < #{quoted(val, "time")}")
end

# Shortcut to define end point of the time interval including the time provided.
# Accepts DateTime objects.
def before_including(val)
where("time <= #{quoted(val, "time")}")
end

private

def build_fill(val)
Expand Down
19 changes: 13 additions & 6 deletions lib/influxer/metrics/relation/where_clause.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ def load
protected

def build_where(args, hargs, negate)
if args.present? && args[0].is_a?(String)
where_values.concat(args.map { |str| "(#{str})" })
if args.present?
if args[0].is_a?(String)
where_values.concat(args.map { |str| "(#{str})" })
elsif args[0].is_a?(Hash)
build_hash_where(args[0], negate)
else
false
end
elsif hargs.present?
build_hash_where(hargs, negate)
else
Expand Down Expand Up @@ -83,18 +89,19 @@ def build_in(key, arr, negate)
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength, Style/IfInsideElse
def build_range(key, val, negate)
if val.exclude_end?

# begin...end range
if negate
"#{key} < #{quoted(val.begin, key)} or #{key} >= #{quoted(val.end, key)}"
[val.begin.nil? ? nil : "#{key} < #{quoted(val.begin, key)}", val.end.nil? ? nil : "#{key} >= #{quoted(val.end, key)}"].compact.join(" or ")
else
"#{key} >= #{quoted(val.begin, key)} and #{key} < #{quoted(val.end, key)}"
[val.begin.nil? ? nil : "#{key} >= #{quoted(val.begin, key)}", val.end.nil? ? nil : "#{key} < #{quoted(val.end, key)}"].compact.join(" and ")
end
else
# begin..end range
if negate
"#{key} < #{quoted(val.begin, key)} or #{key} > #{quoted(val.end, key)}"
[val.begin.nil? ? nil : "#{key} < #{quoted(val.begin, key)}", val.end.nil? ? nil : "#{key} > #{quoted(val.end, key)}"].compact.join(" or ")
else
"#{key} >= #{quoted(val.begin, key)} and #{key} <= #{quoted(val.end, key)}"
[val.begin.nil? ? nil : "#{key} >= #{quoted(val.begin, key)}", val.end.nil? ? nil : "#{key} <= #{quoted(val.end, key)}"].compact.join(" and ")
end
end
end
Expand Down
Loading

0 comments on commit 69bd7a8

Please sign in to comment.