sloc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/sloc +9 -0
- data/lib/sloc.rb +5 -0
- data/lib/sloc/analyzer.rb +19 -0
- data/lib/sloc/cli.rb +34 -0
- data/lib/sloc/runner.rb +42 -0
- data/lib/sloc/version.rb +3 -0
- data/sloc.gemspec +27 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b46653f18fd1c3a549b1a044ab715b906dbbd7c3
|
4
|
+
data.tar.gz: 2a7de9e2d0b267a0236adb70af09c0ea65cae417
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ebe9dbcd0bce080ce86ac42be5a9f51ac33aab53fa0ead3ad510f5ebd6668c05a6069ef471f1f45d2ba9138447ccd1fce6bb0b4ecdc6b94e56126e68d68da81
|
7
|
+
data.tar.gz: faea9c4ae2e41215832d0ecacb22d0493f208e9b8b2a53b513b3dc3b30d1b2452999aa99fb61b1e838fe73663874e2abd4e8debf792f41d7e4bfc57d9e809bec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 meganemura
|
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
|
+
# Sloc
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
`sloc <target(s)>` to display SLOC (source lines of code)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sloc'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sloc
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/meganemura/sloc/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
36
|
+
|
37
|
+
## Credits
|
38
|
+
|
39
|
+
This library was heavily inspired by [flosse/sloc](https://github.com/flosse/sloc).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sloc"
|
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
data/exe/sloc
ADDED
data/lib/sloc.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sloc
|
2
|
+
class Analyzer
|
3
|
+
def initialize(options)
|
4
|
+
@options = options
|
5
|
+
end
|
6
|
+
|
7
|
+
def analyze(code, extension)
|
8
|
+
result = {}
|
9
|
+
|
10
|
+
code.gsub!(/\r\n|\r/, "\n")
|
11
|
+
|
12
|
+
result[:total] = code.scan("\n").size
|
13
|
+
result[:empty_lines] = code.scan(/^\s*$/).size
|
14
|
+
result[:comments] = 'N/A' # FIXME
|
15
|
+
|
16
|
+
result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/sloc/cli.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'slop'
|
2
|
+
require 'sloc/runner'
|
3
|
+
|
4
|
+
module Sloc
|
5
|
+
class CLI
|
6
|
+
def initialize
|
7
|
+
@options = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(args = ARGV)
|
11
|
+
@options, paths = parse_options(args)
|
12
|
+
|
13
|
+
if paths.empty?
|
14
|
+
return help
|
15
|
+
end
|
16
|
+
|
17
|
+
runner = Runner.new(@options)
|
18
|
+
|
19
|
+
runner.run(paths)
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_options(args)
|
23
|
+
opts = Slop.parse! do |o|
|
24
|
+
o.on('-h', '--help', 'Display this help message.')
|
25
|
+
end
|
26
|
+
|
27
|
+
[opts, args]
|
28
|
+
end
|
29
|
+
|
30
|
+
def help
|
31
|
+
puts @options
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/sloc/runner.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'sloc/analyzer'
|
2
|
+
|
3
|
+
module Sloc
|
4
|
+
class Runner
|
5
|
+
def initialize(options)
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(paths)
|
10
|
+
target_files = find_target_files(paths)
|
11
|
+
|
12
|
+
# TODO: count sloc
|
13
|
+
analyzer = Analyzer.new(@options)
|
14
|
+
report = target_files.each_with_object({}) do |path, h|
|
15
|
+
code = File.read(path)
|
16
|
+
extension = File.extname(path)
|
17
|
+
|
18
|
+
h[path] = analyzer.analyze(code, extension)
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: formatted output
|
22
|
+
require 'pp'
|
23
|
+
pp report
|
24
|
+
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def find_target_files(paths)
|
31
|
+
files = paths.uniq.flat_map do |path|
|
32
|
+
if File.directory?(path)
|
33
|
+
Dir.glob("#{path}/**/*").select {|f| File.file?(f) }
|
34
|
+
else
|
35
|
+
path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
files.map {|f| File.expand_path(f) }.uniq
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/sloc/version.rb
ADDED
data/sloc.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sloc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sloc"
|
8
|
+
spec.version = Sloc::VERSION
|
9
|
+
spec.authors = ["meganemura"]
|
10
|
+
spec.email = ["meganemura@users.noreply.github.com"]
|
11
|
+
|
12
|
+
spec.summary = "A tool for counting source lines of code"
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/meganemura/sloc"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "slop", "~> 3.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sloc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- meganemura
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: A tool for counting source lines of code
|
70
|
+
email:
|
71
|
+
- meganemura@users.noreply.github.com
|
72
|
+
executables:
|
73
|
+
- sloc
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- exe/sloc
|
87
|
+
- lib/sloc.rb
|
88
|
+
- lib/sloc/analyzer.rb
|
89
|
+
- lib/sloc/cli.rb
|
90
|
+
- lib/sloc/runner.rb
|
91
|
+
- lib/sloc/version.rb
|
92
|
+
- sloc.gemspec
|
93
|
+
homepage: https://github.com/meganemura/sloc
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.2.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: A tool for counting source lines of code
|
117
|
+
test_files: []
|