influxer 0.5.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/gemfiles/rails32.gemfile +7 -0
- data/influxer.gemspec +2 -2
- data/lib/influxer/metrics/active_model3/model.rb +16 -0
- data/lib/influxer/metrics/metrics.rb +12 -2
- data/lib/influxer/metrics/scoping/current_scope.rb +46 -0
- data/lib/influxer/metrics/scoping/old_current_scope.rb +14 -0
- data/lib/influxer/metrics/scoping.rb +7 -38
- data/lib/influxer/version.rb +1 -1
- data/lib/influxer.rb +4 -0
- data/spec/metrics/metrics_spec.rb +12 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 117d8b97d33b7cd7f38c38effae7184c9a4ec602
|
4
|
+
data.tar.gz: 3ae53237115bec8868ebe4db4840c98bf57e18b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b791f7e55f2c096ebb5d269be7498680fce388638f22abd92f0c2e3128da31bbc46302d028b642dac2de93d29d256124b8b9d7d4bcc82437e50ffb54f6721282
|
7
|
+
data.tar.gz: 3a1e42dda73963b45641386b227c24cc893cbc0a9ccc9823d6e04cb171f46d0f7a593fb9a5d0c99d7639837a11aca119e0ec7ceb33238f4392ab744b0804caca
|
data/.travis.yml
CHANGED
data/influxer.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.files = `git ls-files`.split($/)
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
|
-
s.add_dependency "activemodel", '>=
|
18
|
+
s.add_dependency "activemodel", '>= 3.2.0'
|
19
19
|
s.add_dependency "influxdb", "~> 0.3"
|
20
20
|
s.add_dependency "anyway_config", "~>0.3.0"
|
21
21
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency "simplecov", ">= 0.3.8"
|
24
24
|
s.add_development_dependency 'rake', '~> 10.1'
|
25
25
|
s.add_development_dependency 'sqlite3'
|
26
|
-
s.add_development_dependency 'activerecord', '>=
|
26
|
+
s.add_development_dependency 'activerecord', '>= 3.2.0'
|
27
27
|
s.add_development_dependency 'pry-byebug'
|
28
28
|
s.add_development_dependency "rspec", ">= 3.1.0"
|
29
29
|
s.add_development_dependency "webmock", "~> 1.21.0"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Influxer
|
2
|
+
module ActiveModel3
|
3
|
+
# Replacement of ActiveModel::Model for ActiveModel 3
|
4
|
+
module Model
|
5
|
+
def initialize(attributes = {})
|
6
|
+
if attributes
|
7
|
+
attributes.each do |attr, value|
|
8
|
+
public_send("#{attr}=", value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'influxer/metrics/relation'
|
2
2
|
require 'influxer/metrics/scoping'
|
3
|
+
require 'influxer/metrics/active_model3/model'
|
3
4
|
require 'active_model'
|
4
5
|
|
5
6
|
module Influxer
|
@@ -10,7 +11,13 @@ module Influxer
|
|
10
11
|
# rubocop:disable Metrics/ClassLength
|
11
12
|
class Metrics
|
12
13
|
TIME_FACTOR = 1_000_000_000
|
13
|
-
|
14
|
+
|
15
|
+
if Influxer.active_model3?
|
16
|
+
include Influxer::ActiveModel3::Model
|
17
|
+
else
|
18
|
+
include ActiveModel::Model
|
19
|
+
end
|
20
|
+
|
14
21
|
include ActiveModel::Validations
|
15
22
|
extend ActiveModel::Callbacks
|
16
23
|
|
@@ -122,7 +129,6 @@ module Influxer
|
|
122
129
|
# rubocop:enable Metrics/MethodLength
|
123
130
|
end
|
124
131
|
|
125
|
-
delegate :tag_names, to: :class
|
126
132
|
attr_accessor :timestamp
|
127
133
|
|
128
134
|
def initialize(attributes = {})
|
@@ -178,6 +184,10 @@ module Influxer
|
|
178
184
|
@attributes.select { |k, _| tag_names.include?(k.to_s) }
|
179
185
|
end
|
180
186
|
|
187
|
+
def tag_names
|
188
|
+
self.class.tag_names
|
189
|
+
end
|
190
|
+
|
181
191
|
private
|
182
192
|
|
183
193
|
# rubocop:disable Metrics/MethodLength
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'active_support/per_thread_registry'
|
2
|
+
|
3
|
+
module Influxer
|
4
|
+
module Scoping
|
5
|
+
module CurrentScope
|
6
|
+
# Clone of current_scope methods for newer versions of ActiveModel
|
7
|
+
def current_scope
|
8
|
+
ScopeRegistry.value_for(:current_scope, name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def current_scope=(scope)
|
12
|
+
ScopeRegistry.set_value_for(:current_scope, name, scope)
|
13
|
+
end
|
14
|
+
|
15
|
+
class ScopeRegistry # :nodoc:
|
16
|
+
extend ActiveSupport::PerThreadRegistry
|
17
|
+
|
18
|
+
VALID_SCOPE_TYPES = [:current_scope].freeze
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@registry = Hash.new { |hash, key| hash[key] = {} }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Obtains the value for a given +scope_name+ and +variable_name+.
|
25
|
+
def value_for(scope_type, variable_name)
|
26
|
+
raise_invalid_scope_type!(scope_type)
|
27
|
+
@registry[scope_type][variable_name]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Sets the +value+ for a given +scope_type+ and +variable_name+.
|
31
|
+
def set_value_for(scope_type, variable_name, value)
|
32
|
+
raise_invalid_scope_type!(scope_type)
|
33
|
+
@registry[scope_type][variable_name] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def raise_invalid_scope_type!(scope_type)
|
39
|
+
return if VALID_SCOPE_TYPES.include?(scope_type)
|
40
|
+
raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. \
|
41
|
+
Scope types must be included in VALID_SCOPE_TYPES"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Influxer
|
2
|
+
module Scoping
|
3
|
+
# Clone of current_scope methods for older versions of ActiveModel
|
4
|
+
module CurrentScope
|
5
|
+
def current_scope
|
6
|
+
Thread.current["#{self}_current_scope"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_scope=(scope)
|
10
|
+
Thread.current["#{self}_current_scope"] = scope
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,7 +1,12 @@
|
|
1
|
-
require 'active_support/per_thread_registry'
|
2
1
|
require 'influxer/metrics/scoping/default'
|
3
2
|
require 'influxer/metrics/scoping/named'
|
4
3
|
|
4
|
+
if Influxer.active_model3?
|
5
|
+
require 'influxer/metrics/scoping/old_current_scope'
|
6
|
+
else
|
7
|
+
require 'influxer/metrics/scoping/current_scope'
|
8
|
+
end
|
9
|
+
|
5
10
|
module Influxer
|
6
11
|
# Clone of ActiveRecord::Relation scoping
|
7
12
|
module Scoping # :nodoc:
|
@@ -15,43 +20,7 @@ module Influxer
|
|
15
20
|
end
|
16
21
|
|
17
22
|
module ClassMethods # :nodoc:
|
18
|
-
|
19
|
-
ScopeRegistry.value_for(:current_scope, name)
|
20
|
-
end
|
21
|
-
|
22
|
-
def current_scope=(scope)
|
23
|
-
ScopeRegistry.set_value_for(:current_scope, name, scope)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class ScopeRegistry # :nodoc:
|
28
|
-
extend ActiveSupport::PerThreadRegistry
|
29
|
-
|
30
|
-
VALID_SCOPE_TYPES = [:current_scope].freeze
|
31
|
-
|
32
|
-
def initialize
|
33
|
-
@registry = Hash.new { |hash, key| hash[key] = {} }
|
34
|
-
end
|
35
|
-
|
36
|
-
# Obtains the value for a given +scope_name+ and +variable_name+.
|
37
|
-
def value_for(scope_type, variable_name)
|
38
|
-
raise_invalid_scope_type!(scope_type)
|
39
|
-
@registry[scope_type][variable_name]
|
40
|
-
end
|
41
|
-
|
42
|
-
# Sets the +value+ for a given +scope_type+ and +variable_name+.
|
43
|
-
def set_value_for(scope_type, variable_name, value)
|
44
|
-
raise_invalid_scope_type!(scope_type)
|
45
|
-
@registry[scope_type][variable_name] = value
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def raise_invalid_scope_type!(scope_type)
|
51
|
-
return if VALID_SCOPE_TYPES.include?(scope_type)
|
52
|
-
raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. \
|
53
|
-
Scope types must be included in VALID_SCOPE_TYPES"
|
54
|
-
end
|
23
|
+
include Influxer::Scoping::CurrentScope
|
55
24
|
end
|
56
25
|
end
|
57
26
|
end
|
data/lib/influxer/version.rb
CHANGED
data/lib/influxer.rb
CHANGED
@@ -32,7 +32,18 @@ describe Influxer::Metrics, :query do
|
|
32
32
|
specify { is_expected.to respond_to :write! }
|
33
33
|
specify { is_expected.to respond_to :persisted? }
|
34
34
|
specify { is_expected.to respond_to :series }
|
35
|
-
|
35
|
+
if Influxer.active_model3?
|
36
|
+
specify { is_expected.to be_a Influxer::ActiveModel3::Model }
|
37
|
+
else
|
38
|
+
specify { is_expected.to be_a ActiveModel::Model }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#initialize" do
|
43
|
+
it "assigns initial values in constructor" do
|
44
|
+
m = DummyMetrics.new(dummy_id: 1)
|
45
|
+
expect(m.dummy_id).to eq 1
|
46
|
+
end
|
36
47
|
end
|
37
48
|
|
38
49
|
describe "#write" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: influxer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Dem
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: influxdb
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 3.2.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 3.2.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: pry-byebug
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- MIT-LICENSE
|
181
181
|
- README.md
|
182
182
|
- Rakefile
|
183
|
+
- gemfiles/rails32.gemfile
|
183
184
|
- gemfiles/rails42.gemfile
|
184
185
|
- gemfiles/rails5.gemfile
|
185
186
|
- influxer.gemspec
|
@@ -187,14 +188,17 @@ files:
|
|
187
188
|
- lib/influxer/client.rb
|
188
189
|
- lib/influxer/config.rb
|
189
190
|
- lib/influxer/engine.rb
|
191
|
+
- lib/influxer/metrics/active_model3/model.rb
|
190
192
|
- lib/influxer/metrics/metrics.rb
|
191
193
|
- lib/influxer/metrics/relation.rb
|
192
194
|
- lib/influxer/metrics/relation/calculations.rb
|
193
195
|
- lib/influxer/metrics/relation/time_query.rb
|
194
196
|
- lib/influxer/metrics/relation/where_clause.rb
|
195
197
|
- lib/influxer/metrics/scoping.rb
|
198
|
+
- lib/influxer/metrics/scoping/current_scope.rb
|
196
199
|
- lib/influxer/metrics/scoping/default.rb
|
197
200
|
- lib/influxer/metrics/scoping/named.rb
|
201
|
+
- lib/influxer/metrics/scoping/old_current_scope.rb
|
198
202
|
- lib/influxer/model.rb
|
199
203
|
- lib/influxer/rails/client.rb
|
200
204
|
- lib/influxer/version.rb
|