filetype 0.3.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4727e0c57dc75e0f130816a7ad47fa057d49dd72d3eb9309bdb14f497e668e6e
4
- data.tar.gz: 7ced5c77fabf3df3015385286e5b86aff8ef4172dc27ed2ea894d7040ef08d55
3
+ metadata.gz: ea7cc215335d49eb8a449ee4f7896963256396e3dd82808977f946785623cfb5
4
+ data.tar.gz: 62ebd38de6d7f69fea1da86ab071f16dfbb660822ff48cbc6b29f47cd7c03e62
5
5
  SHA512:
6
- metadata.gz: 282c798ef18f796e4e8cbb101b076c4de92e8fe5ef99f015ac96de1b7a0ef6f20d54401b1b9cfdd1b939d6615f58a36a4d18e34d789fa4f665986828d23fb3da
7
- data.tar.gz: ab11c48de92bb964a443c057be81581a00cd602495c8a695e66c29ea67bc212c6b150c731a69bb7cfbbef91c6d8be16d60fb043896267788bf5af4301dd9abaa
6
+ metadata.gz: d83e7ac6df8cb28b3c3429190fcad96317cde1f82017828305828ffbb389d18524d1b90728685949b0a0d79afbddaa20419a0361604044f9ff375c923086c792
7
+ data.tar.gz: 2da0a3ac276ab6c35e9fef4416616fa36b7d9738eab8ed192100ecdad16d81f7ece94a3e7d8c12710f3990839b8d44873cad66dede620687cb5de7906ae80a90
data/filetype.gemspec CHANGED
@@ -10,8 +10,11 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "http://github.com/injekt/filetype"
11
11
  s.summary = "Find a files type"
12
12
  s.description = "Find a file type according to a filename or extension"
13
+ s.license = "MIT"
13
14
 
14
- s.files = `git ls-files`.split("\n")
15
+ s.files = `git ls-files`.split("\n").reject do |f|
16
+ f.match(%r{^(test|spec|features|\.github)/})
17
+ end
15
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
20
  s.require_paths = ["lib"]
data/lib/filetype.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Filetype
2
2
  module_function
3
3
 
4
- VERSION = '0.3.2'
4
+ VERSION = '1.2.0'
5
5
 
6
6
  FTYPES = {
7
7
  :actionscript => %w[ as mxml ],
@@ -33,6 +33,7 @@ module Filetype
33
33
  :html => %w[ html xhtml shtml htm ],
34
34
  :java => %w[ java jar ],
35
35
  :js => %w[ js ],
36
+ :json => %w[ json ],
36
37
  :lisp => %w[ lisp lsp ],
37
38
  :lua => %w[ lua ],
38
39
  :make => /\A[Mm]akefile\z/,
@@ -56,6 +57,7 @@ module Filetype
56
57
  :sql => %w[ sql ctl ],
57
58
  :tar => %w[ tar ],
58
59
  :text => %w[ txt ],
60
+ :toml => %w[ toml ],
59
61
  :yaml => %w[ yaml yml ],
60
62
  :xml => %w[ xml dtd ],
61
63
  :xsl => %w[ xsl xslt],
@@ -70,6 +72,7 @@ module Filetype
70
72
  # Filetype.get('Rakefile') #=> :rake
71
73
  # @return [Symbol] The language found or nil
72
74
  def get(fname)
75
+ fname = File.basename(fname)
73
76
  FTYPES.each do |ftype, rule|
74
77
  case rule
75
78
  when Array
@@ -90,6 +93,7 @@ module Filetype
90
93
  # Filetype.all('foo.h') #=> [:c, :cpp, :objc]
91
94
  # @return [Array] The list of languages found
92
95
  def all(fname)
96
+ fname = File.basename(fname)
93
97
  FTYPES.select do |ftype, rule|
94
98
  ftype if rule.is_a?(Array) && rule.include?(ext(fname))
95
99
  end.keys
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filetype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-12 00:00:00.000000000 Z
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Find a file type according to a filename or extension
14
14
  email:
@@ -24,10 +24,9 @@ files:
24
24
  - Rakefile
25
25
  - filetype.gemspec
26
26
  - lib/filetype.rb
27
- - test/filetype_test.rb
28
- - test/test_helper.rb
29
27
  homepage: http://github.com/injekt/filetype
30
- licenses: []
28
+ licenses:
29
+ - MIT
31
30
  metadata: {}
32
31
  post_install_message:
33
32
  rdoc_options: []
@@ -44,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
43
  - !ruby/object:Gem::Version
45
44
  version: '0'
46
45
  requirements: []
47
- rubygems_version: 3.2.9
46
+ rubygems_version: 3.0.3.1
48
47
  signing_key:
49
48
  specification_version: 4
50
49
  summary: Find a files type
@@ -1,114 +0,0 @@
1
- require 'test_helper'
2
-
3
- class FileTypeTest < TestCase
4
-
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')
79
- assert_equal :ruby, Filetype.get('foo.rb')
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')
102
- end
103
-
104
- test 'fetching multiple languages of a file name' do
105
- assert_equal [:c, :cpp, :objc], Filetype.all('foo.h')
106
- assert_empty Filetype.all('foo.aahaha')
107
- end
108
-
109
- test 'adding filetypes' do
110
- Filetype.add(:bar, %w/foo bar/)
111
- assert_equal :bar, Filetype.get('hello.foo')
112
- end
113
-
114
- end
data/test/test_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- class TestCase < Minitest::Test
2
- def self.test(name, &block)
3
- test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym
4
- defined = instance_method(test_name) rescue false
5
- raise "#{test_name} is already defined in #{self}" if defined
6
- if block_given?
7
- define_method(test_name, &block)
8
- else
9
- define_method(test_name) do
10
- flunk "No implementation provided for #{name}"
11
- end
12
- end
13
- end
14
- end