railsochrome 0.1.0

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: be9b603631b9e43d8e832e7e8b3d8104b54a22f2bb55b124a906001e6e9043b3
4
+ data.tar.gz: cb481cfaebf213a5b7b6876345601437569891acbd470de4e9466e05bdbc059b
5
+ SHA512:
6
+ metadata.gz: ff0ff94db66c87bf7a2fdb2ab9ec65297c09e4be92777ae562491017818bfcfa5a6f490bf84e4cd28d71932bbf1ea2777405bf3da74b55867977b2f8af2e3be2
7
+ data.tar.gz: b88d42a5583a940e974b0970d1c02e2cbd7fce852d7b68f4508b62ef622e35fc87cc62d8dad624ef9b49e3d4c7fa5179efb53a791314de83cc3070901ade60d4
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Railsochrome
2
+
3
+ [![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)
4
+ [![Listed on OpenSource-Heroes.com](https://opensource-heroes.com/badge-v1.svg)](https://opensource-heroes.com/o/railsjazz)
5
+
6
+ Project created just for fun and because of curiosity.
7
+
8
+ The idea of this project is to print log messages from Rails app in Chrome console. It will work even if you have a simple JSON API call.
9
+
10
+ What is funny it can print log messages from the models. Just call a class method `Railsochrome.log`.
11
+
12
+ How it works see on the diagram below:
13
+
14
+ ## Usage
15
+
16
+ 1. Close the repo
17
+
18
+ 2. Install chrome extension from the source code.
19
+
20
+ 3. Add gem and use in your code:
21
+
22
+ ```ruby
23
+ # controller
24
+ def index
25
+ Railsochrome.log("Opening index action")
26
+ Railsochrome.log("user_id = #{rand(111)}")
27
+ Railsochrome.log("account_id = #{rand(111)}")
28
+
29
+ @projects = Project.all
30
+ end
31
+
32
+ # model
33
+ class Project < ApplicationRecord
34
+ after_initialize do
35
+ Railsochrome.log("after_initialize project id=#{self.id}")
36
+ end
37
+ end
38
+ ```
39
+
40
+ ## Installation
41
+
42
+ ```ruby
43
+ gem "railsochrome"
44
+ ```
45
+
46
+ And then execute:
47
+ ```bash
48
+ $ bundle
49
+ ```
50
+
51
+ Or install it yourself as:
52
+ ```bash
53
+ $ gem install railsochrome
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ Contribution directions go here.
59
+
60
+ ## License
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.or
62
+ g/licenses/MIT).
63
+
64
+
65
+ [<img src="https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/more_gems.png?raw=true"
66
+ />](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=peity_vanilla)
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ module Railsochrome
2
+ class Collector < ActiveSupport::CurrentAttributes
3
+ attribute :messages
4
+
5
+ def add(message)
6
+ self.messages ||= []
7
+ self.messages.push(message)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module Railsochrome
2
+ class Railtie < ::Rails::Engine
3
+
4
+ if Railsochrome.enabled
5
+ initializer "railsochrome.middleware" do |app|
6
+ if ::Rails::VERSION::MAJOR.to_i >= 5
7
+ app.middleware.insert_after ActionDispatch::Executor, Railsochrome::Middleware
8
+ else
9
+ begin
10
+ app.middleware.insert_after ActionDispatch::Static, Railsochrome::Middleware
11
+ rescue
12
+ app.middleware.insert_after Rack::SendFile, RailsLiveReload::Middleware
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Railsochrome
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ dup.call!(env)
9
+ end
10
+
11
+ def call!(env)
12
+ status, headers, response = @app.call(env)
13
+
14
+ if Railsochrome.enabled
15
+ headers["railsochrome"] = "Hi there :)"
16
+ Array.wrap(Railsochrome::Collector.messages).each_with_index do |e, i|
17
+ headers["railsochrome_msg_#{i}"] = e
18
+ end
19
+ end
20
+
21
+ [status, headers, response]
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Railsochrome
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ require "railsochrome/version"
2
+
3
+ module Railsochrome
4
+ mattr_accessor :enabled
5
+ @@enabled = true
6
+
7
+ autoload :Collector, "railsochrome/collector"
8
+ autoload :Middleware, "railsochrome/middleware"
9
+
10
+ def Railsochrome.log(message)
11
+ Railsochrome::Collector.add(message)
12
+ end
13
+ end
14
+
15
+ require "railsochrome/engine"
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :railsochrome do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railsochrome
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ''
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: puma
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Get better visibility of what happen on your server with logs directly
56
+ in Chrome
57
+ email:
58
+ - igorkasyanchuk@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/railsochrome.rb
67
+ - lib/railsochrome/collector.rb
68
+ - lib/railsochrome/engine.rb
69
+ - lib/railsochrome/middleware.rb
70
+ - lib/railsochrome/version.rb
71
+ - lib/tasks/railsochrome_tasks.rake
72
+ homepage: https://www.railsjazz.com
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ homepage_uri: https://www.railsjazz.com
77
+ source_code_uri: https://github.com/railsjazz/railsochrome
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.3.7
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Get better visibility of what happen on your server with logs directly in
97
+ Chrome
98
+ test_files: []