informant-rails 2.0.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 508ce7cb53f750ba6b422a41c966b1fbdd46b623dcb311c4410d80c9b3b95f2f
4
- data.tar.gz: 28662decb01dd5ae5b943a0f099bf68eaf3bbbfd1b6cb31172eb7d1673238b24
3
+ metadata.gz: 3ea25418001e3eab7a6a002c400905fae2c59e43cc43c31897bf04aac59ec499
4
+ data.tar.gz: a2f87283669067d6c79e4c9f892f47e20a7398a42f216fdfd0cecc93ec3812ae
5
5
  SHA512:
6
- metadata.gz: babd9a69b4121f59f3dae1bddc3933d33c083d2f86ad8cc95cd265b8dc7c13c795b8f6803c81764c91a0868357d27f11863bac12c9e83b55bbfbfbfb8f6f2010
7
- data.tar.gz: ec774a339d41ba6c95f82bb37f78eb90280f4c238dcbf4b31f1a7b71abdc5c3ee05bbddeb888e99232cffdceb4a112df59de270c7963623deb130b4eb1765ed0
6
+ metadata.gz: '07936249ff1fecbadddf07edf8f3c2da63b421fd4a29040f27644809ccfe9e7818cf247e675f7ed36635ba5f45efcf017649389e4deb28090f0e2735764b01bd'
7
+ data.tar.gz: f99902c5bed9ad84be24befce881a1d0c29ec632f67166a3a6ed39141e8305883d43c2f7ec34fe3b37397f758d2262e0f577d3dd06e790020ebd26a5b6a78338
data/README.markdown CHANGED
@@ -8,12 +8,11 @@ The informant-rails gem provides Rails and ActiveRecord hooks for The Informant.
8
8
 
9
9
  ## Compatibility
10
10
 
11
- The informant-rails gem officially supports Ruby 2.0+.
11
+ The informant-rails gem officially supports Ruby 2.5+.
12
12
 
13
- It will work automatically with Rails 3 and up as well as Mongoid 3 and up.
13
+ It will work automatically with Rails 5.2+ as well as Mongoid 6.2 and up.
14
14
 
