active_flux 0.1.0.alfa

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9e84076fd18aa62c6feccf4ee4b61af9c18a076af5a4f688e30edee744edb6b8
4
+ data.tar.gz: ab82201934a7cb34b0aa6f32852ee596ecf5a53c84bc72ad4cd31a152ca59411
5
+ SHA512:
6
+ metadata.gz: e05966ba4b67304a2b1944656f458562105a74958b8f001a6a27fa36e54c4b3dac34562ee24c48c9cdb441c7ea85637d0b6bf3ea881dce371ed585889e9ceff6
7
+ data.tar.gz: 2ad33fa978a42bb52fda92dae0b5590b1ecde0efed59393741aadd8af7bd238ae25350f69957f9b6639e7188f13edd7c8ddb351e0023bafaff2653728e526ff0
data/.DS_Store ADDED
Binary file
data/.byebug_history ADDED
@@ -0,0 +1,4 @@
1
+ c
2
+ ActiveFlux.query('from(bucket: "my-bucket") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
3
+ res.class
4
+ res
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,175 @@
1
+ # Allow longer lines and methods
2
+ Layout/LineLength:
3
+ Max: 500
4
+
5
+ Metrics/MethodLength:
6
+ Max: 30
7
+
8
+ # Tests are declarative, no block length test
9
+ Metrics/BlockLength:
10
+ IgnoredMethods: ["describe", "context", "namespace"]
11
+
12
+ AllCops:
13
+ TargetRubyVersion: 3.0.2
14
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
15
+ # to ignore them, so only the ones explicitly set in this file are enabled.
16
+ DisabledByDefault: true
17
+
18
+ # Prefer &&/|| over and/or.
19
+ Style/AndOr:
20
+ Enabled: true
21
+
22
+ # Align `when` with `case`.
23
+ Layout/CaseIndentation:
24
+ Enabled: true
25
+
26
+ # Align comments with method definitions.
27
+ Layout/CommentIndentation:
28
+ Enabled: true
29
+
30
+ Layout/ElseAlignment:
31
+ Enabled: true
32
+
33
+ # Align `end` with the matching keyword or starting expression except for
34
+ # assignments, where it should be aligned with the LHS.
35
+ Layout/EndAlignment:
36
+ Enabled: true
37
+ EnforcedStyleAlignWith: variable
38
+ AutoCorrect: true
39
+
40
+ Layout/EmptyLineAfterMagicComment:
41
+ Enabled: true
42
+
43
+ # In a regular class definition, no empty lines around the body.
44
+ Layout/EmptyLinesAroundClassBody:
45
+ Enabled: true
46
+
47
+ # In a regular method definition, no empty lines around the body.
48
+ Layout/EmptyLinesAroundMethodBody:
49
+ Enabled: true
50
+
51
+ # In a regular module definition, no empty lines around the body.
52
+ Layout/EmptyLinesAroundModuleBody:
53
+ Enabled: true
54
+
55
+ Layout/FirstArgumentIndentation:
56
+ Enabled: true
57
+
58
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
59
+ Style/HashSyntax:
60
+ Enabled: true
61
+
62
+ # Method definitions after `private` or `protected` isolated calls need one
63
+ # extra level of indentation.
64
+ Layout/IndentationConsistency:
65
+ Enabled: true
66
+ EnforcedStyle: indented_internal_methods
67
+
68
+ # Two spaces, no tabs (for indentation).
69
+ Layout/IndentationWidth:
70
+ Enabled: true
71
+
72
+ Layout/LeadingCommentSpace:
73
+ Enabled: true
74
+
75
+ Layout/SpaceAfterColon:
76
+ Enabled: true
77
+
78
+ Layout/SpaceAfterComma:
79
+ Enabled: true
80
+
81
+ Layout/SpaceAroundEqualsInParameterDefault:
82
+ Enabled: true
83
+
84
+ Layout/SpaceAroundKeyword:
85
+ Enabled: true
86
+
87
+ Layout/SpaceAroundOperators:
88
+ Enabled: true
89
+
90
+ Layout/SpaceBeforeComma:
91
+ Enabled: true
92
+
93
+ Layout/SpaceBeforeFirstArg:
94
+ Enabled: true
95
+
96
+ Style/DefWithParentheses:
97
+ Enabled: true
98
+
99
+ # Defining a method with parameters needs parentheses.
100
+ Style/MethodDefParentheses:
101
+ Enabled: true
102
+
103
+ Style/FrozenStringLiteralComment:
104
+ Enabled: true
105
+ EnforcedStyle: always
106
+ Exclude:
107
+ - "actionview/test/**/*.builder"
108
+ - "actionview/test/**/*.ruby"
109
+ - "actionpack/test/**/*.builder"
110
+ - "actionpack/test/**/*.ruby"
111
+ - "activestorage/db/migrate/**/*.rb"
112
+ - "db/migrate/**/*.rb"
113
+ - "db/*.rb"
114
+
115
+ # Use `foo {}` not `foo{}`.
116
+ Layout/SpaceBeforeBlockBraces:
117
+ Enabled: true
118
+
119
+ # Use `foo { bar }` not `foo {bar}`.
120
+ Layout/SpaceInsideBlockBraces:
121
+ Enabled: true
122
+
123
+ # Use `{ a: 1 }` not `{a:1}`.
124
+ Layout/SpaceInsideHashLiteralBraces:
125
+ Enabled: true
126
+
127
+ Layout/SpaceInsideParens:
128
+ Enabled: true
129
+
130
+ # Check quotes usage according to lint rule below.
131
+ Style/StringLiterals:
132
+ Enabled: true
133
+ EnforcedStyle: single_quotes
134
+
135
+ # Detect hard tabs, no hard tabs.
136
+ Layout/IndentationStyle:
137
+ Enabled: true
138
+
139
+ # Blank lines should not have any spaces.
140
+ Layout/TrailingEmptyLines:
141
+ Enabled: true
142
+
143
+ # No trailing whitespace.
144
+ Layout/TrailingWhitespace:
145
+ Enabled: true
146
+
147
+ # Use quotes for string literals when they are enough.
148
+ Style/RedundantPercentQ:
149
+ Enabled: true
150
+
151
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
152
+ Lint/RequireParentheses:
153
+ Enabled: true
154
+
155
+ Lint/RedundantStringCoercion:
156
+ Enabled: true
157
+
158
+ # Supports --auto-correct
159
+ Style/RedundantSelf:
160
+ Description: Don't use self where it's not needed.
161
+ StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-self-unless-required
162
+ Enabled: true
163
+
164
+ Style/RedundantReturn:
165
+ Enabled: true
166
+ AllowMultipleReturnValues: true
167
+
168
+ Style/Semicolon:
169
+ Enabled: true
170
+ AllowAsExpressionSeparator: true
171
+
172
+ # Prefer Foo.method over Foo::method
173
+ Style/ColonMethodCall:
174
+ Enabled: true
175
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Releases]
2
+
3
+ ## [0.1.0] - 2022-05-17
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at lapoelisacci@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in active_flux.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rubocop', '~> 1.21'
11
+
12
+ gem 'rspec', '~> 3'
13
+
14
+ gem 'simplecov', require: false, group: :test
15
+
16
+ gem 'byebug', group: :development
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active_flux (0.1.0.alfa)
5
+ activemodel (>= 5)
6
+ activesupport (>= 5)
7
+ influx (~> 0)
8
+ influxdb-client (~> 2)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (7.0.3)
14
+ activesupport (= 7.0.3)
15
+ activesupport (7.0.3)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ ast (2.4.2)
21
+ byebug (11.1.3)
22
+ concurrent-ruby (1.1.10)
23
+ diff-lcs (1.5.0)
24
+ docile (1.4.0)
25
+ i18n (1.10.0)
26
+ concurrent-ruby (~> 1.0)
27
+ influx (0.1.0)
28
+ influxdb-client (2.4.0)
29
+ minitest (5.15.0)
30
+ parallel (1.22.0)
31
+ parser (3.1.1.0)
32
+ ast (~> 2.4.1)
33
+ rainbow (3.1.1)
34
+ rake (13.0.6)
35
+ regexp_parser (2.2.1)
36
+ rexml (3.2.5)
37
+ rspec (3.10.0)
38
+ rspec-core (~> 3.10.0)
39
+ rspec-expectations (~> 3.10.0)
40
+ rspec-mocks (~> 3.10.0)
41
+ rspec-core (3.10.2)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-expectations (3.10.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-mocks (3.10.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-support (3.10.3)
50
+ rubocop (1.26.1)
51
+ parallel (~> 1.10)
52
+ parser (>= 3.1.0.0)
53
+ rainbow (>= 2.2.2, < 4.0)
54
+ regexp_parser (>= 1.8, < 3.0)
55
+ rexml
56
+ rubocop-ast (>= 1.16.0, < 2.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (>= 1.4.0, < 3.0)
59
+ rubocop-ast (1.16.0)
60
+ parser (>= 3.1.1.0)
61
+ ruby-progressbar (1.11.0)
62
+ simplecov (0.21.2)
63
+ docile (~> 1.1)
64
+ simplecov-html (~> 0.11)
65
+ simplecov_json_formatter (~> 0.1)
66
+ simplecov-html (0.12.3)
67
+ simplecov_json_formatter (0.1.4)
68
+ tzinfo (2.0.4)
69
+ concurrent-ruby (~> 1.0)
70
+ unicode-display_width (2.1.0)
71
+
72
+ PLATFORMS
73
+ arm64-darwin-21
74
+
75
+ DEPENDENCIES
76
+ active_flux!
77
+ byebug
78
+ rake (~> 13.0)
79
+ rspec (~> 3)
80
+ rubocop (~> 1.21)
81
+ simplecov
82
+
83
+ BUNDLED WITH
84
+ 2.3.13
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Lapo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # ActiveFlux
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_flux`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add active_flux
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install active_flux
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_flux. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/active_flux/blob/main/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the ActiveFlux project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_flux/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFlux
4
+ class Base
5
+ extend Querying
6
+ include ModelSchema
7
+ include Point
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFlux
4
+ module ModelSchema
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def bucket
9
+ @bucket || ActiveFlux.config.bucket
10
+ end
11
+
12
+ def bucket=(value)
13
+ value = value && value.to_s
14
+ return if value == @bucket && defined?(@bucket)
15
+
16
+ @bucket = value
17
+ end
18
+
19
+ def measurement
20
+ @measurement
21
+ end
22
+
23
+ def measurement=(value)
24
+ value = value && value.to_s
25
+ return if value == @measurement && defined?(@measurement)
26
+
27
+ @measurement = value
28
+ end
29
+
30
+ def org
31
+ @org || ActiveFlux.config.org
32
+ end
33
+
34
+ def org=(value)
35
+ value = value && value.to_s
36
+ return if value == @org && defined?(@org)
37
+
38
+ @org = value
39
+ end
40
+
41
+ def tags
42
+ @tags
43
+ end
44
+
45
+ def tags=(value)
46
+ return if value == @tags && defined?(@tags)
47
+
48
+ @tags = value
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFlux
4
+ module Point
5
+ def self.included(base)
6
+ base.include ActiveModel::API
7
+ base.include InstanceMethods
8
+ base.send(:attr_accessor, :measurement, :tags, :fields, :time)
9
+ end
10
+
11
+ module InstanceMethods
12
+ def initialize(measurement = self.class.measurement, tags: self.class.tags, fields:, time: Influx.now)
13
+ @measurement = measurement
14
+ @tags = tags
15
+ @fields = fields
16
+ @time = time
17
+ end
18
+
19
+ def to_influx
20
+ Influx::Point.new(measurement, tags: tags, fields: fields, time: time)
21
+ end
22
+
23
+ def to_h
24
+ {
25
+ measurement: measurement,
26
+ tags: tags,
27
+ fields: fields,
28
+ time: time
29
+ }
30
+ end
31
+
32
+ def save
33
+ ActiveFlux.write(data: to_influx.to_flux, bucket: self.class.bucket, org: self.class.org)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFlux
4
+ module QueryMethods
5
+ def inspect
6
+ "#<#{self.class}>"
7
+ end
8
+
9
+ def self.inspected
10
+ @inspected ||= []
11
+ end
12
+
13
+ def raw
14
+ ActiveFlux.query_raw(query: to_flux)
15
+ end
16
+
17
+ def query
18
+ ActiveFlux.query(query: to_flux)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFlux
4
+ module Querying
5
+ extend ActiveSupport::Concern
6
+
7
+ QUERYING_METHODS = [
8
+ :aggregate_window,
9
+ :cumulative_sum,
10
+ :derivative,
11
+ :fill,
12
+ :filter,
13
+ :first,
14
+ :group,
15
+ :histogram,
16
+ :increase,
17
+ :last,
18
+ :limit,
19
+ :median,
20
+ :moving_average,
21
+ :quantile,
22
+ :range,
23
+ :sort,
24
+ :timed_moving_average
25
+ ].freeze
26
+
27
+ delegate(*QUERYING_METHODS, to: :influx_query)
28
+
29
+ def influx_query
30
+ Influx::Query.new(bucket: bucket)
31
+ end
32
+
33
+ Influx::Query.send(:include, ActiveFlux::QueryMethods)
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFlux
4
+ VERSION = '0.1.0.alfa'
5
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model'
4
+ require 'active_support'
5
+ # require 'active_support/concern'
6
+ # require 'active_support/configurable'
7
+ # require 'active_support/core_ext/module/delegation'
8
+ # require 'active_support/dependencies/autoload'
9
+
10
+ require 'influx'
11
+ require 'influxdb-client'
12
+
13
+ require_relative 'active_flux/version'
14
+
15
+ module ActiveFlux
16
+ extend ActiveSupport::Autoload
17
+
18
+ autoload :Base
19
+ autoload :Callbacks
20
+ autoload :ModelSchema
21
+ autoload :Point
22
+ autoload :Querying
23
+ autoload :QueryMethods
24
+
25
+ include ActiveSupport::Configurable
26
+
27
+ config_accessor :precision do
28
+ InfluxDB2::WritePrecision::NANOSECOND
29
+ end
30
+
31
+ config_accessor :open_timeout, :write_timeout, :read_timeout, :max_redirect_count do
32
+ 10
33
+ end
34
+
35
+ config_accessor :redirect_forward_authorization, :use_ssl do
36
+ true
37
+ end
38
+
39
+ config_accessor :verify_mode do
40
+ OpenSSL::SSL::VERIFY_NONE
41
+ end
42
+
43
+ class << self
44
+ attr_accessor :client
45
+
46
+ def client
47
+ @@client ||= InfluxDB2::Client.new(
48
+ config.host,
49
+ config.token,
50
+ **config.except(:host, :token)
51
+ )
52
+ end
53
+
54
+ delegate :delete, to: :delete_api
55
+ delegate :query, :query_stream, :query_raw, to: :query_api
56
+ delegate :write, to: :write_api
57
+
58
+ private
59
+
60
+ #
61
+ # InfluxDB2::DeleteApi
62
+ #
63
+ # @return [InfluxDB2::DeleteApi] the delete API
64
+ #
65
+ def delete_api
66
+ @@delete_api ||= client.create_delete_api
67
+ end
68
+
69
+ #
70
+ # InfluxDB2::QueryApi
71
+ #
72
+ # @return [InfluxDB2::QueryApi] the query API
73
+ #
74
+ def query_api
75
+ @@query_api ||= client.create_query_api
76
+ end
77
+
78
+ #
79
+ # InfluxDB2::WriteApi
80
+ #
81
+ # @param [InfluxDB2::WriteOptions] options the write options
82
+ #
83
+ # @return [InfluxDB2::WriteApi] the write API
84
+ #
85
+ def write_api(options: InfluxDB2::SYNCHRONOUS)
86
+ @@write_api ||= client.create_write_api(write_options: options)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ # Creates the ActiveFlux initializer file for Rails apps.
6
+ #
7
+ # @example Invokation from terminal
8
+ # rails generate active_flux
9
+ #
10
+ class ActiveFluxGenerator < Rails::Generators::Base
11
+ desc "Description:\n This creates a Rails initializer for ActiveFlux"
12
+
13
+ source_root File.expand_path('templates', __dir__)
14
+
15
+ desc 'Configures ActiveFlux to connect to InfluxDB'
16
+ def generate_layout
17
+ template 'initializer.rb', 'config/initializers/active_flux.rb'
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveFlux.configure do |config|
4
+ config.host = 'http://localhost:8086'
5
+ config.token = 'my-token'
6
+
7
+ # Optional
8
+ # config.bucket = 'my-bucket'
9
+ # config.org = 'my-org'
10
+ # config.precision = InfluxDB2::WritePrecision::NANOSECOND # or MICROSECOND, MILLISECOND, SECOND
11
+ # config.open_timeout = 10 # Number of seconds to wait for the connection to open
12
+ # config.write_timeout = 10 # Number of seconds to wait for one block of data to be written
13
+ # config.read_timeout = 10 # Number of seconds to wait for one block of data to be read
14
+ # config.max_redirect_count = 10 # Maximal number of followed HTTP redirects
15
+ # config.redirect_forward_authorization = false # Pass Authorization header to different domain during HTTP redirect.
16
+ # config.use_ssl = true # Turn on/off SSL for HTTP communication
17
+ # config.verify_mode = OpenSSL::SSL::VERIFY_NONE # or OpenSSL::SSL::VERIFY_PEER
18
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveFlux
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_flux
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alfa
5
+ platform: ruby
6
+ authors:
7
+ - Lapo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: influx
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: influxdb-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
69
+ description: The gem allows you to query InfluxDB with Flux syntax in an ORM fashion.
70
+ email:
71
+ - lapoelisacci@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".DS_Store"
77
+ - ".byebug_history"
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - lib/active_flux.rb
88
+ - lib/active_flux/base.rb
89
+ - lib/active_flux/model_schema.rb
90
+ - lib/active_flux/point.rb
91
+ - lib/active_flux/query_methods.rb
92
+ - lib/active_flux/querying.rb
93
+ - lib/active_flux/version.rb
94
+ - lib/generators/active_flux.rb
95
+ - lib/generators/templates/initializer.rb
96
+ - sig/active_flux.rbs
97
+ homepage: https://github.com/LapoElisacci/active_flux
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ homepage_uri: https://github.com/LapoElisacci/active_flux
102
+ source_code_uri: https://github.com/LapoElisacci/active_flux
103
+ changelog_uri: https://github.com/LapoElisacci/active_flux/blob/main/CHANGELOG.md
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 2.6.0
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.1
118
+ requirements: []
119
+ rubygems_version: 3.2.22
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Ruby ORM for Flux
123
+ test_files: []