filetype 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/filetype.rb +7 -1
- data/test/filetype_test.rb +9 -1
- data/test/test_helper.rb +2 -2
- metadata +22 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a56c7ff8c99578de57f5c70bc4e29e14f163839860edbfb9064e89d6c32d88a
|
4
|
+
data.tar.gz: 877cc1dc0f8584fb0e824914af1d2e2ac08f15efc66ed085d23b8ff989b39a74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7f2b4bfb8ebb254c827303f7faa7cae1e590e7262f426f9ed0fc0ba46404c5d8fb25b32edd5adafb2dd3464f70750b3dcb59280064541f7230295410a56e3ef
|
7
|
+
data.tar.gz: cb5f20e546c4ce6cb3337b4ba9f5915630c9d1a1f769ce41a6f9024795df22c053792b5ec05dfb91e230c40a17f56603c0c123c1958660d919cc84bc656ad4c6
|
data/lib/filetype.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Filetype
|
2
2
|
module_function
|
3
3
|
|
4
|
-
VERSION = '0.
|
4
|
+
VERSION = '1.0.0'
|
5
5
|
|
6
6
|
FTYPES = {
|
7
7
|
:actionscript => %w[ as mxml ],
|
@@ -16,10 +16,14 @@ module Filetype
|
|
16
16
|
:csharp => %w[ cs ],
|
17
17
|
:css => %w[ css ],
|
18
18
|
:diff => %w[ diff patch ],
|
19
|
+
:docker => /\A[Dd]ockerfile(?:\.\w+)?\z/,
|
19
20
|
:elisp => %w[ el ],
|
21
|
+
:epub => %w[ epub ],
|
20
22
|
:erb => %w[ rhtml erb ],
|
21
23
|
:erlang => %w[ erl hrl ],
|
22
24
|
:exe => %w[ exe ],
|
25
|
+
:forth => %w[ 4th ],
|
26
|
+
:fsharp => %w[ fs ],
|
23
27
|
:gem => %w[ gem ],
|
24
28
|
:go => %w[ go ],
|
25
29
|
:groovy => %w[ groovy gpp grunit gtmpl ],
|
@@ -66,6 +70,7 @@ module Filetype
|
|
66
70
|
# Filetype.get('Rakefile') #=> :rake
|
67
71
|
# @return [Symbol] The language found or nil
|
68
72
|
def get(fname)
|
73
|
+
fname = File.basename(fname)
|
69
74
|
FTYPES.each do |ftype, rule|
|
70
75
|
case rule
|
71
76
|
when Array
|
@@ -86,6 +91,7 @@ module Filetype
|
|
86
91
|
# Filetype.all('foo.h') #=> [:c, :cpp, :objc]
|
87
92
|
# @return [Array] The list of languages found
|
88
93
|
def all(fname)
|
94
|
+
fname = File.basename(fname)
|
89
95
|
FTYPES.select do |ftype, rule|
|
90
96
|
ftype if rule.is_a?(Array) && rule.include?(ext(fname))
|
91
97
|
end.keys
|
data/test/filetype_test.rb
CHANGED
@@ -36,7 +36,10 @@ class FileTypeTest < TestCase
|
|
36
36
|
assert_equal :cpp, Filetype.get('foo.hxx')
|
37
37
|
assert_equal :csharp, Filetype.get('foo.cs')
|
38
38
|
assert_equal :css, Filetype.get('foo.css')
|
39
|
+
assert_equal :docker, Filetype.get('Dockerfile')
|
40
|
+
assert_equal :docker, Filetype.get('Dockerfile.build')
|
39
41
|
assert_equal :elisp, Filetype.get('foo.el')
|
42
|
+
assert_equal :epub, Filetype.get('foo.epub')
|
40
43
|
assert_equal :erb, Filetype.get('foo.rhtml')
|
41
44
|
assert_equal :erb, Filetype.get('foo.erb')
|
42
45
|
assert_equal :erlang, Filetype.get('foo.erl')
|
@@ -98,6 +101,11 @@ class FileTypeTest < TestCase
|
|
98
101
|
assert_equal :xsl, Filetype.get('foo.xsl')
|
99
102
|
end
|
100
103
|
|
104
|
+
test 'evaluates filetype against file basename' do
|
105
|
+
assert_equal :c, Filetype.get('dockerfile/foo.h')
|
106
|
+
assert_equal :sql, Filetype.get('Makefile/blah.sql')
|
107
|
+
end
|
108
|
+
|
101
109
|
test 'fetching multiple languages of a file name' do
|
102
110
|
assert_equal [:c, :cpp, :objc], Filetype.all('foo.h')
|
103
111
|
assert_empty Filetype.all('foo.aahaha')
|
@@ -108,4 +116,4 @@ class FileTypeTest < TestCase
|
|
108
116
|
assert_equal :bar, Filetype.get('hello.foo')
|
109
117
|
end
|
110
118
|
|
111
|
-
end
|
119
|
+
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.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
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-28 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: []
|