15
- [![Build Status](https://travis-ci.org/informantapp/informant-rails.svg?branch=master)](https://travis-ci.org/informantapp/informant-rails)
16
- [![Code Climate](https://codeclimate.com/github/informantapp/informant-rails.png)](https://codeclimate.com/github/informantapp/informant-rails)
15
+ [![pipeline status](https://gitlab.com/informantapp/informant-rails/badges/master/pipeline.svg)](https://gitlab.com/informantapp/informant-rails/-/commits/master)
17
16
 
18
17
  ## Installation
19
18
 
@@ -28,6 +27,10 @@ It will work automatically with Rails 3 and up as well as Mongoid 3 and up.
28
27
  4. Deploy with the gem installed
29
28
  5. Submit a form and you'll see it appear in our web interface
30
29
 
30
+ We've set up
31
+ [informant-rails-example](https://gitlab.com/informantapp/informant-rails-example)
32
+ as a demonstrate of installation and operation.
33
+
31
34
  ## Usage
32
35
 
33
36
  By default, any request that causes an ActiveRecord or Mongoid model to be validated will be tracked by the Informant once the gem is added to your project.
data/Rakefile CHANGED
@@ -1,12 +1,15 @@
1
- require "bundler/setup"
2
- require "bundler/gem_tasks"
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
3
 
4
- if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
5
- require "appraisal/task"
6
- Appraisal::Task.new
7
- task default: :appraisal
8
- else
9
- require "rspec/core/rake_task"
4
+ default_task = :spec
5
+
6
+ if ENV['APPRAISAL_INITIALIZED']
7
+ require 'rspec/core/rake_task'
10
8
  RSpec::Core::RakeTask.new
11
- task default: :spec
9
+ else
10
+ require 'appraisal/task'
11
+ Appraisal::Task.new
12
+ default_task = :appraisal
12
13
  end
14
+
15
+ task default: default_task
@@ -1,24 +1,13 @@
1
- module InformantRails::Config
2
- extend self
3
-
4
- attr_accessor :api_token, :exclude_models, :filter_parameters, :value_tracking
5
-
6
- self.api_token
7
- self.exclude_models = []
8
- self.filter_parameters = []
9
- self.value_tracking = true
10
-
11
- def configure; yield self end
12
-
13
- def self.client_identifier
14
- @client_identifier ||= "informant-rails-#{InformantRails::VERSION}"
15
- end
16
-
17
- def self.enabled?
18
- api_token.present?
19
- end
20
-
21
- def self.collector_host
22
- @collector_host ||= ENV['INFORMANT_COLLECTOR_HOST'] || 'https://collector-api.informantapp.com'
1
+ module InformantRails
2
+ module Config
3
+ extend self
4
+
5
+ delegate :api_token, :api_token=,
6
+ :collector_host,
7
+ :enabled?,
8
+ :exclude_models, :exclude_models=,
9
+ :filter_parameters, :filter_parameters=,
10
+ :value_tracking?, :value_tracking=,
11
+ to: InformantCommon::Config
23
12
  end
24
13
  end
@@ -1,24 +1,23 @@
1
+ class TestClass
2
+ include ActiveModel::Model
3
+
4
+ attr_accessor :field_name
5
+
6
+ validates_presence_of :field_name
7
+ end
8
+
1
9
  module InformantRails
2
10
  class Diagnostic
3
- def self.run; new.run end
11
+ def self.run
12
+ new.run
13
+ end
4
14
 
5
15
  def run
6
16
  if Config.api_token.blank?
7
17
  Rails.logger.info missing_api_token_message
8
18
  else
9
- Client.record('REQUEST_METHOD' => 'POST')
10
- Client.record_action('Connectivity', 'test')
11
- Client.request.instance_variable_set('@models', [{
12
- name: 'TestClass',
13
- errors: [name: 'field_name', value: 'field_value', message: 'must be unique']
14
- }])
15
- response = Client.transmit(Client.request)
16
-
17
- if response.code == '204'
18
- Rails.logger.info success_message
19
- else
20
- Rails.logger.info bad_response_message(response.body)
21
- end
19
+ response = InformantCommon::Client.transmit(test_form_submission).join.value
20
+ display_response_message(response)
22
21
  end
23
22
 
24
23
  Rails.logger.info assistance_message
@@ -44,11 +43,26 @@ module InformantRails
44
43
  end
45
44
 
46
45
  def success_message
47
- "Everything looks good. You should see a test request on your dashboard."
46
+ 'Everything looks good. You should see a test request on your dashboard.'
48
47
  end
49
48
 
50
49
  def assistance_message
51
50
  "If you need assistance or have any questions, send an email to support@informantapp.com or tweet @informantapp and we'll help you out!"
52
51
  end
52
+
53
+ def test_form_submission
54
+ InformantCommon::Event::FormSubmission.new.tap do |form_submission|
55
+ form_submission.handler = 'Connectivity#test'
56
+ form_submission.process_model(InformantCommon::Model::ActiveModel.new(TestClass.new.tap(&:valid?)))
57
+ end
58
+ end
59
+
60
+ def display_response_message(response)
61
+ if response.code == '204'
62
+ Rails.logger.info success_message
63
+ else
64
+ Rails.logger.info bad_response_message(response.body)
65
+ end
66
+ end
53
67
  end
54
68
  end
@@ -1,9 +1,13 @@
1
1
  module InformantRails
2
- class Middleware < Struct.new(:app)
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
3
7
  def call(env)
4
- Client.record(env)
5
- response = app.call(env)
6
- Client.process
8
+ InformantCommon::Client.start_transaction!(env['REQUEST_METHOD'])
9
+ response = @app.call(env)
10
+ InformantCommon::Client.process
7
11
  response
8
12
  end
9
13
  end
@@ -1,30 +1,31 @@
1
1
  module InformantRails
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer 'informant' do |config|
4
- Config.api_token ||= ENV['INFORMANT_API_KEY']
4
+ if Config.enabled?
5
+ InformantCommon::Client.transmit(
6
+ InformantCommon::Event::AgentInfo.new(
7
+ agent_identifier: "informant-rails-#{InformantRails::VERSION}",
8
+ framework_version: "rails-#{Rails.version}"
9
+ )
10
+ )
11
+ InformantRails::Config.filter_parameters = Rails.configuration.filter_parameters
5
12
 
6
- begin
7
- if Config.enabled?
8
- InformantRails::Client.log_client_info
9
- InformantRails::Config.filter_parameters = Rails.configuration.filter_parameters
13
+ config.middleware.use InformantRails::Middleware
10
14
 
11
- config.middleware.use InformantRails::Middleware
12
-
13
- ActiveSupport.on_load(:action_controller) do
14
- include InformantRails::RequestTracking
15
- end
15
+ ActiveSupport.on_load(:action_controller) do
16
+ include InformantRails::RequestTracking
17
+ end
16
18
 
17
- ActiveSupport.on_load(:active_record) do
18
- include InformantRails::ValidationTracking
19
- end
19
+ ActiveSupport.on_load(:active_record) do
20
+ include InformantRails::ValidationTracking
21
+ end
20
22
 
21
- ActiveSupport.on_load(:mongoid) do
22
- include InformantRails::ValidationTracking
23
- end
23
+ ActiveSupport.on_load(:mongoid) do
24
+ include InformantRails::ValidationTracking
24
25
  end
25
- rescue
26
- puts "Unable to bootstrap informant."
27
26
  end
27
+ rescue StandardError => e
28
+ puts "Unable to bootstrap informant: #{e.message}"
28
29
  end
29
30
  end
30
31
  end
@@ -5,11 +5,11 @@ module InformantRails
5
5
  included do
6
6
  if defined? before_action
7
7
  before_action do
8
- InformantRails::Client.record_action(controller_name, action_name)
8
+ InformantCommon::Client.current_transaction&.handler = [controller_name, action_name].join('#')
9
9
  end
10
10
  else
11
11
  before_filter do
12
- InformantRails::Client.record_action(controller_name, action_name)
12
+ InformantCommon::Client.current_transaction&.handler = [controller_name, action_name].join('#')
13
13
  end
14
14
  end
15
15
  end
@@ -3,9 +3,7 @@ module InformantRails
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- set_callback(:validate, :after) do
7
- InformantRails::Client.record_validated_model(self)
8
- end
6
+ include InformantCommon::ValidationTracking
9
7
  end
10
8
  end
11
9
  end
@@ -1,3 +1,3 @@
1
1
  module InformantRails
2
- VERSION = '2.0.1'
2
+ VERSION = '2.4.0'.freeze
3
3
  end
@@ -3,23 +3,15 @@ if defined?(Rake)
3
3
  Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
4
4
  end
5
5
 
6
+ require 'informant-common'
7
+
6
8
  module InformantRails
7
9
  autoload :Config, 'informant-rails/config'
8
10
  autoload :Diagnostic, 'informant-rails/diagnostic'
9
- autoload :Client, 'informant-rails/client'
10
- autoload :FieldError, 'informant-rails/field_error'
11
11
  autoload :Middleware, 'informant-rails/middleware'
12
- autoload :Model, 'informant-rails/model'
13
- autoload :ParameterFilter, 'informant-rails/parameter_filter'
14
12
  autoload :RequestTracking, 'informant-rails/request_tracking'
15
13
  autoload :ValidationTracking, 'informant-rails/validation_tracking'
16
14
  autoload :VERSION, 'informant-rails/version'
17
-
18
- module Event
19
- autoload :Base, 'informant-rails/event/base'
20
- autoload :ClientInfo, 'informant-rails/event/client_info'
21
- autoload :FormSubmission, 'informant-rails/event/form_submission'
22
- end
23
15
  end
24
16
 
25
17
  require 'informant-rails/railtie'
@@ -1,9 +1,7 @@
1
1
  namespace :informant do
2
-
3
- desc "Verify connectivity from your app to Informant"
4
- task :diagnostic => :environment do
5
- Rails.logger = Logger.new(STDOUT)
2
+ desc 'Verify connectivity from your app to Informant'
3
+ task diagnostic: :environment do
4
+ Rails.logger = Logger.new($stdout)
6
5
  InformantRails::Diagnostic.run
7
6
  end
8
-
9
7
  end
metadata CHANGED
@@ -1,35 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: informant-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Informant, LLC
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2021-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: informant-common
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.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.2.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: 3.2.0
33
+ version: 5.2.0
20
34
  - - "<"
21
35
  - !ruby/object:Gem::Version
22
- version: 7.0.0
36
+ version: 8.0.0
23
37
  type: :runtime
24
38
  prerelease: false
25
39
  version_requirements: !ruby/object:Gem::Requirement
26
40
  requirements:
27
41
  - - ">="
28
42
  - !ruby/object:Gem::Version
29
- version: 3.2.0
43
+ version: 5.2.0
30
44
  - - "<"
31
45
  - !ruby/object:Gem::Version
32
- version: 7.0.0
46
+ version: 8.0.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: appraisal
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
33
61
  description: The Informant tracks what users do wrong in your forms so you can make
34
62
  them better.
35
63
  email:
@@ -42,16 +70,9 @@ files:
42
70
  - README.markdown
43
71
  - Rakefile
44
72
  - lib/informant-rails.rb
45
- - lib/informant-rails/client.rb
46
73
  - lib/informant-rails/config.rb
47
74
  - lib/informant-rails/diagnostic.rb
48
- - lib/informant-rails/event/base.rb
49
- - lib/informant-rails/event/client_info.rb
50
- - lib/informant-rails/event/form_submission.rb
51
- - lib/informant-rails/field_error.rb
52
75
  - lib/informant-rails/middleware.rb
53
- - lib/informant-rails/model.rb
54
- - lib/informant-rails/parameter_filter.rb
55
76
  - lib/informant-rails/railtie.rb
56
77
  - lib/informant-rails/request_tracking.rb
57
78
  - lib/informant-rails/validation_tracking.rb
@@ -60,8 +81,9 @@ files:
60
81
  homepage: https://www.informantapp.com
61
82
  licenses:
62
83
  - MIT
63
- metadata: {}
64
- post_install_message:
84
+ metadata:
85
+ rubygems_mfa_required: 'true'
86
+ post_install_message:
65
87
  rdoc_options: []
66
88
  require_paths:
67
89
  - lib
@@ -69,16 +91,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
91
  requirements:
70
92
  - - ">="
71
93
  - !ruby/object:Gem::Version
72
- version: '0'
94
+ version: 2.6.0
73
95
  required_rubygems_version: !ruby/object:Gem::Requirement
74
96
  requirements:
75
97
  - - ">="
76
98
  - !ruby/object:Gem::Version
77
99
  version: '0'
78
100
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.7.8
81
- signing_key:
101
+ rubygems_version: 3.2.32
102
+ signing_key:
82
103
  specification_version: 4
83
104
  summary: The Informant tracks server-side validation errors and gives you metrics
84
105
  you never dreamed of.
@@ -1,63 +0,0 @@
1
- require 'net/http'
2
-
3
- module InformantRails
4
- class Client
5
-
6
- def self.supported_request_methods
7
- @supported_request_methods ||= %w(POST PATCH PUT DELETE)
8
- end
9
-
10
- def self.record(env)
11
- new_request if supported_request_methods.include?(env['REQUEST_METHOD'])
12
- end
13
-
14
- def self.record_action(controller_name, action)
15
- if request
16
- request.filename = controller_name
17
- request.action = action
18
- end
19
- end
20
-
21
- def self.record_validated_model(model)
22
- request.process_model(model) if request && include_model?(model)
23
- end
24
-
25
- def self.process
26
- if request && request.models.any?
27
- this_request = request
28
- Thread.new { transmit(this_request) }
29
- end
30
- ensure
31
- cleanup
32
- end
33
-
34
- def self.request
35
- Thread.current[:informant_request]
36
- end
37
-
38
- def self.cleanup
39
- Thread.current[:informant_request] = nil
40
- end
41
-
42
- def self.transmit(event)
43
- Net::HTTP.start(*event.net_http_start_arguments) do |http|
44
- http.request(event.post_request)
45
- end
46
- end
47
-
48
- def self.log_client_info
49
- transmit(InformantRails::Event::ClientInfo.new)
50
- end
51
-
52
- private
53
-
54
- def self.include_model?(model)
55
- !Config.exclude_models.include?(model.class.to_s)
56
- end
57
-
58
- def self.new_request
59
- Thread.current[:informant_request] = Event::FormSubmission.new
60
- end
61
-
62
- end
63
- end
@@ -1,25 +0,0 @@
1
- module InformantRails::Event
2
- class Base
3
- def self.endpoint
4
- raise 'Must implement'
5
- end
6
- def endpoint; self.class.endpoint end
7
-
8
- def self.authorization_header_value
9
- @authorization_header_value ||= ActionController::HttpAuthentication::Token.encode_credentials(InformantRails::Config.api_token)
10
- end
11
- def authorization_header_value; self.class.authorization_header_value end
12
-
13
- def post_request
14
- Net::HTTP::Post.new(endpoint, {
15
- "Authorization" => authorization_header_value,
16
- "Content-Type" => "application/json"
17
- }).tap { |r| r.body = to_json }
18
- end
19
-
20
- def self.net_http_start_arguments
21
- @net_http_start_arguments ||= [endpoint.host, endpoint.port, use_ssl: endpoint.scheme == 'https']
22
- end
23
- def net_http_start_arguments; self.class.net_http_start_arguments end
24
- end
25
- end
@@ -1,16 +0,0 @@
1
- module InformantRails::Event
2
- class ClientInfo < Base
3
- def as_json(*args)
4
- {
5
- agent_identifier: InformantRails::Config.client_identifier,
6
- framework_version: "rails-#{Rails.version}",
7
- runtime_version: "ruby-#{RUBY_VERSION}",
8
- mongoid_version: defined?(Mongoid) ? Mongoid::VERSION : nil
9
- }
10
- end
11
-
12
- def self.endpoint
13
- @endpoint ||= URI("#{InformantRails::Config.collector_host}/v2/client-info")
14
- end
15
- end
16
- end
@@ -1,36 +0,0 @@
1
- module InformantRails::Event
2
- class FormSubmission < Base
3
- attr_accessor :request_url, :filename, :action
4
-
5
- def process_model(model)
6
- if model && untracked?(model)
7
- models << InformantRails::Model.new(model)
8
- end
9
- end
10
-
11
- def models
12
- @models ||= []
13
- end
14
-
15
- def as_json(*args)
16
- {
17
- name: [filename, action].compact.join('#'),
18
- models: models.map(&:as_json)
19
- }
20
- end
21
-
22
- def self.endpoint
23
- @endpoint ||= URI("#{InformantRails::Config.collector_host}/v2/form-submissions")
24
- end
25
-
26
- protected
27
-
28
- def rails_version
29
- @rails_version ||= Rails.version
30
- end
31
-
32
- def untracked?(model)
33
- !models.detect { |container| container.model == model }
34
- end
35
- end
36
- end
@@ -1,19 +0,0 @@
1
- module InformantRails
2
- class FieldError
3
- attr_accessor :name, :value, :message
4
-
5
- def initialize(name, value, message=nil)
6
- self.name = name
7
- self.value = value
8
- self.message = message
9
- end
10
-
11
- def value=(value)
12
- @value = InformantRails::ParameterFilter.filter(name, value)
13
- end
14
-
15
- def as_json(*args)
16
- { name: name, value: value, message: message }
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- module InformantRails
2
- class Model < Struct.new(:model)
3
- def name
4
- model.class.name
5
- end
6
-
7
- def errors
8
- model.errors.map do |field, error|
9
- InformantRails::FieldError.new(field.to_s, model[field], error)
10
- end
11
- end
12
-
13
- def as_json(*args)
14
- { name: name, errors: errors.map(&:as_json) }
15
- end
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- module InformantRails
2
- class ParameterFilter
3
- def self.filter(name, value)
4
- Config.value_tracking && !matcher.match(name) ? value : '[FILTERED]'
5
- end
6
-
7
- protected
8
-
9
- def self.matcher
10
- @matcher ||= Regexp.new(/#{Config.filter_parameters.join('|').presence || '$^'}/)
11
- end
12
- end
13
- end