currentsh 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
+ SHA1:
3
+ metadata.gz: ddb730caa780b9939af76f1520742d46fa0f1cf8
4
+ data.tar.gz: 19ae5ba9eda7dd1f34331ed8aae20547527d90f0
5
+ SHA512:
6
+ metadata.gz: 1e36ba7ff55c6c950a5056ed93529c9a3eef97e0f10d74e8af602d752e810667a9c6cd083c329b6b004bf85dc133e4c01e7ac2665560107f7e42b76ac6789b55
7
+ data.tar.gz: 630e2e19818a1a0549f3dbe64f1768bd1f904b414b604f0ac56ce1abed0b3870d67215b539d9c7aff6fc578b999cc5d9a1003781ae33ae66a3ef31abdd30abac
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in currentsh.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Currentsh
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/currentsh`. 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
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'currentsh'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install currentsh
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/currentsh.
36
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "currentsh"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/currentsh.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'currentsh/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "currentsh"
8
+ spec.version = Currentsh::VERSION
9
+ spec.authors = ["Evan Phoenix"]
10
+ spec.email = ["evan@current.sh"]
11
+
12
+ spec.summary = %q{Integration with current.sh}
13
+ spec.description = %q{Use this gem to send logs to current.sh}
14
+ spec.homepage = "http://github.com/vektra/currentsh"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
data/lib/currentsh.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "currentsh/version"
2
+ require 'currentsh/process'
3
+ require 'currentsh/rails'
4
+
5
+ module Currentsh
6
+ PROCESS = Process.new
7
+
8
+ def self.track_rails!
9
+ PROCESS.track_rails!
10
+ end
11
+ end
12
+
13
+ require 'currentsh/railtie' if defined?(Rails)
@@ -0,0 +1,11 @@
1
+ module Currentsh
2
+ class LogOutput
3
+ def initialize(io=$stdout)
4
+ @io = io
5
+ end
6
+
7
+ def <<(data)
8
+ @io.puts "@current: #{data.to_json}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'currentsh/log_output'
2
+
3
+ module Currentsh
4
+ class Process
5
+ def initialize
6
+ @output = LogOutput.new
7
+ @trackers = []
8
+ end
9
+
10
+ def track_rails!(app)
11
+ @output << { :type => "boot", :application => app.class.name }
12
+ rails = RailsTracker.new(@output)
13
+ rails.register
14
+
15
+ @trackers << rails
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,64 @@
1
+ module Currentsh
2
+ class RailsTracker
3
+ def initialize(output)
4
+ @output = output
5
+ end
6
+
7
+ def register
8
+ ActiveSupport::Notifications.subscribe "sql.active_record" do |*args|
9
+ event = ActiveSupport::Notifications::Event.new *args
10
+ sql(event)
11
+ end
12
+
13
+ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
14
+ event = ActiveSupport::Notifications::Event.new *args
15
+ action(event)
16
+ end
17
+
18
+ ActiveSupport::Notifications.subscribe "request.action_dispatch" do |*args|
19
+ event = ActiveSupport::Notifications::Event.new *args
20
+ request(event)
21
+ end
22
+ end
23
+
24
+ def action(event)
25
+ data = {
26
+ :type => "action",
27
+ :transaction => event.transaction_id,
28
+ }.merge(event.payload)
29
+
30
+ @output << data
31
+ end
32
+
33
+ def request(event)
34
+ request = event.payload[:request]
35
+
36
+ data = {
37
+ :type => "request",
38
+ :transaction => event.transaction_id,
39
+ :method => request.method,
40
+ :path => request.path,
41
+ :elapse => event.end - event.time
42
+ }
43
+
44
+ @output << data
45
+ end
46
+
47
+ def sql(event)
48
+ binds = event.payload[:binds].map do |(attribute,value)|
49
+ { :name => attribute.name, :type => attribute.type, :value => value }
50
+ end
51
+
52
+
53
+ data = {
54
+ :type => "sql",
55
+ :name => event.payload[:name],
56
+ :transaction => event.transaction_id,
57
+ :query => event.payload[:sql].strip,
58
+ :binds => binds,
59
+ }
60
+
61
+ @output << data
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/railtie'
2
+
3
+ module Currentsh
4
+ class Railtie < Rails::Railtie
5
+ config.currentsh = ActiveSupport::OrderedOptions.new
6
+ config.currentsh.enabled = false
7
+
8
+ config.after_initialize do |app|
9
+ Currentsh::PROCESS.track_rails!(app) if app.config.currentsh.enabled
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,3 @@
1
+ module Currentsh
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: currentsh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Evan Phoenix
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Use this gem to send logs to current.sh
42
+ email:
43
+ - evan@current.sh
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - currentsh.gemspec
55
+ - lib/currentsh.rb
56
+ - lib/currentsh/log_output.rb
57
+ - lib/currentsh/process.rb
58
+ - lib/currentsh/rails.rb
59
+ - lib/currentsh/railtie.rb
60
+ - lib/currentsh/version.rb
61
+ homepage: http://github.com/vektra/currentsh
62
+ licenses: []
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.5
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Integration with current.sh
84
+ test_files: []