colrou 0.1.1

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: e4c7367465b841f2060d90d41d9c8493c68ee82b95ffdcb4b67292e0323d7efc
4
+ data.tar.gz: 7f78fe6baa21b74f75560c4e914cf809725f21c84a956e44267037dab21fa5e6
5
+ SHA512:
6
+ metadata.gz: 694ed42e1c1c0718192bc36ca74babbb00aac6b272cbd4b555bf16332baba1f2489d15f3eda65b38a3b9c4a4eddb971bffde2a0367ee4057599d33f0de6d9cec
7
+ data.tar.gz: 8bf01225cb8d917d024f5551e0fb3baaeab5628148535eac0bacc2f75d20ea14c832d3dcd36ca23ef869ea6658e44cd1dd2020178a0c4e86ee446982748c85d9
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in colrou.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ colrou (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 2.0)
16
+ colrou!
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Erik van Eykelen
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,39 @@
1
+ # Colrou
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/colrou`. 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 'colrou'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install colrou
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. Then, run `rake test` to run the tests. 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]/colrou.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "colrou"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/colrou.gemspec ADDED
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "colrou/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "colrou"
8
+ spec.version = Colrou::VERSION
9
+ spec.authors = ["Erik van Eykelen"]
10
+ spec.email = ["erik.van.eykelen@bitgain.com"]
11
+
12
+ spec.summary = %q{Colorize `rails routes` output and insert line breaks between controllers}
13
+ spec.homepage = "https://github.com/evaneykelen/colrou"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/evaneykelen/colrou"
22
+ spec.metadata["changelog_uri"] = "https://github.com/evaneykelen/colrou/CHANGELOG.md"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 2.0"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ end
data/exe/colrou ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'colrou/parse'
3
+ Colrou::Parse::rails_routes
@@ -0,0 +1,84 @@
1
+ module Colrou
2
+ class Parse
3
+ def self.rails_routes
4
+ if ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?)
5
+ RailsRoutesParser.parse
6
+ else
7
+ puts %{
8
+ Reformats output of `rails routes`:
9
+ - HTTP verbs and path parameters are colorized
10
+ - Line breaks are inserted between controllers
11
+
12
+ Usage examples:
13
+
14
+ $ rails routes | colrou
15
+ $ rails routes -g posts | colrou
16
+
17
+ }
18
+ end
19
+ end
20
+ end
21
+
22
+ class RailsRoutesParser
23
+ RED = "\e[91m"
24
+ GREEN = "\e[92m"
25
+ YELLOW = "\e[93m"
26
+ PURPLE = "\e[95m"
27
+ CYAN = "\e[96m"
28
+ RESET_COLOR = "\e[0m"
29
+
30
+ VERBS_AND_COLORS = [
31
+ { verb: "DELETE", color: RED },
32
+ { verb: "GET", color: GREEN },
33
+ { verb: "PATCH", color: PURPLE },
34
+ { verb: "POST", color: YELLOW },
35
+ { verb: "PUT", color: PURPLE }
36
+ ]
37
+
38
+ def self.colorize_verbs(line)
39
+ VERBS_AND_COLORS.each do |verb_and_color|
40
+ verb = verb_and_color[:verb]
41
+ color = verb_and_color[:color]
42
+ line.gsub!(/#{verb}/, "#{color}#{verb}#{RESET_COLOR}")
43
+ end
44
+ end
45
+
46
+ # Uses https://ruby-doc.org/core-1.9.3/Regexp.html#class-Regexp-label-Capturing
47
+ def self.colorize_parameters(line)
48
+ line.gsub!(/(?<parameter>\/:\w+)/) do
49
+ "/#{CYAN}#{$~[:parameter].slice(1..-1)}#{RESET_COLOR}"
50
+ end
51
+ end
52
+
53
+ def self.extract_controller_name(line)
54
+ controller_action = line[/\w+#\w+$/] # Find "controller#action\n"
55
+ return if nil == controller_action
56
+ controller_action.split("#")[0] # Get "controller" from "controller#action"
57
+ end
58
+
59
+ def self.parse
60
+ prev_controller_name = nil
61
+ begin
62
+ while input = ARGF.gets
63
+ input.each_line do |line|
64
+ begin
65
+ # Apply colorizations
66
+ colorize_verbs(line)
67
+ colorize_parameters(line)
68
+ # Apply line breaks between controllers
69
+ controller_name = extract_controller_name(line)
70
+ $stdout.puts if controller_name != prev_controller_name && nil != prev_controller_name
71
+ prev_controller_name = controller_name
72
+ # Output formatted line
73
+ $stdout.puts(line)
74
+ rescue Errno::EPIPE
75
+ exit(74) # Bash exit status code (input/output error)
76
+ end
77
+ end
78
+ end
79
+ rescue
80
+ puts "Invalid input"
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module Colrou
2
+ VERSION = "0.1.1"
3
+ end
data/lib/colrou.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'colrou/parse'
2
+ require "colrou/version"
3
+
4
+ module Colrou
5
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colrou
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Erik van Eykelen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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:
42
+ email:
43
+ - erik.van.eykelen@bitgain.com
44
+ executables:
45
+ - colrou
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - colrou.gemspec
59
+ - exe/colrou
60
+ - lib/colrou.rb
61
+ - lib/colrou/parse.rb
62
+ - lib/colrou/version.rb
63
+ homepage: https://github.com/evaneykelen/colrou
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://github.com/evaneykelen/colrou
68
+ source_code_uri: https://github.com/evaneykelen/colrou
69
+ changelog_uri: https://github.com/evaneykelen/colrou/CHANGELOG.md
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.0.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Colorize `rails routes` output and insert line breaks between controllers
89
+ test_files: []