infield 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9458fc81e6f321f72ee910bfcb944ff359c0e47b27f2c6de6a9fb2650a41970b
4
+ data.tar.gz: d66a3b866bd8e0999b9d1f9b70f8d334f968a5cc542b0a25a0aa99512438f245
5
+ SHA512:
6
+ metadata.gz: 6e37fb65c690b43432782df71af7a21062f0fe474351645dbba95e8e7c1e11051e815a1b68535c5b12e74aa364485ee500f90ee84cfd86ced133c28e594736f4
7
+ data.tar.gz: f9404e0e124318e96dcf86d07cb7c8d45b999fa043bae7a6cae1f5b4acbed5661601223b1f853f8306f9ff12f02537a631bc47b9156e6c6231a8fad11c6c7011
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.0
3
+
4
+ Style/StringLiteralsInInterpolation:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Layout/LineLength:
9
+ Max: 120
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-11-14
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Infield
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,3 @@
1
+ # Infield
2
+
3
+ This gem handles reporting deprecation warnings to Infield.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'infield'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Infield
4
+ module Core
5
+ def warn(*messages, **xargs)
6
+ super
7
+
8
+ callstack = caller_locations(1 + xargs[:uplevel].to_i)
9
+ Infield::DeprecationWarning.log(*messages, callstack: callstack, validated: xargs[:category] == :deprecated)
10
+ end
11
+ end
12
+
13
+ Kernel.prepend(Core)
14
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'concurrent/array'
4
+ require 'concurrent/atomic/event'
5
+ require 'net/http'
6
+
7
+ module Infield
8
+ module DeprecationWarning
9
+ Task = Struct.new(:message, :callstack)
10
+
11
+ module Runner
12
+ class << self
13
+ def event
14
+ @event ||= Concurrent::Event.new
15
+ end
16
+
17
+ def tasks
18
+ @tasks ||= Concurrent::Array.new
19
+ end
20
+
21
+ def run
22
+ Thread.new { loop { event.wait.then { deliver }.then { event.reset } } }
23
+ end
24
+
25
+ private
26
+
27
+ def default_api_params
28
+ { repo_environment_id: Infield.repo_environment_id,
29
+ environment: Infield.environment }
30
+ end
31
+
32
+ def infield_api_uri
33
+ URI.parse(ENV['INFIELD_API_URL'] || 'http://127.0.0.1:3000' || 'https://app.infield.ai')
34
+ end
35
+
36
+ def upload_message(task)
37
+ http = Net::HTTP.new(infield_api_uri.host, infield_api_uri.port)
38
+ http.post('/api/raw_deprecation_warnings',
39
+ default_api_params.merge(message: task.message).to_json,
40
+ { 'Content-Type' => 'application/json', 'Authorization' => "bearer #{Infield.api_key}" })
41
+ end
42
+
43
+ def deliver
44
+ while (task = tasks.shift)
45
+ upload_message(task)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ class << self
52
+ def log(*messages, callstack: nil, validated: false)
53
+ callstack ||= caller_locations(2)
54
+ messages = messages.select(&method(:valid_message)) unless validated
55
+ messages.each { |message| tasks << Task.new(message, callstack) }
56
+ Runner.event.set
57
+ end
58
+
59
+ private
60
+
61
+ delegate :tasks, to: 'Infield::DeprecationWarning::Runner'
62
+
63
+ def valid_message(message)
64
+ message =~ /(?:^|\W)deprecated(?:$|\W)/i
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Infield
4
+ class Railtie < Rails::Railtie
5
+ initializer 'infield.deprecation_warnings', after: 'active_support.deprecation_behavior' do |_app|
6
+ ActiveSupport::Notifications.subscribe('deprecation.rails') do |_name, _start, _finish, _id, payload|
7
+ Infield::DeprecationWarning.log(payload[:message], callstack: payload[:callstack], validated: true)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Infield
4
+ VERSION = '0.1.0'
5
+ end
data/lib/infield.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'infield/version'
4
+
5
+ # require_relative 'infield/core_ext'
6
+ require_relative 'infield/rails' if defined?(Rails)
7
+
8
+ module Infield
9
+ Error = Class.new(StandardError)
10
+
11
+ autoload :DeprecationWarning, "#{__dir__}/infield/deprecation_warning.rb"
12
+
13
+ class << self
14
+ attr_accessor :api_key, :repo_environment_id, :environment
15
+
16
+ def run(api_key: nil, repo_environment_id: nil, environment: nil)
17
+ @api_key = api_key || ENV['INFIELD_API_KEY']
18
+ @repo_environment_id = repo_environment_id
19
+ raise 'API key is required' unless @api_key
20
+ raise 'repo_environment_id is required' unless @repo_environment_id
21
+
22
+ @environment = environment || defined?(Rails) ? Rails.env : nil
23
+ DeprecationWarning::Runner.run
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infield
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Infield
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description:
28
+ email:
29
+ - support@infield.ai
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - ".ruby-version"
37
+ - CHANGELOG.md
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - lib/infield.rb
43
+ - lib/infield/core_ext.rb
44
+ - lib/infield/deprecation_warning.rb
45
+ - lib/infield/rails.rb
46
+ - lib/infield/version.rb
47
+ homepage:
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.0.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.4.19
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Send deprecation warnings to Infield
70
+ test_files: []