filetype 0.1.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +8 -0
- data/lib/filetype.rb +31 -8
- data/test/filetype_test.rb +97 -3
- data/test/test_helper.rb +2 -2
- metadata +22 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4727e0c57dc75e0f130816a7ad47fa057d49dd72d3eb9309bdb14f497e668e6e
|
4
|
+
data.tar.gz: 7ced5c77fabf3df3015385286e5b86aff8ef4172dc27ed2ea894d7040ef08d55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 282c798ef18f796e4e8cbb101b076c4de92e8fe5ef99f015ac96de1b7a0ef6f20d54401b1b9cfdd1b939d6615f58a36a4d18e34d789fa4f665986828d23fb3da
|
7
|
+
data.tar.gz: ab11c48de92bb964a443c057be81581a00cd602495c8a695e66c29ea67bc212c6b150c731a69bb7cfbbef91c6d8be16d60fb043896267788bf5af4301dd9abaa
|
data/README.md
CHANGED
@@ -30,6 +30,14 @@ You can of course add your own custom file types
|
|
30
30
|
Filetype.add(:cool, %w[ cool kl ])
|
31
31
|
Filetype.get('hello.kl') #=> :cool
|
32
32
|
|
33
|
+
Simple
|
34
|
+
------
|
35
|
+
|
36
|
+
You may notice how basic Filetype is, all it's doing is checking the file name
|
37
|
+
or file extension. Well, that's its intention, it was built for nothing more.
|
38
|
+
If you want more advanced information, check out the
|
39
|
+
[mime-types](http://mime-types.rubyforge.org/) library.
|
40
|
+
|
33
41
|
Contributing
|
34
42
|
------------
|
35
43
|
|
data/lib/filetype.rb
CHANGED
@@ -1,38 +1,52 @@
|
|
1
1
|
module Filetype
|
2
2
|
module_function
|
3
3
|
|
4
|
-
VERSION = '0.
|
4
|
+
VERSION = '0.3.2'
|
5
5
|
|
6
6
|
FTYPES = {
|
7
7
|
:actionscript => %w[ as mxml ],
|
8
8
|
:ada => %w[ ada adb ads ],
|
9
9
|
:asm => %w[ asm s ],
|
10
10
|
:batch => %w[ bat cmd ],
|
11
|
+
:bundler => /\A[Gg]emfile(?:\.lock)?\z/,
|
12
|
+
:bzip => %w[ bzip2 bzip ],
|
11
13
|
:c => %w[ c h ],
|
12
14
|
:clojure => %w[ clj ],
|
13
15
|
:cpp => %w[ cpp cc cxx m hpp hh h hxx ],
|
14
16
|
:csharp => %w[ cs ],
|
15
17
|
:css => %w[ css ],
|
18
|
+
:diff => %w[ diff patch ],
|
19
|
+
:docker => /\A[Dd]ockerfile(?:\.\w+)?\z/,
|
16
20
|
:elisp => %w[ el ],
|
21
|
+
:epub => %w[ epub ],
|
22
|
+
:erb => %w[ rhtml erb ],
|
17
23
|
:erlang => %w[ erl hrl ],
|
24
|
+
:exe => %w[ exe ],
|
25
|
+
:forth => %w[ 4th ],
|
26
|
+
:fsharp => %w[ fs ],
|
27
|
+
:gem => %w[ gem ],
|
18
28
|
:go => %w[ go ],
|
19
29
|
:groovy => %w[ groovy gpp grunit gtmpl ],
|
30
|
+
:gzip => %w[ gzip gz ],
|
20
31
|
:haskell => %w[ hs lhs ],
|
21
32
|
:haml => %w[ haml ],
|
22
33
|
:html => %w[ html xhtml shtml htm ],
|
23
|
-
:java => %w[ java ],
|
34
|
+
:java => %w[ java jar ],
|
24
35
|
:js => %w[ js ],
|
25
36
|
:lisp => %w[ lisp lsp ],
|
26
37
|
:lua => %w[ lua ],
|
27
38
|
:make => /\A[Mm]akefile\z/,
|
28
39
|
:objc => %w[ m h ],
|
29
40
|
:ocaml => %w[ ml mli ],
|
41
|
+
:pcap => %w[ pcap ],
|
30
42
|
:perl => %w[ pl pm t pod ],
|
43
|
+
:pgp => %w[ asc pgp gpg ],
|
31
44
|
:php => %w[ php phpt phtml ],
|
32
45
|
:python => %w[ py pyc ],
|
33
46
|
:rackup => %w[ ru ],
|
34
47
|
:rake => /\A[Rr]akefile(?:.rb)?\z/,
|
35
|
-
:
|
48
|
+
:rar => %w[ rar ],
|
49
|
+
:ruby => %w[ rb rake gemspec rjs ],
|
36
50
|
:sass => %w[ sass ],
|
37
51
|
:scala => %w[ scala ],
|
38
52
|
:scss => %w[ scss ],
|
@@ -40,8 +54,12 @@ module Filetype
|
|
40
54
|
:shell => %w[ sh bash ksh zsh csh ],
|
41
55
|
:smalltalk => %w[ st ],
|
42
56
|
:sql => %w[ sql ctl ],
|
57
|
+
:tar => %w[ tar ],
|
58
|
+
:text => %w[ txt ],
|
43
59
|
:yaml => %w[ yaml yml ],
|
44
|
-
:xml => %w[ xml
|
60
|
+
:xml => %w[ xml dtd ],
|
61
|
+
:xsl => %w[ xsl xslt],
|
62
|
+
:zip => %w[ zip ]
|
45
63
|
}
|
46
64
|
|
47
65
|
# Fetch a language for this filetype
|
@@ -55,8 +73,7 @@ module Filetype
|
|
55
73
|
FTYPES.each do |ftype, rule|
|
56
74
|
case rule
|
57
75
|
when Array
|
58
|
-
|
59
|
-
return ftype if rule.include? ext
|
76
|
+
return ftype if rule.include? ext(fname)
|
60
77
|
when Regexp
|
61
78
|
return ftype if fname.match rule
|
62
79
|
when String, Symbol
|
@@ -74,8 +91,7 @@ module Filetype
|
|
74
91
|
# @return [Array] The list of languages found
|
75
92
|
def all(fname)
|
76
93
|
FTYPES.select do |ftype, rule|
|
77
|
-
|
78
|
-
ftype if rule.is_a?(Array) && rule.include?(ext)
|
94
|
+
ftype if rule.is_a?(Array) && rule.include?(ext(fname))
|
79
95
|
end.keys
|
80
96
|
end
|
81
97
|
|
@@ -92,4 +108,11 @@ module Filetype
|
|
92
108
|
def add(ftype, rule)
|
93
109
|
FTYPES[ftype] = rule
|
94
110
|
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def self.ext(fname)
|
115
|
+
ext = File.extname(fname)[1..-1]
|
116
|
+
ext.downcase if ext
|
117
|
+
end
|
95
118
|
end
|
data/test/filetype_test.rb
CHANGED
@@ -2,9 +2,103 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class FileTypeTest < TestCase
|
4
4
|
|
5
|
-
test '
|
5
|
+
test 'testing all languages with all extensions' do
|
6
|
+
assert_equal :bundler, Filetype.get('Gemfile')
|
7
|
+
assert_equal :bundler, Filetype.get('gemfile') # ?
|
8
|
+
assert_equal :bundler, Filetype.get('Gemfile.lock') # ?
|
9
|
+
assert_equal :bundler, Filetype.get('gemfile.lock') # ?
|
10
|
+
assert_equal :make, Filetype.get('Makefile')
|
11
|
+
assert_equal :make, Filetype.get('makefile')
|
12
|
+
assert_equal :rake, Filetype.get('Rakefile')
|
13
|
+
assert_equal :rake, Filetype.get('rakefile')
|
14
|
+
assert_equal :rake, Filetype.get('Rakefile.rb')
|
15
|
+
|
16
|
+
assert_equal :actionscript, Filetype.get('foo.as')
|
17
|
+
assert_equal :actionscript, Filetype.get('foo.AS')
|
18
|
+
assert_equal :actionscript, Filetype.get('foo.mxml')
|
19
|
+
assert_equal :ada, Filetype.get('foo.ada')
|
20
|
+
assert_equal :ada, Filetype.get('foo.adb')
|
21
|
+
assert_equal :ada, Filetype.get('foo.ads')
|
22
|
+
assert_equal :asm, Filetype.get('foo.asm')
|
23
|
+
assert_equal :asm, Filetype.get('foo.s')
|
24
|
+
assert_equal :batch, Filetype.get('foo.bat')
|
25
|
+
assert_equal :batch, Filetype.get('foo.cmd')
|
26
|
+
assert_equal :c, Filetype.get('foo.c')
|
27
|
+
assert_equal :c, Filetype.get('foo.h')
|
28
|
+
assert_equal :clojure, Filetype.get('foo.clj')
|
29
|
+
assert_equal :cpp, Filetype.get('foo.cpp')
|
30
|
+
assert_equal :cpp, Filetype.get('foo.cc')
|
31
|
+
assert_equal :cpp, Filetype.get('foo.cxx')
|
32
|
+
assert_equal :cpp, Filetype.get('foo.m')
|
33
|
+
assert_equal :cpp, Filetype.get('foo.hpp')
|
34
|
+
assert_equal :cpp, Filetype.get('foo.hh')
|
35
|
+
# assert_equal :cpp, Filetype.get('foo.h') # DUPLICATE
|
36
|
+
assert_equal :cpp, Filetype.get('foo.hxx')
|
37
|
+
assert_equal :csharp, Filetype.get('foo.cs')
|
38
|
+
assert_equal :css, Filetype.get('foo.css')
|
39
|
+
assert_equal :docker, Filetype.get('Dockerfile')
|
40
|
+
assert_equal :docker, Filetype.get('Dockerfile.build')
|
41
|
+
assert_equal :elisp, Filetype.get('foo.el')
|
42
|
+
assert_equal :epub, Filetype.get('foo.epub')
|
43
|
+
assert_equal :erb, Filetype.get('foo.rhtml')
|
44
|
+
assert_equal :erb, Filetype.get('foo.erb')
|
45
|
+
assert_equal :erlang, Filetype.get('foo.erl')
|
46
|
+
assert_equal :erlang, Filetype.get('foo.hrl')
|
47
|
+
assert_equal :go, Filetype.get('foo.go')
|
48
|
+
assert_equal :groovy, Filetype.get('foo.groovy')
|
49
|
+
assert_equal :groovy, Filetype.get('foo.gpp')
|
50
|
+
assert_equal :groovy, Filetype.get('foo.grunit')
|
51
|
+
assert_equal :groovy, Filetype.get('foo.gtmpl')
|
52
|
+
assert_equal :haskell, Filetype.get('foo.hs')
|
53
|
+
assert_equal :haskell, Filetype.get('foo.lhs')
|
54
|
+
assert_equal :haml, Filetype.get('foo.haml')
|
55
|
+
assert_equal :html, Filetype.get('foo.html')
|
56
|
+
assert_equal :html, Filetype.get('foo.xhtml')
|
57
|
+
assert_equal :html, Filetype.get('foo.shtml')
|
58
|
+
assert_equal :html, Filetype.get('foo.htm')
|
59
|
+
assert_equal :java, Filetype.get('foo.java')
|
60
|
+
assert_equal :java, Filetype.get('foo.jar')
|
61
|
+
assert_equal :js, Filetype.get('foo.js')
|
62
|
+
assert_equal :lisp, Filetype.get('foo.lisp')
|
63
|
+
assert_equal :lisp, Filetype.get('foo.lsp')
|
64
|
+
assert_equal :lua, Filetype.get('foo.lua')
|
65
|
+
# assert_equal :objc, Filetype.get('foo.m') # DUPLICATE
|
66
|
+
# assert_equal :objc, Filetype.get('foo.h') # DUPLICATE
|
67
|
+
assert_equal :ocaml, Filetype.get('foo.ml')
|
68
|
+
assert_equal :ocaml, Filetype.get('foo.mli')
|
69
|
+
assert_equal :perl, Filetype.get('foo.pl')
|
70
|
+
assert_equal :perl, Filetype.get('foo.pm')
|
71
|
+
assert_equal :perl, Filetype.get('foo.t')
|
72
|
+
assert_equal :perl, Filetype.get('foo.pod')
|
73
|
+
assert_equal :php, Filetype.get('foo.php')
|
74
|
+
assert_equal :php, Filetype.get('foo.phpt')
|
75
|
+
assert_equal :php, Filetype.get('foo.phtml')
|
76
|
+
assert_equal :python, Filetype.get('foo.py')
|
77
|
+
assert_equal :python, Filetype.get('foo.pyc')
|
78
|
+
assert_equal :rackup, Filetype.get('foo.ru')
|
6
79
|
assert_equal :ruby, Filetype.get('foo.rb')
|
7
|
-
|
80
|
+
assert_equal :ruby, Filetype.get('foo.rake')
|
81
|
+
assert_equal :ruby, Filetype.get('foo.rjs')
|
82
|
+
assert_equal :sass, Filetype.get('foo.sass')
|
83
|
+
assert_equal :scala, Filetype.get('foo.scala')
|
84
|
+
assert_equal :scss, Filetype.get('foo.scss')
|
85
|
+
assert_equal :scheme, Filetype.get('foo.scm')
|
86
|
+
assert_equal :scheme, Filetype.get('foo.ss')
|
87
|
+
assert_equal :shell, Filetype.get('foo.sh')
|
88
|
+
assert_equal :shell, Filetype.get('foo.bash')
|
89
|
+
assert_equal :shell, Filetype.get('foo.ksh')
|
90
|
+
assert_equal :shell, Filetype.get('foo.zsh')
|
91
|
+
assert_equal :shell, Filetype.get('foo.csh')
|
92
|
+
assert_equal :smalltalk, Filetype.get('foo.st')
|
93
|
+
assert_equal :sql, Filetype.get('foo.sql')
|
94
|
+
assert_equal :sql, Filetype.get('foo.ctl')
|
95
|
+
assert_equal :text, Filetype.get('foo.txt')
|
96
|
+
assert_equal :yaml, Filetype.get('foo.yaml')
|
97
|
+
assert_equal :yaml, Filetype.get('foo.yml')
|
98
|
+
assert_equal :xml, Filetype.get('foo.xml')
|
99
|
+
assert_equal :xml, Filetype.get('foo.dtd')
|
100
|
+
assert_equal :xsl, Filetype.get('foo.xslt')
|
101
|
+
assert_equal :xsl, Filetype.get('foo.xsl')
|
8
102
|
end
|
9
103
|
|
10
104
|
test 'fetching multiple languages of a file name' do
|
@@ -17,4 +111,4 @@ class FileTypeTest < TestCase
|
|
17
111
|
assert_equal :bar, Filetype.get('hello.foo')
|
18
112
|
end
|
19
113
|
|
20
|
-
end
|
114
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class TestCase <
|
1
|
+
class TestCase < Minitest::Test
|
2
2
|
def self.test(name, &block)
|
3
3
|
test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym
|
4
4
|
defined = instance_method(test_name) rescue false
|
@@ -11,4 +11,4 @@ class TestCase < MiniTest::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,31 +1,24 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: filetype
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Lee Jarvis
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-04-26 00:00:00 +01:00
|
14
|
-
default_executable:
|
11
|
+
date: 2021-10-12 00:00:00.000000000 Z
|
15
12
|
dependencies: []
|
16
|
-
|
17
13
|
description: Find a file type according to a filename or extension
|
18
|
-
email:
|
14
|
+
email:
|
19
15
|
- lee@jarvis.co
|
20
16
|
executables: []
|
21
|
-
|
22
17
|
extensions: []
|
23
|
-
|
24
18
|
extra_rdoc_files: []
|
25
|
-
|
26
|
-
|
27
|
-
- .
|
28
|
-
- .gitignore
|
19
|
+
files:
|
20
|
+
- ".gemtest"
|
21
|
+
- ".gitignore"
|
29
22
|
- LICENSE
|
30
23
|
- README.md
|
31
24
|
- Rakefile
|
@@ -33,34 +26,26 @@ files:
|
|
33
26
|
- lib/filetype.rb
|
34
27
|
- test/filetype_test.rb
|
35
28
|
- test/test_helper.rb
|
36
|
-
has_rdoc: true
|
37
29
|
homepage: http://github.com/injekt/filetype
|
38
30
|
licenses: []
|
39
|
-
|
31
|
+
metadata: {}
|
40
32
|
post_install_message:
|
41
33
|
rdoc_options: []
|
42
|
-
|
43
|
-
require_paths:
|
34
|
+
require_paths:
|
44
35
|
- lib
|
45
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
-
|
47
|
-
requirements:
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
48
38
|
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version:
|
51
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
-
|
53
|
-
requirements:
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
54
43
|
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
57
46
|
requirements: []
|
58
|
-
|
59
|
-
rubyforge_project:
|
60
|
-
rubygems_version: 1.6.2
|
47
|
+
rubygems_version: 3.2.9
|
61
48
|
signing_key:
|
62
|
-
specification_version:
|
49
|
+
specification_version: 4
|
63
50
|
summary: Find a files type
|
64
|
-
test_files:
|
65
|
-
- test/filetype_test.rb
|
66
|
-
- test/test_helper.rb
|
51
|
+
test_files: []
|