ruumba 0.0.1
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 +7 -0
- data/README.md +47 -0
- data/Rakefile +37 -0
- data/bin/ruumba +22 -0
- data/lib/ruumba.rb +3 -0
- data/lib/ruumba/analyzer.rb +38 -0
- data/lib/ruumba/rake_task.rb +42 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c8728a15051d8b738eefad002020f1d547e1f16
|
4
|
+
data.tar.gz: b8d749c81d4719fc52f68a23d6243ac022ac7625
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccc655259643fda1b72c3ea786088641be4da80fc240a92ce2a5495cd9839a7c8156277a517c374fb850027536d297ad4c2ab5c3ecf6b328d438fd0246db78ac
|
7
|
+
data.tar.gz: 2672a943fb32fc126d459eb5c47d6355fa6d5b612c5befefa325c02beff3af90997e9b5d39d276c43a5cd04d770e3ede0a3df38f3ba900d36b26b05351e0a845
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
Ruumba
|
2
|
+
======
|
3
|
+
> .erb or .rb, you're coming with me.
|
4
|
+
|
5
|
+
> — RuboCop
|
6
|
+
|
7
|
+
## About
|
8
|
+
Ruumba is [RuboCop's](https://github.com/bbatsov/rubocop) sidekick, allowing you to lint your .erb Rubies as well as your regular-type ones.
|
9
|
+
|
10
|
+
## Dependencies
|
11
|
+
* Ruby 2.2.2+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
```bash
|
15
|
+
λ gem install ruumba
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
Command line:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
λ ruumba directory_of_erb_files/
|
23
|
+
```
|
24
|
+
|
25
|
+
Rake task:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'ruumba/rake_task'
|
29
|
+
|
30
|
+
Ruumba::RakeTask.new(:ruumba) do |t|
|
31
|
+
t.dir = %w(lib/views)
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Then:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
λ bundle exec rake ruumba
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
1. Branch (`git checkout -b fancy-new-feature`)
|
43
|
+
2. Commit (`git commit -m "Fanciness!"`)
|
44
|
+
3. Test (`bundle exec rake spec`)
|
45
|
+
4. Lint (`bundle exec rake rubocop`)
|
46
|
+
5. Push (`git push origin fancy-new-feature`)
|
47
|
+
6. Ye Olde Pulle Requeste
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
require 'yard'
|
6
|
+
|
7
|
+
task default: 'test:all'
|
8
|
+
|
9
|
+
desc 'Run IRB with the gem environment loaded'
|
10
|
+
task :console do
|
11
|
+
puts '[+] Loading development console...'
|
12
|
+
system('irb -r ./lib/ruumba.rb')
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run tests'
|
16
|
+
task :spec do
|
17
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
18
|
+
t.pattern = './spec/**/*_spec.rb'
|
19
|
+
t.rspec_opts = ['--color --format d']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Lint'
|
24
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
25
|
+
t.patterns = %w(lib/**/*.rb spec/**/*.rb)
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Run all the tests, lint all the things'
|
29
|
+
namespace :test do
|
30
|
+
task all: %i(spec rubocop)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Generate Ruby documentation'
|
34
|
+
YARD::Rake::YardocTask.new do |t|
|
35
|
+
t.files = %w(lib/**/*.rb)
|
36
|
+
t.options = %w(--protected --private)
|
37
|
+
end
|
data/bin/ruumba
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# @author Eric Weinstein <eric.q.weinstein@gmail.com>
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require_relative '../lib/ruumba'
|
6
|
+
|
7
|
+
opt_parser = OptionParser.new do |opts|
|
8
|
+
opts.banner = 'Usage: ruumba path/to/ERBs/'
|
9
|
+
|
10
|
+
opts.on('-h', '--help', 'Display this screen') do
|
11
|
+
puts opts_parser
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
begin opt_parser.parse!
|
17
|
+
rescue OptionParser::InvalidOption => e
|
18
|
+
abort "An error occurred: #{e}. Run ruumba -h for help."
|
19
|
+
end
|
20
|
+
|
21
|
+
analyzer = Ruumba::Analyzer.new
|
22
|
+
analyzer.run
|
data/lib/ruumba.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# @author Eric Weinstein <eric.q.weinstein@gmail.com>
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
# Ruumba: RuboCop's sidekick.
|
6
|
+
module Ruumba
|
7
|
+
# Generates analyzer objects that, when run, delegate
|
8
|
+
# to RuboCop for linting (style, correctness, &c).
|
9
|
+
class Analyzer
|
10
|
+
# The regular expression to capture interpolated Ruby.
|
11
|
+
ERB_REGEX = /<%=?(.*?)%>/
|
12
|
+
|
13
|
+
# Performs static analysis on the provided directory.
|
14
|
+
# @param [Array<String>] dir The directory to analyze.
|
15
|
+
def run(dir = ARGV)
|
16
|
+
fq_dir = File.expand_path dir.first
|
17
|
+
suffix = SecureRandom.hex
|
18
|
+
|
19
|
+
Dir["#{fq_dir}/**/*.erb"].each do |f|
|
20
|
+
File.open("#{f}-#{suffix}.rb", 'w+') do |file|
|
21
|
+
code = extract f
|
22
|
+
file.write code
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
system("rubocop #{fq_dir}")
|
27
|
+
|
28
|
+
Dir.glob(Dir["#{fq_dir}/**/*-#{suffix}.rb"]).each { |f| File.delete(f) }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Extracts Ruby code from an ERB template.
|
32
|
+
# @param [String] filename The filename.
|
33
|
+
# @return [String] The extracted Ruby code.
|
34
|
+
def extract(filename)
|
35
|
+
File.read(filename).scan(ERB_REGEX).map(&:last).map(&:strip).join("\n")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# @author Eric Weinstein <eric.q.weinstein@gmail.com>
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/tasklib'
|
5
|
+
|
6
|
+
module Ruumba
|
7
|
+
# Provides a custom Rake task.
|
8
|
+
class RakeTask < Rake::TaskLib
|
9
|
+
attr_accessor :name, :dir
|
10
|
+
|
11
|
+
# Sets up the custom Rake task.
|
12
|
+
# @param [Array<String>] args Arguments to the Rake task.
|
13
|
+
# @yield If called with a block, we'll call it to ensure
|
14
|
+
# additional options are included (_e.g._ dir).
|
15
|
+
def initialize(*args, &block)
|
16
|
+
@name = args.shift || :ruumba
|
17
|
+
@dir = []
|
18
|
+
|
19
|
+
desc 'Run RuboCop on ERB files' unless ::Rake.application.last_comment
|
20
|
+
|
21
|
+
task(name, *args) do |_, task_args|
|
22
|
+
block.call(*[self, task_args].slice(0, block.arity)) if block
|
23
|
+
run
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Executes the custom Rake task.
|
30
|
+
# @private
|
31
|
+
def run
|
32
|
+
# Like RuboCop itself, we'll lazy load so the task
|
33
|
+
# doesn't substantially impact Rakefile load time.
|
34
|
+
require 'ruumba'
|
35
|
+
|
36
|
+
analyzer = Ruumba::Analyzer.new
|
37
|
+
puts 'Running Ruumba...'
|
38
|
+
|
39
|
+
analyzer.run @dir
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruumba
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Weinstein
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.28.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.28.0
|
27
|
+
description: RuboCop linting for ERB templates.
|
28
|
+
email: eric.q.weinstein@gmail.com
|
29
|
+
executables:
|
30
|
+
- ruumba
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- bin/ruumba
|
37
|
+
- lib/ruumba.rb
|
38
|
+
- lib/ruumba/analyzer.rb
|
39
|
+
- lib/ruumba/rake_task.rb
|
40
|
+
homepage: https://github.com/ericqweinstein/ruumba
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.4.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Allows users to lint Ruby code in ERB templates the same way they lint source
|
64
|
+
code (using RuboCop).
|
65
|
+
test_files: []
|
66
|
+
has_rdoc:
|